(request, domain, app_id, module_id=None, form_id=None,
                 copy_app_form=None, release_manager=False,
                 module_unique_id=None, form_unique_id=None)
return response
This is the main view for the app. All other views redirect to here.
This is the main view for the app. All other views redirect to here.
This is the main view for the app . All other views redirect to here .
def view_generic(request, domain, app_id, module_id=None, form_id=None,
                 copy_app_form=None, release_manager=False,
                 module_unique_id=None, form_unique_id=None):
    """
    This is the main view for the app. All other views redirect to here.

    """
    if form_id and not module_id and module_unique_id is None:
        return bail(request, domain, app_id)

    app = get_app(domain, app_id)
    module = form = None

    if module_id:
        try:
            module = app.get_module(module_id)
        except ModuleNotFoundException:
            raise Http404()
        if not module.unique_id:
            module.get_or_create_unique_id()
            app.save()
    elif module_unique_id:
        try:
            module = app.get_module_by_unique_id(module_unique_id)
        except ModuleNotFoundException:
            raise Http404()
        module_id = module.id

    if form_id and module is not None:
        try:
            form = module.get_form(form_id)
        except IndexError:
            raise Http404()
    elif form_unique_id:
        try:
            form = app.get_form(form_unique_id)
        except FormNotFoundException:
            raise Http404()
        form_id = form.id

    if form is not None and module is None:
        # this is the case where only the form_unique_id is given
        module = form.get_module()
        module_id = module.id

    # Application states that should no longer exist
    if app.application_version == APP_V1:
        _assert = soft_assert()
        _assert(False, 'App version 1.0', {'domain': domain, 'app_id': app_id})
        return render(request, "app_manager/no_longer_supported.html", {
            'domain': domain,
            'app': app,
        })
    if (form is not None and "usercase_preload" in getattr(form, "actions", {})
            and form.actions.usercase_preload.preload):
        _assert = soft_assert(['dmiller' + '@' + 'dimagi.com'])
        _assert(False, 'User property easy refs + old-style config = bad', {
            'domain': domain,
            'app_id': app_id,
            'module_id': module_id,
            'module_unique_id': module_unique_id,
            'form_id': form_id,
            'form_unique_id': form_unique_id,
        })

    context = get_apps_base_context(request, domain, app)
    if app.copy_of:
        # redirect to "main" app rather than specific build
        return HttpResponseRedirect(reverse(
            "view_app", args=[domain, app.copy_of]
        ))

    context.update({
        'module': module,
        'form': form,
    })

    lang = context['lang']
    if not module and hasattr(app, 'translations'):
        context.update({"translations": app.translations.get(lang, {})})

    if not app.is_remote_app():
        context.update({
            'add_ons': add_ons.get_dict(request, app, module, form),
            'add_ons_privileges': add_ons.get_privileges_dict(request),
            'add_ons_layout': add_ons.get_layout(request),
        })

    if form:
        template, form_context = get_form_view_context_and_template(
            request, domain, form, context['langs'], current_lang=lang
        )
        context.update(form_context)
    elif module:
        template = get_module_template(request.user, module)
        # make sure all modules have unique ids
        app.ensure_module_unique_ids(should_save=True)
        module_context = get_module_view_context(request, app, module, lang)
        context.update(module_context)
    else:
        context.update(get_app_view_context(request, app))

        template = 'app_manager/app_view_settings.html'
        if release_manager:
            template = 'app_manager/app_view_release_manager.html'
        if release_manager:
            context.update(get_releases_context(request, domain, app_id))
        context.update({
            'is_app_settings_page': not release_manager,
        })

    # update multimedia context for forms and modules.
    menu_host = form or module
    if menu_host:
        default_file_name = 'module%s' % module_id
        if form:
            default_file_name = '%s_form%s' % (default_file_name, form_id)

        specific_media = [{
            'menu_refs': app.get_menu_media(module, form=form, form_index=form_id, to_language=lang),
            'default_file_name': '{name}_{lang}'.format(name=default_file_name, lang=lang),
        }]

        if not form and module and not isinstance(module, ReportModule) and module.uses_media():
            def _make_name(suffix):
                return "{default_name}_{suffix}_{lang}".format(
                    default_name=default_file_name,
                    suffix=suffix,
                    lang=lang,
                )

            specific_media.append({
                'menu_refs': app.get_case_list_form_media(module, to_language=lang),
                'default_file_name': _make_name('case_list_form'),
                'qualifier': 'case_list_form_',
            })
            specific_media.append({
                'menu_refs': app.get_case_list_menu_item_media(module, to_language=lang),
                'default_file_name': _make_name('case_list_menu_item'),
                'qualifier': 'case_list-menu_item_',
            })
            if (module and hasattr(module, 'search_config') and module.uses_media()
                    and toggles.USH_CASE_CLAIM_UPDATES.enabled(domain)):
                specific_media.extend([
                    {
                        'menu_refs': app.get_case_search_label_media(
                            module, module.search_config.search_label, to_language=lang),
                        'default_file_name': _make_name('case_search_label_item'),
                        'qualifier': 'case_search-search_label_media_'
                    },
                    {
                        'menu_refs': app.get_case_search_label_media(
                            module, module.search_config.search_again_label, to_language=lang),
                        'default_file_name': _make_name('case_search_again_label_item'),
                        'qualifier': 'case_search-search_again_label_media_'
                    }
                ])
            if (toggles.CASE_LIST_LOOKUP.enabled(request.user.username) or
                    toggles.CASE_LIST_LOOKUP.enabled(app.domain) or
                    toggles.BIOMETRIC_INTEGRATION.enabled(app.domain)):
                specific_media.append({
                    'menu_refs': app.get_case_list_lookup_image(module),
                    'default_file_name': '{}_case_list_lookup'.format(default_file_name),
                    'qualifier': 'case-list-lookupcase',
                })

                if hasattr(module, 'product_details'):
                    specific_media.append({
                        'menu_refs': app.get_case_list_lookup_image(module, type='product'),
                        'default_file_name': '{}_product_list_lookup'.format(default_file_name),
                        'qualifier': 'case-list-lookupproduct',
                    })

        uploaders = {
            'icon': MultimediaImageUploadController(
                "hqimage",
                reverse(ProcessImageFileUploadView.urlname,
                        args=[app.domain, app.get_id])
            ),
            'audio': MultimediaAudioUploadController(
                "hqaudio", reverse(ProcessAudioFileUploadView.urlname,
                        args=[app.domain, app.get_id])
            ),
        }

        multimedia_map = app.multimedia_map
        if form or module:
            multimedia_map = (form or module).get_relevant_multimedia_map(app)
        context.update({
            'multimedia': {
                "object_map": app.get_object_map(multimedia_map=multimedia_map),
                'upload_managers': uploaders,
                'upload_managers_js': {type: u.js_options for type, u in uploaders.items()},
            }
        })

        context['module_icon'] = None
        if toggles.CUSTOM_ICON_BADGES.enabled(domain):
            context['module_icon'] = module.custom_icon if module.custom_icon else CustomIcon()
        context['nav_menu_media_specifics'] = specific_media

    error = request.GET.get('error', '')

    context.update({
        'error': error,
        'app': app,
    })

    # Pass form for Copy Application to template
    if copy_app_form is None:
        copy_app_form = CopyApplicationForm(domain, app)

    domain_names = {
        d.name for d in Domain.active_for_user(request.couch_user)
        if not (is_active_downstream_domain(request.domain)
                and get_upstream_domain_link(request.domain).master_domain == d.name)
    }
    domain_names.add(request.domain)
    if domain_has_privilege(request.domain, RELEASE_MANAGEMENT):
        linkable_domains = get_accessible_downstream_domains(domain, request.couch_user)
    else:
        # keep behavior the same as before for LINKED_DOMAINS toggle
        linkable_domains = domain_names
    context.update({
        'domain_names': sorted(domain_names),
        'linkable_domains': sorted(linkable_domains),
        'limit_to_linked_domains': (domain_has_privilege(request.domain, RELEASE_MANAGEMENT)
                                    and not request.couch_user.is_superuser)
    })
    context.update({
        'copy_app_form': copy_app_form,
    })

    context['latest_commcare_version'] = get_commcare_versions(request.user)[-1]

    if not is_remote_app(app) and has_privilege(request, privileges.COMMCARE_LOGO_UPLOADER):
        uploader_slugs = list(ANDROID_LOGO_PROPERTY_MAPPING.keys())
        from corehq.apps.hqmedia.controller import (
            MultimediaLogoUploadController,
        )
        from corehq.apps.hqmedia.views import ProcessLogoFileUploadView
        uploaders = [
            MultimediaLogoUploadController(
                slug,
                reverse(
                    ProcessLogoFileUploadView.urlname,
                    args=[domain, app_id, slug],
                )
            )
            for slug in uploader_slugs
        ]
        context.update({
            "uploaders": uploaders,
            "uploaders_js": [u.js_options for u in uploaders],
            "refs": {
                slug: ApplicationMediaReference(
                    app.logo_refs.get(slug, {}).get("path", slug),
                    media_class=CommCareImage,
                ).as_dict()
                for slug in uploader_slugs
            },
            "media_info": {
                slug: app.logo_refs.get(slug)
                for slug in uploader_slugs if app.logo_refs.get(slug)
            },
        })

    context.update({
        'show_live_preview': should_show_preview_app(
            request,
            app,
            request.couch_user.username
        ),
    })

    confirm = request.session.pop('CONFIRM', False)
    context.update({'confirm': confirm})

    response = render(request, template, context)

    set_lang_cookie(response, lang)
    return response
