(request, app)
return context
This provides the context to render commcare settings on Edit Application Settings page

    This is where additional app or domain specific context can be added to any individual
    commcare-setting defined in commcare-app-settings.yaml or commcare-profile-settings.yaml
This provides the context to render commcare settings on Edit Application Settings page
This provides the context to render commcare settings on Edit Application Settings page
def get_app_view_context(request, app):
    """
    This provides the context to render commcare settings on Edit Application Settings page

    This is where additional app or domain specific context can be added to any individual
    commcare-setting defined in commcare-app-settings.yaml or commcare-profile-settings.yaml
    """
    context = {}

    settings_layout = copy.deepcopy(
        get_commcare_settings_layout(app)
    )

    for section in settings_layout:
        new_settings = []
        for setting in section['settings']:
            toggle_name = setting.get('toggle')
            if toggle_name and not toggle_enabled(request, toggle_name):
                continue
            privilege_name = setting.get('privilege')
            if privilege_name and not has_privilege(request, privilege_name):
                continue
            disable_if_true = setting.get('disable_if_true')
            if disable_if_true and getattr(app, setting['id']):
                continue
            if is_linked_app(app):
                if setting['id'] in app.supported_settings:
                    if setting['id'] not in app.linked_app_attrs:
                        setting['is_inherited'] = True
            new_settings.append(setting)
        section['settings'] = new_settings

    app_view_options = {
        'permissions': {
            'cloudcare': has_privilege(request, privileges.CLOUDCARE),
            'case_sharing_groups': has_privilege(request,
                                                 privileges.CASE_SHARING_GROUPS),
        },
        'sections': settings_layout,
        'urls': {
            'save': reverse("edit_commcare_settings", args=(app.domain, app.id)),
        },
        'user': {
            'is_previewer': request.couch_user.is_previewer(),
        },
        'values': get_settings_values(app),
        'warning': _("This is not an allowed value for this field"),
    }
    if (app.get_doc_type() == 'Application'
            and toggles.CUSTOM_PROPERTIES.enabled(request.domain)
            and 'custom_properties' in getattr(app, 'profile', {})):
        custom_properties_array = [{'key': p[0], 'value': p[1]} for p in app.profile.get('custom_properties').items()]
        app_view_options.update({'customProperties': custom_properties_array})
    context.update({
        'app_view_options': app_view_options,
    })

    build_config = CommCareBuildConfig.fetch()
    options = build_config.get_menu()
    if not request.user.is_superuser and not toggles.IS_CONTRACTOR.enabled(request.user.username):
        options = [option for option in options if not option.superuser_only]
    options_map = defaultdict(lambda: {"values": [], "value_names": []})
    for option in options:
        builds = options_map[option.build.major_release()]
        builds["values"].append(option.build.to_string())
        builds["value_names"].append(option.get_label())
        if "default" not in builds:
            app_ver = MAJOR_RELEASE_TO_VERSION[option.build.major_release()]
            builds["default"] = build_config.get_default(app_ver).to_string()

    def _get_setting(setting_type, setting_id):
        # get setting dict from settings_layout
        if not settings_layout:
            return None
        matched = [x for x in [
                setting for section in settings_layout
                for setting in section['settings']
            ] if x['type'] == setting_type and x['id'] == setting_id]
        if matched:
            return matched[0]
        else:
            return None

    build_spec_setting = _get_setting('hq', 'build_spec')
    if build_spec_setting:
        build_spec_setting['options_map'] = options_map
        build_spec_setting['default_app_version'] = app.application_version

    practice_user_setting = _get_setting('hq', 'practice_mobile_worker_id')
    if practice_user_setting and has_privilege(request, privileges.PRACTICE_MOBILE_WORKERS):
        try:
            practice_users = get_practice_mode_mobile_workers(request.domain)
        except ESError:
            notify_exception(request, 'Error getting practice mode mobile workers')
            practice_users = []
        practice_user_setting['values'] = [''] + [u['_id'] for u in practice_users]
        practice_user_setting['value_names'] = [_('Not set')] + [u['username'] for u in practice_users]

    context.update({
        'bulk_ui_translation_upload': {
            'action': reverse('upload_bulk_ui_translations',
                              args=(app.domain, app.get_id)),
            'download_url': reverse('download_bulk_ui_translations',
                                    args=(app.domain, app.get_id)),
            'adjective': _("U\u200BI translation"),
            'plural_noun': _("U\u200BI translations"),
        },
        'bulk_app_translation_upload': {
            'action': reverse('upload_bulk_app_translations',
                              args=(app.domain, app.get_id)),
            'download_url': reverse('download_bulk_app_translations',
                                    args=(app.domain, app.get_id)),
            'adjective': _("app translation"),
            'plural_noun': _("app translations"),
            'can_select_language': toggles.BULK_UPDATE_MULTIMEDIA_PATHS.enabled_for_request(request),
            'can_validate_app_translations': toggles.VALIDATE_APP_TRANSLATIONS.enabled_for_request(request),
        },
    })
    context.update({
        'bulk_ui_translation_form': get_bulk_upload_form(
            context,
            context_key="bulk_ui_translation_upload",
        ),
        'bulk_app_translation_form': get_bulk_upload_form(
            context,
            context_key="bulk_app_translation_upload",
            form_class=AppTranslationsBulkUploadForm,
        ),
    })
    context.update({
        'smart_lang_display_enabled': getattr(app, 'smart_lang_display', False)
    })

    context.update({
        'is_linked_app': is_linked_app(app),
        'is_remote_app': is_remote_app(app),
    })
    if is_linked_app(app):
        try:
            upstream_versions_by_id = app.get_latest_master_releases_versions()
            upstream_briefs = [
                brief for brief in app.get_master_app_briefs() if brief.id in upstream_versions_by_id
            ]
        except RemoteRequestError:
            messages.error(request, "Unable to reach remote upstream server. Please try again later.")
            upstream_versions_by_id = {}
            upstream_briefs = []
        upstream_brief = {}
        for b in upstream_briefs:
            if b.id == app.upstream_app_id:
                upstream_brief = b
        context.update({
            'upstream_briefs': upstream_briefs,
            'upstream_versions_by_id': upstream_versions_by_id,
            'multiple_upstreams': app.enable_multi_master and len(upstream_briefs) > 1,
            'upstream_version': app.upstream_version,
            'upstream_brief': upstream_brief,
            'upstream_url': _get_upstream_url(app, request.couch_user),
            'upstream_url_template': _get_upstream_url(app, request.couch_user, upstream_app_id='---'),
        })
    return context
