Skip to content

Commit

Permalink
replace a call to extract_case_blocks with get_case_updates
Browse files Browse the repository at this point in the history
get_case_updates has a normalized return form
whereas extract_case_blocks depends on the version
to return and accept the normalized model (CaseUpdate)
than the raw json
  • Loading branch information
dannyroberts committed Jan 2, 2014
1 parent f86b707 commit 1875f2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion casexml/apps/case/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .xform import process_cases
from .xform import process_cases, get_case_updates
15 changes: 9 additions & 6 deletions casexml/apps/case/xform.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ def get_or_update_cases(xform):
returning a dictionary mapping the case ids affected to the
couch case document objects
"""
case_blocks = extract_case_blocks(xform)
case_updates = get_case_updates(xform)

domain = get_and_check_xform_domain(xform)

case_db = CaseDbCache(domain=domain)
for case_block in case_blocks:
case_doc = _get_or_update_model(case_block, xform, case_db)
for case_update in case_updates:
case_doc = _get_or_update_model(case_update, xform, case_db)
if case_doc:
# todo: legacy behavior, should remove after new case processing
# is fully enabled.
Expand All @@ -207,13 +207,12 @@ def _validate_indices(case):
return case_db.cache


def _get_or_update_model(case_block, xform, case_db):
def _get_or_update_model(case_update, xform, case_db):
"""
Gets or updates an existing case, based on a block of data in a
submitted form. Doesn't save anything.
"""

case_update = case_update_from_block(case_block)
case = case_db.get(case_update.id)

if case is None:
Expand All @@ -237,7 +236,11 @@ def has_case_id(case_block):
def extract_case_blocks(doc):
"""
Extract all case blocks from a document, returning an array of dictionaries
with the data in each case.
with the data in each case.
The json returned is not normalized for casexml version;
for that get_case_updates is better.
"""

if isinstance(doc, XFormInstance):
Expand Down

0 comments on commit 1875f2e

Please sign in to comment.