Skip to content

Commit

Permalink
extract defaults out of loop
Browse files Browse the repository at this point in the history
  • Loading branch information
snopoke committed Jul 21, 2022
1 parent 39b38f2 commit db0a758
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions corehq/ex-submodules/casexml/apps/case/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,16 @@ def get_case_history(case):
changes = defaultdict(dict)
for form in XFormInstance.objects.get_forms(case.xform_ids, case.domain):
name = xmlns_to_name(case.domain, form.xmlns, form.app_id, form_name=form.form_data.get('@name'))
defaults = {
'Form ID': form.form_id,
'Form Name': name,
'Form Received On': form.received_on,
'Form Submitted By': form.metadata.username,
}
case_blocks = extract_case_blocks(form)
for block in case_blocks:
if block.get('@case_id') == case.case_id:
property_changes = {
'Form ID': form.form_id,
'Form Name': name,
'Form Received On': form.received_on,
'Form Submitted By': form.metadata.username,
}
property_changes = defaults.copy()
property_changes.update(block.get('create', {}))
property_changes.update(block.get('update', {}))
changes[form.form_id].update(property_changes)
Expand Down

0 comments on commit db0a758

Please sign in to comment.