示例#1
0
def overwrite_app(app, master_build, report_map=None):
    excluded_fields = set(Application._meta_fields).union([
        'date_created', 'build_profiles', 'copy_history', 'copy_of',
        'name', 'comment', 'doc_type', '_LAZY_ATTACHMENTS', 'practice_mobile_worker_id',
        'custom_base_url'
    ])
    master_json = master_build.to_json()
    app_json = app.to_json()
    id_map = _get_form_id_map(app_json)  # do this before we change the source

    for key, value in six.iteritems(master_json):
        if key not in excluded_fields:
            app_json[key] = value
    app_json['version'] = master_json['version']
    wrapped_app = wrap_app(app_json)
    for module in wrapped_app.get_report_modules():
        if report_map is None:
            raise AppEditingError('Report map not passed to overwrite_app')

        for config in module.report_configs:
            try:
                config.report_id = report_map[config.report_id]
            except KeyError:
                raise AppEditingError(config.report_id)

    wrapped_app = _update_form_ids(wrapped_app, master_build, id_map)
    enable_usercase_if_necessary(wrapped_app)
    return wrapped_app
示例#2
0
def overwrite_app(app, master_build, report_map=None, maintain_ids=False):
    excluded_fields = set(Application._meta_fields).union([
        'date_created', 'build_profiles', 'copy_history', 'copy_of', 'name',
        'comment', 'doc_type'
    ])
    master_json = master_build.to_json()
    for key, value in master_json.iteritems():
        if key not in excluded_fields:
            app[key] = value
    app['version'] = master_json['version']
    wrapped_app = wrap_app(app)
    for module in wrapped_app.modules:
        if isinstance(module, ReportModule):
            if report_map is not None:
                for config in module.report_configs:
                    try:
                        config.report_id = report_map[config.report_id]
                    except KeyError:
                        raise AppEditingError('Dynamic UCR used in linked app')
            else:
                raise AppEditingError('Report map not passed to overwrite_app')
    if maintain_ids:
        id_map = _get_form_id_map(app)
        wrapped_app = _update_form_ids(wrapped_app, master_build, id_map)
    wrapped_app.copy_attachments(master_build)
    enable_usercase_if_necessary(wrapped_app)
    wrapped_app.save(increment_version=False)
示例#3
0
def overwrite_app(app, master_build, report_map=None):
    excluded_fields = set(Application._meta_fields).union([
        'date_created',
        'build_profiles',
        'copy_history',
        'copy_of',
        'name',
        'comment',
        'doc_type',
        '_LAZY_ATTACHMENTS',
        'practice_mobile_worker_id',
        'custom_base_url',
        'family_id',
    ])
    master_json = master_build.to_json()
    app_json = app.to_json()

    for key, value in master_json.items():
        if key not in excluded_fields:
            app_json[key] = value
    app_json['version'] = app_json.get('version', 1)
    app_json['upstream_version'] = master_json['version']
    app_json['upstream_app_id'] = master_json['copy_of']
    wrapped_app = wrap_app(app_json)
    for module in wrapped_app.get_report_modules():
        if report_map is None:
            raise AppEditingError('Report map not passed to overwrite_app')

        for config in module.report_configs:
            try:
                config.report_id = report_map[config.report_id]
            except KeyError:
                raise AppEditingError(config.report_id)

    # Legacy linked apps have different form unique ids than their master app(s). These mappings
    # are stored as ResourceOverride objects. Look up to see if this app has any.
    from corehq.apps.app_manager.suite_xml.post_process.resources import get_xform_resource_overrides
    overrides = get_xform_resource_overrides(domain=wrapped_app.domain,
                                             app_id=wrapped_app.get_id)
    ids_map = {
        pre_id: override.post_id
        for pre_id, override in overrides.items()
    }
    wrapped_app = _update_forms(wrapped_app, master_build, ids_map)

    # Multimedia versions should be set based on the linked app's versions, not those of the master app.
    for path in wrapped_app.multimedia_map.keys():
        wrapped_app.multimedia_map[path].version = None
    wrapped_app.set_media_versions()

    enable_usercase_if_necessary(wrapped_app)
    return wrapped_app
