Example #1
0
def _extract_case_blocks(data, path=None, form_id=Ellipsis):
    """
    helper for extract_case_blocks

    data must be json representing a node in an xform submission
    """
    from corehq.form_processor.utils import extract_meta_instance_id
    if form_id is Ellipsis:
        form_id = extract_meta_instance_id(data)

    path = path or []
    if isinstance(data, list):
        for item in data:
            for case_block in _extract_case_blocks(item, path=path, form_id=form_id):
                yield case_block
    elif isinstance(data, dict) and not is_device_report(data):
        for key, value in data.items():
            new_path = path + [key]
            if const.CASE_TAG == key:
                # it's a case block! Stop recursion and add to this value
                if isinstance(value, list):
                    case_blocks = value
                else:
                    case_blocks = [value]

                for case_block in case_blocks:
                    if has_case_id(case_block):
                        validate_phone_datetime(
                            case_block.get('@date_modified'), none_ok=True, form_id=form_id
                        )
                        yield CaseBlockWithPath(caseblock=case_block, path=path)
            else:
                for case_block in _extract_case_blocks(value, path=new_path, form_id=form_id):
                    yield case_block
Example #2
0
def _extract_case_blocks(data, path=None, form_id=Ellipsis):
    """
    helper for extract_case_blocks

    data must be json representing a node in an xform submission
    """
    from corehq.form_processor.utils import extract_meta_instance_id
    if form_id is Ellipsis:
        form_id = extract_meta_instance_id(data)

    path = path or []
    if isinstance(data, list):
        for item in data:
            for case_block in _extract_case_blocks(item, path=path, form_id=form_id):
                yield case_block
    elif isinstance(data, dict) and not is_device_report(data):
        for key, value in data.items():
            new_path = path + [key]
            if const.CASE_TAG == key:
                # it's a case block! Stop recursion and add to this value
                if isinstance(value, list):
                    case_blocks = value
                else:
                    case_blocks = [value]

                for case_block in case_blocks:
                    if has_case_id(case_block):
                        validate_phone_datetime(
                            case_block.get('@date_modified'), none_ok=True, form_id=form_id
                        )
                        yield CaseBlockWithPath(caseblock=case_block, path=path)
            else:
                for case_block in _extract_case_blocks(value, path=new_path, form_id=form_id):
                    yield case_block
Example #3
0
    def new_xform(cls, form_data):
        form_id = extract_meta_instance_id(form_data) or unicode(uuid.uuid4())

        return XFormInstanceSQL(
            # other properties can be set post-wrap
            form_id=form_id,
            xmlns=form_data.get('@xmlns'),
            received_on=datetime.datetime.utcnow(),
            user_id=extract_meta_user_id(form_data),
        )
Example #4
0
    def new_xform(cls, form_data):
        form_id = extract_meta_instance_id(form_data) or unicode(uuid.uuid4())

        return XFormInstanceSQL(
            # other properties can be set post-wrap
            form_id=form_id,
            xmlns=form_data.get('@xmlns'),
            received_on=datetime.datetime.utcnow(),
            user_id=extract_meta_user_id(form_data),
        )
Example #5
0
 def new_xform(cls, form_data):
     _id = extract_meta_instance_id(form_data) or uuid.uuid4().hex
     assert _id
     xform = XFormInstance(
         # form has to be wrapped
         {'form': form_data},
         # other properties can be set post-wrap
         _id=_id,
         xmlns=form_data.get('@xmlns'),
         received_on=datetime.datetime.utcnow(),
     )
     return xform
Example #6
0
 def new_xform(cls, form_data):
     _id = extract_meta_instance_id(form_data) or XFormInstance.get_db().server.next_uuid()
     assert _id
     xform = XFormInstance(
         # form has to be wrapped
         {'form': form_data},
         # other properties can be set post-wrap
         _id=_id,
         xmlns=form_data.get('@xmlns'),
         received_on=datetime.datetime.utcnow(),
     )
     return xform