コード例 #1
0
def migrate_preloads(app, form, preload_items, form_ix, dry):
    xform = XForm(form.source)
    if form.case_references:
        load_refs = form.case_references.load
    else:
        load_refs = {}
        form.case_references = CaseReferences(load=load_refs)
    for hashtag, preloads in preload_items:
        if hashtag == "#case/":
            xform.add_case_preloads(preloads)
        elif hashtag == "#user/":
            xform.add_casedb()
            for nodeset, prop in preloads.items():
                assert '/' not in prop, (app.id, form.unique_id, prop)
                xform.add_setvalue(ref=nodeset, value=USERPROP_PREFIX + prop)
        else:
            raise ValueError("unknown hashtag: " + hashtag)
        for nodeset, prop in preloads.items():
            load_refs.setdefault(nodeset, []).append(hashtag + prop)
            logger.info("%s/%s %s setvalue %s = %s", app.domain, app._id,
                        form_ix, nodeset, hashtag + prop)
    if dry:
        logger.info(
            "setvalue XML: %s",
            " ".join(line.strip()
                     for line in ET.tostring(xform.xml).split("\n")
                     if "setvalue" in line))
    else:
        save_xform(app, form, ET.tostring(xform.xml))
コード例 #2
0
def migrate_preloads(app, form, preload_items, form_ix, dry):
    xform = XForm(form.source)
    if form.case_references:
        load_refs = form.case_references.load
    else:
        load_refs = {}
        form.case_references = CaseReferences(load=load_refs)
    for hashtag, preloads in preload_items:
        if hashtag == "#case/":
            xform.add_case_preloads(preloads)
        elif hashtag == "#user/":
            xform.add_casedb()
            for nodeset, prop in preloads.items():
                assert '/' not in prop, (app.id, form.unique_id, prop)
                xform.add_setvalue(ref=nodeset, value=USERPROP_PREFIX + prop)
        else:
            raise ValueError("unknown hashtag: " + hashtag)
        for nodeset, prop in six.iteritems(preloads):
            load_refs.setdefault(nodeset, []).append(hashtag + prop)
            logger.info("%s/%s %s setvalue %s = %s",
                app.domain, app._id, form_ix, nodeset, hashtag + prop)
    if dry:
        logger.info("setvalue XML: %s", " ".join(line.strip()
            for line in ET.tostring(xform.xml).split("\n")
            if "setvalue" in line))
    else:
        save_xform(app, form, ET.tostring(xform.xml))
コード例 #3
0
def migrate_preloads(app, form, preloads):
    xform = XForm(form.source)
    for kwargs in preloads:
        hashtag = kwargs.pop("hashtag")
        xform.add_case_preloads(**kwargs)
        refs = {path: [hashtag + case_property]
                for path, case_property in kwargs["preloads"].iteritems()}
        if form.case_references:
            form.case_references.load.update(refs)
        else:
            form.case_references = CaseReferences(load=refs)
    save_xform(app, form, ET.tostring(xform.xml))
コード例 #4
0
    def migrate_app(self, app_id):
        app = Application.get(app_id)
        modules = [m for m in app.modules if m.module_type == 'basic']

        for module in modules:
            forms = [f for f in module.forms if f.doc_type == 'Form']
            for form in forms:
                preload = form.actions.case_preload.preload
                if preload:
                    xform = XForm(form.source)
                    xform.add_case_preloads(preload)
                    save_xform(app, form, ET.tostring(xform.xml))
                    form.actions.load_from_form = form.actions.case_preload
                    form.actions.case_preload = PreloadAction()

        app.vellum_case_management = True
        app.save()
コード例 #5
0
    def migrate_app(self, app_id):
        app = Application.get(app_id)
        if app.vellum_case_management:
            logger.info('already migrated app {}'.format(app_id))
            return

        modules = [m for m in app.modules if m.module_type == 'basic']
        for module in modules:
            forms = [f for f in module.forms if f.doc_type == 'Form']
            for form in forms:
                preload = form.actions.case_preload.preload
                if preload:
                    xform = XForm(form.source)
                    xform.add_case_preloads(preload)
                    save_xform(app, form, ET.tostring(xform.xml))
                    form.actions.load_from_form = form.actions.case_preload
                    form.actions.case_preload = PreloadAction()

        app.vellum_case_management = True
        app.save()
コード例 #6
0
    def migrate_app(self, app_id):
        app = Application.get(app_id)
        if app.vellum_case_management:
            logger.info('already migrated app {}'.format(app_id))
            return

        modules = [m for m in app.modules if m.module_type == 'basic']
        for module in modules:
            forms = [f for f in module.forms if f.doc_type == 'Form']
            for form in forms:
                preload = form.actions.case_preload.preload
                if preload:
                    if form.requires == 'case':
                        xform = XForm(form.source)
                        xform.add_case_preloads(preload)
                        save_xform(app, form, ET.tostring(xform.xml))
                        form.case_references = {"load": {path: [case_property]
                            for path, case_property in preload.iteritems()}}
                    form.actions.case_preload = PreloadAction()

        app.vellum_case_management = True
        app.save()