def get_app_view_context ( request , app ) : context = { } settings_layout = copy . deepcopy ( get_commcare_settings_layout ( app ) ) for section in settings_layout : new_settings = [ ] for setting in section [ 'settings' ] : toggle_name = setting . get ( 'toggle' ) if toggle_name and not toggle_enabled ( request , toggle_name ) : continue privilege_name = setting . get ( 'privilege' ) if privilege_name and not has_privilege ( request , privilege_name ) : continue disable_if_true = setting . get ( 'disable_if_true' ) if disable_if_true and getattr ( app , setting [ 'id' ] ) : continue if is_linked_app ( app ) : if setting [ 'id' ] in app . supported_settings : if setting [ 'id' ] not in app . linked_app_attrs : setting [ 'is_inherited' ] = True new_settings . append ( setting ) section [ 'settings' ] = new_settings app_view_options = { 'permissions' : { 'cloudcare' : has_privilege ( request , privileges . CLOUDCARE ) , 'case_sharing_groups' : has_privilege ( request , privileges . CASE_SHARING_GROUPS ) , } , 'sections' : settings_layout , 'urls' : { 'save' : reverse ( "edit_commcare_settings" , args = ( app . domain , app . id ) ) , } , 'user' : { 'is_previewer' : request . couch_user . is_previewer ( ) , } , 'values' : get_settings_values ( app ) , 'warning' : _ ( "This is not an allowed value for this field" ) , } if ( app . get_doc_type ( ) == 'Application' and toggles . CUSTOM_PROPERTIES . enabled ( request . domain ) and 'custom_properties' in getattr ( app , 'profile' , { } ) ) : custom_properties_array = [ { 'key' : p [ 0 ] , 'value' : p [ 1 ] } for p in app . profile . get ( 'custom_properties' ) . items ( ) ] app_view_options . update ( { 'customProperties' : custom_properties_array } ) context . update ( { 'app_view_options' : app_view_options , } ) build_config = CommCareBuildConfig . fetch ( ) options = build_config . get_menu ( ) if not request . user . is_superuser and not toggles . IS_CONTRACTOR . enabled ( request . user . username ) : options = [ option for option in options if not option . superuser_only ] options_map = defaultdict ( lambda : { "values" : [ ] , "value_names" : [ ] } ) for option in options : builds = options_map [ option . build . major_release ( ) ] builds [ "values" ] . append ( option . build . to_string ( ) ) builds [ "value_names" ] . append ( option . get_label ( ) ) if "default" not in builds : app_ver = MAJOR_RELEASE_TO_VERSION [ option . build . major_release ( ) ] builds [ "default" ] = build_config . get_default ( app_ver ) . to_string ( ) def _get_setting ( setting_type , setting_id ) : # get setting dict from settings_layout if not settings_layout : return None matched = [ x for x in [ setting for section in settings_layout for setting in section [ 'settings' ] ] if x [ 'type' ] == setting_type and x [ 'id' ] == setting_id ] if matched : return matched [ 0 ] else : return None build_spec_setting = _get_setting ( 'hq' , 'build_spec' ) if build_spec_setting : build_spec_setting [ 'options_map' ] = options_map build_spec_setting [ 'default_app_version' ] = app . application_version practice_user_setting = _get_setting ( 'hq' , 'practice_mobile_worker_id' ) if practice_user_setting and has_privilege ( request , privileges . PRACTICE_MOBILE_WORKERS ) : try : practice_users = get_practice_mode_mobile_workers ( request . domain ) except ESError : notify_exception ( request , 'Error getting practice mode mobile workers' ) practice_users = [ ] practice_user_setting [ 'values' ] = [ '' ] + [ u [ '_id' ] for u in practice_users ] practice_user_setting [ 'value_names' ] = [ _ ( 'Not set' ) ] + [ u [ 'username' ] for u in practice_users ] context . update ( { 'bulk_ui_translation_upload' : { 'action' : reverse ( 'upload_bulk_ui_translations' , args = ( app . domain , app . get_id ) ) , 'download_url' : reverse ( 'download_bulk_ui_translations' , args = ( app . domain , app . get_id ) ) , 'adjective' : _ ( "U\u200BI translation" ) , 'plural_noun' : _ ( "U\u200BI translations" ) , } , 'bulk_app_translation_upload' : { 'action' : reverse ( 'upload_bulk_app_translations' , args = ( app . domain , app . get_id ) ) , 'download_url' : reverse ( 'download_bulk_app_translations' , args = ( app . domain , app . get_id ) ) , 'adjective' : _ ( "app translation" ) , 'plural_noun' : _ ( "app translations" ) , 'can_select_language' : toggles . BULK_UPDATE_MULTIMEDIA_PATHS . enabled_for_request ( request ) , 'can_validate_app_translations' : toggles . VALIDATE_APP_TRANSLATIONS . enabled_for_request ( request ) , } , } ) context . update ( { 'bulk_ui_translation_form' : get_bulk_upload_form ( context , context_key = "bulk_ui_translation_upload" , ) , 'bulk_app_translation_form' : get_bulk_upload_form ( context , context_key = "bulk_app_translation_upload" , form_class = AppTranslationsBulkUploadForm , ) , } ) context . update ( { 'smart_lang_display_enabled' : getattr ( app , 'smart_lang_display' , False ) } ) context . update ( { 'is_linked_app' : is_linked_app ( app ) , 'is_remote_app' : is_remote_app ( app ) , } ) if is_linked_app ( app ) : try : upstream_versions_by_id = app . get_latest_master_releases_versions ( ) upstream_briefs = [ brief for brief in app . get_master_app_briefs ( ) if brief . id in upstream_versions_by_id ] except RemoteRequestError : messages . error ( request , "Unable to reach remote upstream server. Please try again later." ) upstream_versions_by_id = { } upstream_briefs = [ ] upstream_brief = { } for b in upstream_briefs : if b . id == app . upstream_app_id : upstream_brief = b context . update ( { 'upstream_briefs' : upstream_briefs , 'upstream_versions_by_id' : upstream_versions_by_id , 'multiple_upstreams' : app . enable_multi_master and len ( upstream_briefs ) > 1 , 'upstream_version' : app . upstream_version , 'upstream_brief' : upstream_brief , 'upstream_url' : _get_upstream_url ( app , request . couch_user ) , 'upstream_url_template' : _get_upstream_url ( app , request . couch_user , upstream_app_id = '---' ) , } ) return context