def view_generic ( request , domain , app_id , module_id = None , form_id = None , copy_app_form = None , release_manager = False , module_unique_id = None , form_unique_id = None ) : if form_id and not module_id and module_unique_id is None : return bail ( request , domain , app_id ) app = get_app ( domain , app_id ) module = form = None if module_id : try : module = app . get_module ( module_id ) except ModuleNotFoundException : raise Http404 ( ) if not module . unique_id : module . get_or_create_unique_id ( ) app . save ( ) elif module_unique_id : try : module = app . get_module_by_unique_id ( module_unique_id ) except ModuleNotFoundException : raise Http404 ( ) module_id = module . id if form_id and module is not None : try : form = module . get_form ( form_id ) except IndexError : raise Http404 ( ) elif form_unique_id : try : form = app . get_form ( form_unique_id ) except FormNotFoundException : raise Http404 ( ) form_id = form . id if form is not None and module is None : # this is the case where only the form_unique_id is given module = form . get_module ( ) module_id = module . id # Application states that should no longer exist if app . application_version == APP_V1 : _assert = soft_assert ( ) _assert ( False , 'App version 1.0' , { 'domain' : domain , 'app_id' : app_id } ) return render ( request , "app_manager/no_longer_supported.html" , { 'domain' : domain , 'app' : app , } ) if ( form is not None and "usercase_preload" in getattr ( form , "actions" , { } ) and form . actions . usercase_preload . preload ) : _assert = soft_assert ( [ 'dmiller' + '@' + 'dimagi.com' ] ) _assert ( False , 'User property easy refs + old-style config = bad' , { 'domain' : domain , 'app_id' : app_id , 'module_id' : module_id , 'module_unique_id' : module_unique_id , 'form_id' : form_id , 'form_unique_id' : form_unique_id , } ) context = get_apps_base_context ( request , domain , app ) if app . copy_of : # redirect to "main" app rather than specific build return HttpResponseRedirect ( reverse ( "view_app" , args = [ domain , app . copy_of ] ) ) context . update ( { 'module' : module , 'form' : form , } ) lang = context [ 'lang' ] if not module and hasattr ( app , 'translations' ) : context . update ( { "translations" : app . translations . get ( lang , { } ) } ) if not app . is_remote_app ( ) : context . update ( { 'add_ons' : add_ons . get_dict ( request , app , module , form ) , 'add_ons_privileges' : add_ons . get_privileges_dict ( request ) , 'add_ons_layout' : add_ons . get_layout ( request ) , } ) if form : template , form_context = get_form_view_context_and_template ( request , domain , form , context [ 'langs' ] , current_lang = lang ) context . update ( form_context ) elif module : template = get_module_template ( request . user , module ) # make sure all modules have unique ids app . ensure_module_unique_ids ( should_save = True ) module_context = get_module_view_context ( request , app , module , lang ) context . update ( module_context ) else : context . update ( get_app_view_context ( request , app ) ) template = 'app_manager/app_view_settings.html' if release_manager : template = 'app_manager/app_view_release_manager.html' if release_manager : context . update ( get_releases_context ( request , domain , app_id ) ) context . update ( { 'is_app_settings_page' : not release_manager , } ) # update multimedia context for forms and modules. menu_host = form or module if menu_host : default_file_name = 'module%s' % module_id if form : default_file_name = '%s_form%s' % ( default_file_name , form_id ) specific_media = [ { 'menu_refs' : app . get_menu_media ( module , form = form , form_index = form_id , to_language = lang ) , 'default_file_name' : '{name}_{lang}' . format ( name = default_file_name , lang = lang ) , } ] if not form and module and not isinstance ( module , ReportModule ) and module . uses_media ( ) : def _make_name ( suffix ) : return "{default_name}_{suffix}_{lang}" . format ( default_name = default_file_name , suffix = suffix , lang = lang , ) specific_media . append ( { 'menu_refs' : app . get_case_list_form_media ( module , to_language = lang ) , 'default_file_name' : _make_name ( 'case_list_form' ) , 'qualifier' : 'case_list_form_' , } ) specific_media . append ( { 'menu_refs' : app . get_case_list_menu_item_media ( module , to_language = lang ) , 'default_file_name' : _make_name ( 'case_list_menu_item' ) , 'qualifier' : 'case_list-menu_item_' , } ) if ( module and hasattr ( module , 'search_config' ) and module . uses_media ( ) and toggles . USH_CASE_CLAIM_UPDATES . enabled ( domain ) ) : specific_media . extend ( [ { 'menu_refs' : app . get_case_search_label_media ( module , module . search_config . search_label , to_language = lang ) , 'default_file_name' : _make_name ( 'case_search_label_item' ) , 'qualifier' : 'case_search-search_label_media_' } , { 'menu_refs' : app . get_case_search_label_media ( module , module . search_config . search_again_label , to_language = lang ) , 'default_file_name' : _make_name ( 'case_search_again_label_item' ) , 'qualifier' : 'case_search-search_again_label_media_' } ] ) if ( toggles . CASE_LIST_LOOKUP . enabled ( request . user . username ) or toggles . CASE_LIST_LOOKUP . enabled ( app . domain ) or toggles . BIOMETRIC_INTEGRATION . enabled ( app . domain ) ) : specific_media . append ( { 'menu_refs' : app . get_case_list_lookup_image ( module ) , 'default_file_name' : '{}_case_list_lookup' . format ( default_file_name ) , 'qualifier' : 'case-list-lookupcase' , } ) if hasattr ( module , 'product_details' ) : specific_media . append ( { 'menu_refs' : app . get_case_list_lookup_image ( module , type = 'product' ) , 'default_file_name' : '{}_product_list_lookup' . format ( default_file_name ) , 'qualifier' : 'case-list-lookupproduct' , } ) uploaders = { 'icon' : MultimediaImageUploadController ( "hqimage" , reverse ( ProcessImageFileUploadView . urlname , args = [ app . domain , app . get_id ] ) ) , 'audio' : MultimediaAudioUploadController ( "hqaudio" , reverse ( ProcessAudioFileUploadView . urlname , args = [ app . domain , app . get_id ] ) ) , } multimedia_map = app . multimedia_map if form or module : multimedia_map = ( form or module ) . get_relevant_multimedia_map ( app ) context . update ( { 'multimedia' : { "object_map" : app . get_object_map ( multimedia_map = multimedia_map ) , 'upload_managers' : uploaders , 'upload_managers_js' : { type : u . js_options for type , u in uploaders . items ( ) } , } } ) context [ 'module_icon' ] = None if toggles . CUSTOM_ICON_BADGES . enabled ( domain ) : context [ 'module_icon' ] = module . custom_icon if module . custom_icon else CustomIcon ( ) context [ 'nav_menu_media_specifics' ] = specific_media error = request . GET . get ( 'error' , '' ) context . update ( { 'error' : error , 'app' : app , } ) # Pass form for Copy Application to template if copy_app_form is None : copy_app_form = CopyApplicationForm ( domain , app ) domain_names = { d . name for d in Domain . active_for_user ( request . couch_user ) if not ( is_active_downstream_domain ( request . domain ) and get_upstream_domain_link ( request . domain ) . master_domain == d . name ) } domain_names . add ( request . domain ) if domain_has_privilege ( request . domain , RELEASE_MANAGEMENT ) : linkable_domains = get_accessible_downstream_domains ( domain , request . couch_user ) else : # keep behavior the same as before for LINKED_DOMAINS toggle linkable_domains = domain_names context . update ( { 'domain_names' : sorted ( domain_names ) , 'linkable_domains' : sorted ( linkable_domains ) , 'limit_to_linked_domains' : ( domain_has_privilege ( request . domain , RELEASE_MANAGEMENT ) and not request . couch_user . is_superuser ) } ) context . update ( { 'copy_app_form' : copy_app_form , } ) context [ 'latest_commcare_version' ] = get_commcare_versions ( request . user ) [ - 1 ] if not is_remote_app ( app ) and has_privilege ( request , privileges . COMMCARE_LOGO_UPLOADER ) : uploader_slugs = list ( ANDROID_LOGO_PROPERTY_MAPPING . keys ( ) ) from corehq . apps . hqmedia . controller import ( MultimediaLogoUploadController , ) from corehq . apps . hqmedia . views import ProcessLogoFileUploadView uploaders = [ MultimediaLogoUploadController ( slug , reverse ( ProcessLogoFileUploadView . urlname , args = [ domain , app_id , slug ] , ) ) for slug in uploader_slugs ] context . update ( { "uploaders" : uploaders , "uploaders_js" : [ u . js_options for u in uploaders ] , "refs" : { slug : ApplicationMediaReference ( app . logo_refs . get ( slug , { } ) . get ( "path" , slug ) , media_class = CommCareImage , ) . as_dict ( ) for slug in uploader_slugs } , "media_info" : { slug : app . logo_refs . get ( slug ) for slug in uploader_slugs if app . logo_refs . get ( slug ) } , } ) context . update ( { 'show_live_preview' : should_show_preview_app ( request , app , request . couch_user . username ) , } ) confirm = request . session . pop ( 'CONFIRM' , False ) context . update ( { 'confirm' : confirm } ) response = render ( request , template , context ) set_lang_cookie ( response , lang ) return response