def sms_languages(request, domain): with StandaloneTranslationDoc.get_locked_obj(domain, "sms", create=True) as tdoc: if len(tdoc.langs) == 0: tdoc.langs = ["en"] tdoc.translations["en"] = {} tdoc.save() context = { "domain": domain, "always_deploy": True, "sms_langs": tdoc.langs, "bulk_upload": { "action": reverse("upload_sms_translations", args=(domain,)), "download_url": reverse("download_sms_translations", args=(domain,)), "adjective": _("messaging translation"), "plural_noun": _("messaging translations"), }, } context.update({ "bulk_upload_form": get_bulk_upload_form(context), }) return render(request, "sms/languages.html", context)
def page_context(self): context = super().page_context context.update({ 'bulk_upload': { "download_url": reverse('download_location_reassignment_template', args=[self.domain]), "adjective": _("locations"), "plural_noun": _("Location Reassignment Request File"), "verb": _("Perform"), "help_link": "https://confluence.dimagi.com/display/ICDS/Location+Reassignment", }, }) context.update({ 'bulk_upload_form': get_bulk_upload_form(context, form_class=LocationReassignmentRequestForm), "no_header": True, }) return context
def page_context(self): context = { "bulk_upload": { "download_url": reverse("product_export", args=(self.domain,)), "adjective": _("product"), "plural_noun": _("products"), } } context.update({"bulk_upload_form": get_bulk_upload_form(context)}) return context
def page_context(self): context = { 'bulk_upload': { "download_url": reverse("product_export", args=(self.domain,)), "adjective": _("product"), "plural_noun": _("products"), }, } context.update({ 'bulk_upload_form': get_bulk_upload_form(context), }) return context
def page_context(self): context = { "bulk_upload": { "help_site": {"address": BULK_MOBILE_HELP_SITE, "name": _("CommCare Help Site")}, "download_url": reverse("download_commcare_users", args=(self.domain,)), "adjective": _("mobile worker"), "plural_noun": _("mobile workers"), }, "show_secret_settings": self.request.REQUEST.get("secret", False), } context.update({"bulk_upload_form": get_bulk_upload_form(context)}) return context
def page_context(self): context = { 'bulk_upload': { "download_url": reverse("download_conditional_alert", args=(self.domain,)), "adjective": _("conditional alert"), "plural_noun": _("conditional alerts"), }, } context.update({ 'bulk_upload_form': get_bulk_upload_form(context), }) return context
def page_context(self): main_context = super(UploadDataDictionaryView, self).main_context main_context.update({ 'bulk_upload': { "download_url": reverse('export_data_dictionary', args=[self.domain]), "adjective": _("data dictionary"), "plural_noun": _("data dictionary"), }, }) main_context.update({ 'bulk_upload_form': get_bulk_upload_form(main_context), }) return main_context
def page_context(self): context = super().page_context context.update({ 'bulk_upload': { "download_url": reverse('download_multimedia_paths', args=[self.domain, self.app.get_id]), "adjective": _("multimedia paths"), "plural_noun": _("multimedia paths"), "help_link": "https://confluence.dimagi.com/display/ICDS/Multimedia+Path+Manager", }, }) context.update({ 'bulk_upload_form': get_bulk_upload_form(context), }) return context
def page_context(self): context = { 'bulk_upload': { "download_url": reverse( "location_export", args=(self.domain,)), "adjective": _("location"), "plural_noun": _("locations"), }, "manage_consumption": self.domain_object.commtrack_settings.individual_consumption_defaults, } context.update({ 'bulk_upload_form': get_bulk_upload_form(context), }) return context
def page_context(self): context = {} context.update({ 'bulk_upload': { "download_url": static( 'data_interfaces/xlsx/forms_bulk_example.xlsx'), "adjective": _("example"), "verb": _("archive"), "plural_noun": _("forms"), }, }) context.update({ 'bulk_upload_form': get_bulk_upload_form(context), }) return context
def page_context(self): context = {} context.update({ 'bulk_upload': { "download_url": static( 'data_interfaces/files/forms_bulk_example.xlsx'), "adjective": _("example"), "verb": _("archive"), "plural_noun": _("forms"), }, }) context.update({ 'bulk_upload_form': get_bulk_upload_form(context), }) return context
def page_context(self): context = { 'bulk_upload': { "download_url": reverse("location_export", args=(self.domain, )), "adjective": _("location"), "plural_noun": _("locations"), }, "manage_consumption": self.domain_object.commtrack_settings. individual_consumption_defaults, } context.update({ 'bulk_upload_form': get_bulk_upload_form(context), }) return context
def page_context(self): context = self.pagination_context context.update({ 'bulk_upload': { "download_url": static( 'data_interfaces/xlsx/cases_bulk_example.xlsx'), "adjective": _("case"), "plural_noun": _("cases"), }, 'bulk_upload_id': self.bulk_upload_id, 'update_case_group_form': self.update_case_group_form, 'group_name': self.case_group.name, }) context.update({ 'bulk_upload_form': get_bulk_upload_form(context), }) return context
def page_context(self): context = self.pagination_context context.update({ 'bulk_upload': { "download_url": static( 'data_interfaces/files/cases_bulk_example.xlsx'), "adjective": _("case"), "plural_noun": _("cases"), }, 'bulk_upload_id': self.bulk_upload_id, 'update_case_group_form': self.update_case_group_form, 'group_name': self.case_group.name, }) context.update({ 'bulk_upload_form': get_bulk_upload_form(context), }) return context
def page_context(self): context = { 'bulk_upload': { "download_url": reverse("download_conditional_alert", args=(self.domain, )), "adjective": _("SMS alert content"), "plural_noun": _("SMS alert content"), "help_link": "https://confluence.dimagi.com/display/commcarepublic/Bulk+download+and+upload+of+SMS+content+in+conditional+alerts", # noqa }, } context.update({ 'bulk_upload_form': get_bulk_upload_form(context), }) return context
def page_context(self): context = { 'bulk_upload': { "help_site": { "address": BULK_MOBILE_HELP_SITE, "name": _("CommCare Help Site"), }, "download_url": reverse( "download_commcare_users", args=(self.domain,)), "adjective": _("mobile worker"), "plural_noun": _("mobile workers"), }, 'show_secret_settings': self.request.REQUEST.get("secret", False), } context.update({ 'bulk_upload_form': get_bulk_upload_form(context), }) return context
def page_context(self): request_params = expect_GET(self.request) context = { 'bulk_upload': { "help_site": { "address": BULK_MOBILE_HELP_SITE, "name": _("CommCare Help Site"), }, "download_url": reverse( "download_commcare_users", args=(self.domain,)), "adjective": _("mobile worker"), "plural_noun": _("mobile workers"), }, 'show_secret_settings': request_params.get("secret", False), } context.update({ 'bulk_upload_form': get_bulk_upload_form(context), }) return context
def page_context(self): def _get_manage_consumption(): if self.domain_object.commtrack_settings: return self.domain_object.commtrack_settings.individual_consumption_defaults else: return False context = { 'bulk_upload': { "download_url": reverse( "location_export", args=(self.domain,)), "adjective": _("Organization Structure"), "plural_noun": _("Organization Structure"), }, "manage_consumption": _get_manage_consumption(), } context.update({ 'bulk_upload_form': get_bulk_upload_form(context), }) return context
def page_context(self): def _get_manage_consumption(): if self.domain_object.commtrack_settings: return self.domain_object.commtrack_settings.individual_consumption_defaults else: return False context = { 'bulk_upload': { "download_url": reverse("location_export", args=(self.domain, )), "adjective": _("Organization Structure"), "plural_noun": _("Organization Structure"), }, "manage_consumption": _get_manage_consumption(), } context.update({ 'bulk_upload_form': get_bulk_upload_form(context), }) return context
def get_app_view_context(request, app): is_cloudcare_allowed = has_privilege(request, privileges.CLOUDCARE) context = {} settings_layout = copy.deepcopy(get_commcare_settings_layout(request.domain)[app.get_doc_type()]) 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 new_settings.append(setting) section["settings"] = new_settings if toggles.CUSTOM_PROPERTIES.enabled(request.domain) and "custom_properties" in app.profile: custom_properties_array = map( lambda p: {"key": p[0], "value": p[1]}, app.profile.get("custom_properties").items() ) context.update({"custom_properties": custom_properties_array}) context.update( { "settings_layout": settings_layout, "settings_values": get_settings_values(app), "is_cloudcare_allowed": is_cloudcare_allowed, } ) build_config = CommCareBuildConfig.fetch() options = build_config.get_menu() if not request.user.is_superuser: 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() (build_spec_setting,) = filter( lambda x: x["type"] == "hq" and x["id"] == "build_spec", [setting for section in context["settings_layout"] for setting in section["settings"]], ) build_spec_setting["options_map"] = options_map build_spec_setting["default_app_version"] = app.application_version 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"U\u200BI translation"), "plural_noun": _(u"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"), }, } ) 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"), } ) context["is_app_view"] = True try: context["fetchLimit"] = int(request.GET.get("limit", DEFAULT_FETCH_LIMIT)) except ValueError: context["fetchLimit"] = DEFAULT_FETCH_LIMIT return context
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.get_doc_type()) ) 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 app.get_doc_type() == 'LinkedApplication': 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), }, '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) }) # Not used in APP_MANAGER_V2 context['is_app_view'] = True if app.get_doc_type() == 'LinkedApplication': context['upstream_url'] = _get_upstream_url(app, request.couch_user) try: context['master_version'] = app.get_master_version() except RemoteRequestError: pass return context
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(request.user)[app.get_doc_type()] ) 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 new_settings.append(setting) section['settings'] = new_settings app_view_options = { 'permissions': { 'cloudcare': has_privilege(request, privileges.CLOUDCARE), }, '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 toggles.CUSTOM_PROPERTIES.enabled(request.domain) and 'custom_properties' in getattr(app, 'profile', {}): custom_properties_array = map(lambda p: {'key': p[0], 'value': p[1]}, 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: 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 = filter( lambda x: x['type'] == setting_type and x['id'] == setting_id, [ setting for section in settings_layout for setting in section['settings'] ] ) 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"U\u200BI translation"), 'plural_noun': _(u"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"), }, }) 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" ) }) # Not used in APP_MANAGER_V2 context['is_app_view'] = True try: context['fetchLimit'] = int(request.GET.get('limit', DEFAULT_FETCH_LIMIT)) except ValueError: context['fetchLimit'] = DEFAULT_FETCH_LIMIT if app.get_doc_type() == 'LinkedApplication': context['master_version'] = get_app(None, app.master, latest=True).version return context
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: master_versions_by_id = app.get_latest_master_releases_versions() master_briefs = [brief for brief in app.get_master_app_briefs() if brief.id in master_versions_by_id] except RemoteRequestError: messages.error(request, "Unable to reach remote master server. Please try again later.") master_versions_by_id = {} master_briefs = [] upstream_brief = {} for b in master_briefs: if b.id == app.upstream_app_id: upstream_brief = b context.update({ 'master_briefs': master_briefs, 'master_versions_by_id': master_versions_by_id, 'multiple_masters': app.enable_multi_master and len(master_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, master_app_id='---'), }) return context
def get_app_view_context(request, app): is_cloudcare_allowed = has_privilege(request, privileges.CLOUDCARE) context = {} settings_layout = copy.deepcopy( get_commcare_settings_layout()[app.get_doc_type()]) 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 new_settings.append(setting) section['settings'] = new_settings if toggles.CUSTOM_PROPERTIES.enabled(request.domain) and 'custom_properties' in app.profile: custom_properties_array = map(lambda p: {'key': p[0], 'value': p[1]}, app.profile.get('custom_properties').items()) context.update({'custom_properties': custom_properties_array}) context.update({ 'settings_layout': settings_layout, 'settings_values': get_settings_values(app), 'is_cloudcare_allowed': is_cloudcare_allowed, }) build_config = CommCareBuildConfig.fetch() options = build_config.get_menu() if not request.user.is_superuser: 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() (build_spec_setting,) = filter( lambda x: x['type'] == 'hq' and x['id'] == 'build_spec', [setting for section in context['settings_layout'] for setting in section['settings']] ) build_spec_setting['options_map'] = options_map build_spec_setting['default_app_version'] = app.application_version 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"U\u200BI translation"), 'plural_noun': _(u"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"), }, }) 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" ) }) context['is_app_view'] = True return context
def get_app_view_context(request, app): is_cloudcare_allowed = has_privilege(request, privileges.CLOUDCARE) context = {} settings_layout = copy.deepcopy( get_commcare_settings_layout(request.domain)[app.get_doc_type()]) 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 new_settings.append(setting) section['settings'] = new_settings if toggles.CUSTOM_PROPERTIES.enabled( request.domain) and 'custom_properties' in app.profile: custom_properties_array = map( lambda p: { 'key': p[0], 'value': p[1] }, app.profile.get('custom_properties').items()) context.update({'custom_properties': custom_properties_array}) context.update({ 'settings_layout': settings_layout, 'settings_values': get_settings_values(app), 'is_cloudcare_allowed': is_cloudcare_allowed, }) build_config = CommCareBuildConfig.fetch() options = build_config.get_menu() if not request.user.is_superuser: 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() (build_spec_setting, ) = filter( lambda x: x['type'] == 'hq' and x['id'] == 'build_spec', [ setting for section in context['settings_layout'] for setting in section['settings'] ]) if context['settings_layout'] else (None, ) if build_spec_setting: build_spec_setting['options_map'] = options_map build_spec_setting['default_app_version'] = app.application_version 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"U\u200BI translation"), 'plural_noun': _(u"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"), }, }) 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") }) context['is_app_view'] = True try: context['fetchLimit'] = int( request.GET.get('limit', DEFAULT_FETCH_LIMIT)) except ValueError: context['fetchLimit'] = DEFAULT_FETCH_LIMIT if app.get_doc_type() == 'LinkedApplication': context['master_version'] = get_app(None, app.master, latest=True).version return context
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 = { 'legacy_select2': True, } settings_layout = copy.deepcopy( get_commcare_settings_layout(app.get_doc_type())) 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 new_settings.append(setting) section['settings'] = new_settings app_view_options = { 'permissions': { 'cloudcare': has_privilege(request, privileges.CLOUDCARE), }, '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_validate_app_translations': toggles.VALIDATE_APP_TRANSLATIONS.enabled_for_request(request) }, 'bulk_app_multimedia_upload': { 'action': reverse( 'upload_bulk_app_translations', # TODO args=(app.domain, app.get_id)), 'download_url': reverse('download_bulk_multimedia_translations', args=(app.domain, app.get_id)), 'adjective': _("multimedia"), 'plural_noun': _("multimedia references"), }, }) 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, app=app, ), 'bulk_multimedia_translation_form': get_bulk_upload_form( context, context_key="bulk_app_multimedia_upload", form_class=MultimediaTranslationsBulkUploadForm, ), }) context.update({ 'smart_lang_display_enabled': getattr(app, 'smart_lang_display', False) }) # Not used in APP_MANAGER_V2 context['is_app_view'] = True if app.get_doc_type() == 'LinkedApplication': context['upstream_url'] = _get_upstream_url(app, request.couch_user) try: context['master_version'] = app.get_master_version() except RemoteRequestError: pass return context