示例#4
0
def make_remote_profile(app, langs=None):
    try:
        profile = six.moves.urllib.request.urlopen(app.profile_url).read()
    except Exception:
        raise AppEditingError('Unable to access profile url: "%s"' %
                              app.profile_url)

    if app.manage_urls:
        profile_xml = ProfileXML(profile)

        if app.manage_urls:
            profile_xml.auto_set_versions(app.version)
            profile_xml.set_attribute('update', app.hq_profile_url)
            profile_xml.set_property("ota-restore-url", app.ota_restore_url)
            profile_xml.set_property("PostURL", app.post_url)
            profile_xml.set_property("cc_user_domain",
                                     cc_user_domain(app.domain))
            profile_xml.set_property('form-record-url', app.form_record_url)
            profile_xml.set_property('key_server', app.key_server_url)
            download_index_url = reverse(
                'download_index',
                args=[app.domain, app.get_id],
            )
            for suite_node in profile_xml.findall('suite'):
                reset_suite_remote_url(suite_node=suite_node,
                                       profile_url=app.profile_url,
                                       url_base=app.url_base,
                                       download_index_url=download_index_url)

            if langs:
                profile_xml.set_property("cur_locale", langs[0])

        profile = profile_xml.render()
    return profile
示例#5
0
def overwrite_app(app, master_build, report_map=None):
    excluded_fields = set(Application._meta_fields).union([
        'date_created', 'build_profiles', 'copy_history', 'copy_of',
        'name', 'comment', 'doc_type', '_LAZY_ATTACHMENTS', 'practice_mobile_worker_id',
        'custom_base_url', 'family_id',
    ])
    master_json = master_build.to_json()
    app_json = app.to_json()

    old_form_ids_by_xmlns = _get_historical_form_ids_by_xmlns(app)  # before updating anything

    for key, value in master_json.items():
        if key not in excluded_fields:
            app_json[key] = value
    app_json['version'] = app_json.get('version', 1)
    app_json['upstream_version'] = master_json['version']
    app_json['upstream_app_id'] = master_json['copy_of']
    wrapped_app = wrap_app(app_json)
    for module in wrapped_app.get_report_modules():
        if report_map is None:
            raise AppEditingError('Report map not passed to overwrite_app')

        for config in module.report_configs:
            try:
                config.report_id = report_map[config.report_id]
            except KeyError:
                raise AppEditingError(config.report_id)

    ids_map = _map_old_form_ids_to_new(wrapped_app, old_form_ids_by_xmlns)
    wrapped_app = _update_form_ids(wrapped_app, master_build, ids_map)

    # Multimedia versions should be set based on the linked app's versions, not those of the master app.
    for path in wrapped_app.multimedia_map.keys():
        wrapped_app.multimedia_map[path].version = None
    wrapped_app.set_media_versions()

    enable_usercase_if_necessary(wrapped_app)
    return wrapped_app
示例#6
0
def overwrite_app(app, master_build, include_ucrs=False, report_map=None):
    excluded_fields = set(Application._meta_fields).union([
        'date_created', 'build_profiles', 'copy_history', 'copy_of', 'name',
        'comment', 'doc_type'
    ])
    master_json = master_build.to_json()
    for key, value in master_json.iteritems():
        if key not in excluded_fields:
            app[key] = value
    app['version'] = master_json['version']
    wrapped_app = wrap_app(app)
    for module in wrapped_app.modules:
        if isinstance(module, ReportModule):
            if include_ucrs and report_map is not None:
                for config in module.report_configs:
                    config.report_id = report_map[config.report_id]
            else:
                raise AppEditingError()
    wrapped_app.copy_attachments(master_build)
    wrapped_app.save(increment_version=False)