From aa35e454262281484a53f1263b6cd9eafaa778b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Wed, 29 Jul 2020 09:40:51 +0800 Subject: [PATCH] Renamed the variables in the sort_form_transaction_records() utility in the accounting application. --- accounting/utils.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/accounting/utils.py b/accounting/utils.py index 5525780..cfda5e7 100644 --- a/accounting/utils.py +++ b/accounting/utils.py @@ -363,7 +363,7 @@ def sort_form_transaction_records(form): form (dict): The POSTed form. """ # Collects the available record numbers - rec_no = { + record_no = { "debit": [], "credit": [], } @@ -373,32 +373,32 @@ def sort_form_transaction_records(form): key) if m is None: continue - rec_type = m.group(1) + record_type = m.group(1) no = int(m.group(2)) - if no not in rec_no[rec_type]: - rec_no[rec_type].append(no) + if no not in record_no[record_type]: + record_no[record_type].append(no) # Sorts these record numbers by their specified orders - for rec_type in rec_no.keys(): + for record_type in record_no.keys(): orders = {} - for no in rec_no[rec_type]: + for no in record_no[record_type]: try: - orders[no] = int(form[F"{rec_type}-{no}-ord"]) + orders[no] = int(form[F"{record_type}-{no}-ord"]) except KeyError: orders[no] = 9999 except ValueError: orders[no] = 9999 - rec_no[rec_type].sort(key=lambda x: orders[x]) + record_no[record_type].sort(key=lambda x: orders[x]) # Constructs the sorted new form new_form = {} - for rec_type in rec_no.keys(): - for i in range(len(rec_no[rec_type])): - old_no = rec_no[rec_type][i] + for record_type in record_no.keys(): + for i in range(len(record_no[record_type])): + old_no = record_no[record_type][i] no = i + 1 - new_form[F"{rec_type}-{no}-ord"] = no + new_form[F"{record_type}-{no}-ord"] = no for attr in ["sn", "account", "summary", "amount"]: - if F"{rec_type}-{old_no}-{attr}" in form: - new_form[F"{rec_type}-{no}-{attr}"]\ - = form[F"{rec_type}-{old_no}-{attr}"] + if F"{record_type}-{old_no}-{attr}" in form: + new_form[F"{record_type}-{no}-{attr}"]\ + = form[F"{record_type}-{old_no}-{attr}"] # Purges the old form and fills it with the new form for x in [x for x in form.keys() if re.match( "^(debit|credit)-([1-9][0-9]*)-(sn|ord|account|summary|amount)",