def _update_commcare_build_menu(version): build_config_doc = CommCareBuildConfig.fetch() _add_build_menu_item(build_config_doc, version) _update_default_build_spec_to_version(build_config_doc, version) build_config_doc.save() CommCareBuildConfig.clear_local_cache()
def commcare_version_report(request, template="hqadmin/commcare_version.html"): apps = get_db().view("app_manager/applications_brief").all() menu = CommCareBuildConfig.fetch().menu builds = [item.build.to_string() for item in menu] by_build = dict([(item.build.to_string(), {"label": item.label, "apps": []}) for item in menu]) for app in apps: app = app["value"] app["id"] = app["_id"] if app.get("build_spec"): build_spec = BuildSpec.wrap(app["build_spec"]) build = build_spec.to_string() if by_build.has_key(build): by_build[build]["apps"].append(app) else: by_build[build] = {"label": build_spec.get_label(), "apps": [app]} builds.append(build) tables = [] for build in builds: by_build[build]["build"] = build tables.append(by_build[build]) context = get_hqadmin_base_context(request) context.update({"tables": tables}) context["hide_filters"] = True return render(request, template, context)
def releases_ajax(request, domain, app_id, template='app_manager/partials/releases.html'): app = get_app(domain, app_id) context = get_apps_base_context(request, domain, app) can_send_sms = domain_has_privilege(domain, privileges.OUTBOUND_SMS) build_profile_access = domain_has_privilege(domain, privileges.BUILD_PROFILES) context.update({ 'release_manager': True, 'can_send_sms': can_send_sms, 'has_mobile_workers': get_doc_count_in_domain_by_class(domain, CommCareUser) > 0, 'sms_contacts': ( get_sms_autocomplete_context(request, domain)['sms_contacts'] if can_send_sms else [] ), 'build_profile_access': build_profile_access, 'lastest_j2me_enabled_build': CommCareBuildConfig.latest_j2me_enabled_config().label, 'vellum_case_management': app.vellum_case_management, 'fetchLimit': request.GET.get('limit', DEFAULT_FETCH_LIMIT), }) if not app.is_remote_app(): # Multimedia is not supported for remote applications at this time. try: multimedia_state = app.check_media_state() context.update({ 'multimedia_state': multimedia_state, }) except ReportConfigurationNotFoundError: pass response = render(request, template, context) response.set_cookie('lang', encode_if_unicode(context['lang'])) return response
def paginate_releases(request, domain, app_id): limit = request.GET.get('limit') try: limit = int(limit) except (TypeError, ValueError): limit = 10 start_build_param = request.GET.get('start_build') if start_build_param and json.loads(start_build_param): start_build = json.loads(start_build_param) assert isinstance(start_build, int) else: start_build = {} timezone = get_timezone_for_user(request.couch_user, domain) saved_apps = Application.get_db().view( 'app_manager/saved_app', startkey=[domain, app_id, start_build], endkey=[domain, app_id], descending=True, limit=limit, wrapper=lambda x: SavedAppBuild.wrap(x['value']).to_saved_build_json( timezone), ).all() j2me_enabled_configs = CommCareBuildConfig.j2me_enabled_config_labels() for app in saved_apps: app['include_media'] = app['doc_type'] != 'RemoteApp' app['j2me_enabled'] = app['menu_item_label'] in j2me_enabled_configs if toggles.APPLICATION_ERROR_REPORT.enabled(request.couch_user.username): versions = [app['version'] for app in saved_apps] num_errors_dict = _get_error_counts(domain, app_id, versions) for app in saved_apps: app['num_errors'] = num_errors_dict.get(app['version'], 0) return json_response(saved_apps)
def commcare_version_report(request, template="hqadmin/commcare_version.html"): apps = get_db().view('app_manager/applications_brief').all() menu = CommCareBuildConfig.fetch().menu builds = [item.build.to_string() for item in menu] by_build = dict([(item.build.to_string(), { "label": item.label, "apps": [] }) for item in menu]) for app in apps: app = app['value'] app['id'] = app['_id'] if app.get('build_spec'): build_spec = BuildSpec.wrap(app['build_spec']) build = build_spec.to_string() if by_build.has_key(build): by_build[build]['apps'].append(app) else: by_build[build] = { "label": build_spec.get_label(), "apps": [app] } builds.append(build) tables = [] for build in builds: by_build[build]['build'] = build tables.append(by_build[build]) context = get_hqadmin_base_context(request) context.update({'tables': tables}) context['hide_filters'] = True return render(request, template, context)
def save_copy(request, domain, app_id): """ Saves a copy of the app to a new doc. See VersionedDoc.save_copy """ track_built_app_on_hubspot.delay(request.couch_user) comment = request.POST.get('comment') app = get_app(domain, app_id) try: errors = app.validate_app() except ModuleIdMissingException: # For apps (mainly Exchange apps) that lost unique_id attributes on Module app.ensure_module_unique_ids(should_save=True) errors = app.validate_app() if not errors: try: copy = app.make_build( comment=comment, user_id=request.couch_user.get_id, previous_version=app.get_latest_app(released_only=False)) copy.save(increment_version=False) finally: # To make a RemoteApp always available for building if app.is_remote_app(): app.save(increment_version=True) _track_build_for_app_preview(domain, request.couch_user, app_id, 'User created a build') else: copy = None copy = copy and SavedAppBuild.wrap(copy.to_json()).to_saved_build_json( get_timezone_for_user(request.couch_user, domain)) lang, langs = get_langs(request, app) if copy: # Set if build is supported for Java Phones j2me_enabled_configs = CommCareBuildConfig.j2me_enabled_config_labels() copy['j2me_enabled'] = copy['menu_item_label'] in j2me_enabled_configs template = get_app_manager_template( request.user, "app_manager/v1/partials/build_errors.html", "app_manager/v2/partials/build_errors.html", ) return json_response({ "saved_app": copy, "error_html": render_to_string( template, { 'request': request, 'app': get_app(domain, app_id), 'build_errors': errors, 'domain': domain, 'langs': langs, 'lang': lang }), })
def get_releases_context(request, domain, app_id): app = get_app(domain, app_id) context = get_apps_base_context(request, domain, app) can_send_sms = domain_has_privilege(domain, privileges.OUTBOUND_SMS) build_profile_access = domain_has_privilege(domain, privileges.BUILD_PROFILES) context.update({ 'intro_only': len(app.modules) == 0 and toggles.APP_MANAGER_V2.enabled(domain), 'release_manager': True, 'can_send_sms': can_send_sms, 'has_mobile_workers': get_doc_count_in_domain_by_class(domain, CommCareUser) > 0, 'sms_contacts': (get_sms_autocomplete_context( request, domain)['sms_contacts'] if can_send_sms else []), 'build_profile_access': build_profile_access and not toggles.APP_MANAGER_V2.enabled(domain), 'lastest_j2me_enabled_build': CommCareBuildConfig.latest_j2me_enabled_config().label, 'fetchLimit': request.GET.get('limit', DEFAULT_FETCH_LIMIT), }) if not app.is_remote_app(): # Multimedia is not supported for remote applications at this time. try: multimedia_state = app.check_media_state() context.update({ 'multimedia_state': multimedia_state, }) except ReportConfigurationNotFoundError: pass return context
def releases_ajax(request, domain, app_id, template='app_manager/v1/partials/releases.html'): app = get_app(domain, app_id) context = get_apps_base_context(request, domain, app) can_send_sms = domain_has_privilege(domain, privileges.OUTBOUND_SMS) build_profile_access = domain_has_privilege(domain, privileges.BUILD_PROFILES) context.update({ 'intro_only': len(app.modules) == 0, 'release_manager': True, 'can_send_sms': can_send_sms, 'has_mobile_workers': get_doc_count_in_domain_by_class(domain, CommCareUser) > 0, 'sms_contacts': ( get_sms_autocomplete_context(request, domain)['sms_contacts'] if can_send_sms else [] ), 'build_profile_access': build_profile_access and not toggles.APP_MANAGER_V2.enabled(domain), 'lastest_j2me_enabled_build': CommCareBuildConfig.latest_j2me_enabled_config().label, 'fetchLimit': request.GET.get('limit', DEFAULT_FETCH_LIMIT), }) if not app.is_remote_app(): # Multimedia is not supported for remote applications at this time. try: multimedia_state = app.check_media_state() context.update({ 'multimedia_state': multimedia_state, }) except ReportConfigurationNotFoundError: pass response = render(request, template, context) response.set_cookie('lang', encode_if_unicode(context['lang'])) return response
def paginate_releases(request, domain, app_id): limit = request.GET.get('limit') try: limit = int(limit) except (TypeError, ValueError): limit = 10 start_build_param = request.GET.get('start_build') if start_build_param and json.loads(start_build_param): start_build = json.loads(start_build_param) assert isinstance(start_build, int) else: start_build = {} timezone = get_timezone_for_user(request.couch_user, domain) saved_apps = Application.get_db().view('app_manager/saved_app', startkey=[domain, app_id, start_build], endkey=[domain, app_id], descending=True, limit=limit, wrapper=lambda x: SavedAppBuild.wrap(x['value']).to_saved_build_json(timezone), ).all() j2me_enabled_configs = CommCareBuildConfig.j2me_enabled_config_labels() for app in saved_apps: app['include_media'] = app['doc_type'] != 'RemoteApp' app['j2me_enabled'] = app['menu_item_label'] in j2me_enabled_configs if toggles.APPLICATION_ERROR_REPORT.enabled(request.couch_user.username): versions = [app['version'] for app in saved_apps] num_errors_dict = _get_error_counts(domain, app_id, versions) for app in saved_apps: app['num_errors'] = num_errors_dict.get(app['version'], 0) return json_response(saved_apps)
def get_commcare_builds(request_user): can_view_superuser_builds = (request_user.is_superuser or toggles.IS_CONTRACTOR.enabled( request_user.username)) return [ i.build for i in CommCareBuildConfig.fetch().menu if can_view_superuser_builds or not i.superuser_only ]
def get_commcare_builds(request_user): can_view_superuser_builds = (request_user.is_superuser or toggles.IS_CONTRACTOR.enabled(request_user.username)) return [ i.build for i in CommCareBuildConfig.fetch().menu if can_view_superuser_builds or not i.superuser_only ]
def save_copy(request, domain, app_id): """ Saves a copy of the app to a new doc. See VersionedDoc.save_copy """ track_built_app_on_hubspot_v2.delay(request.couch_user) comment = request.POST.get('comment') app = get_app(domain, app_id) try: errors = app.validate_app() except ModuleIdMissingException: # For apps (mainly Exchange apps) that lost unique_id attributes on Module app.ensure_module_unique_ids(should_save=True) errors = app.validate_app() if not errors: try: user_id = request.couch_user.get_id timer = datadog_bucket_timer('commcare.app_build.new_release', tags=[], timing_buckets=(1, 10, 30, 60, 120, 240)) with timer: copy = app.make_build( comment=comment, user_id=user_id, ) copy.save(increment_version=False) CouchUser.get(user_id).set_has_built_app() finally: # To make a RemoteApp always available for building if app.is_remote_app(): app.save(increment_version=True) _track_build_for_app_preview(domain, request.couch_user, app_id, 'User created a build') else: copy = None copy = copy and SavedAppBuild.wrap(copy.to_json()).releases_list_json( get_timezone_for_user(request.couch_user, domain) ) lang, langs = get_langs(request, app) if copy: # Set if build is supported for Java Phones j2me_enabled_configs = CommCareBuildConfig.j2me_enabled_config_labels() copy['j2me_enabled'] = copy['menu_item_label'] in j2me_enabled_configs return json_response({ "saved_app": copy, "error_html": render_to_string("app_manager/partials/build_errors.html", { 'request': request, 'app': get_app(domain, app_id), 'build_errors': errors, 'domain': domain, 'langs': langs, 'lang': lang }), })
def get_releases_context(request, domain, app_id): app = get_app(domain, app_id) context = get_apps_base_context(request, domain, app) can_send_sms = domain_has_privilege(domain, privileges.OUTBOUND_SMS) build_profile_access = domain_has_privilege(domain, privileges.BUILD_PROFILES) prompt_settings_form = PromptUpdateSettingsForm.from_app( app, request_user=request.couch_user) context.update({ 'release_manager': True, 'can_send_sms': can_send_sms, 'has_mobile_workers': get_doc_count_in_domain_by_class(domain, CommCareUser) > 0, 'sms_contacts': (get_sms_autocomplete_context( request, domain)['sms_contacts'] if can_send_sms else []), 'build_profile_access': build_profile_access, 'application_profile_url': reverse(LanguageProfilesView.urlname, args=[domain, app_id]), 'lastest_j2me_enabled_build': CommCareBuildConfig.latest_j2me_enabled_config().label, 'fetchLimit': request.GET.get('limit', DEFAULT_FETCH_LIMIT), 'latest_build_id': get_latest_build_id(domain, app_id), 'prompt_settings_url': reverse(PromptSettingsUpdateView.urlname, args=[domain, app_id]), 'prompt_settings_form': prompt_settings_form, }) if not app.is_remote_app(): context.update({ 'enable_update_prompts': app.enable_update_prompts, }) if not toggles.USER_TESTING_SIMPLIFY.enabled_for_request(request): ab = ab_tests.ABTest(ab_tests.APP_BUILDER_VIDEO, request) context.update({ 'ab_test': ab.context, 'show_video': ab.version == ab_tests.APP_BUILDER_VIDEO_ON, }) if len(app.modules) == 0: context.update({'intro_only': True}) # Multimedia is not supported for remote applications at this time. try: multimedia_state = app.check_media_state() context.update({ 'multimedia_state': multimedia_state, }) except ReportConfigurationNotFoundError: pass return context
def get_releases_context(request, domain, app_id): app = get_app(domain, app_id) can_send_sms = domain_has_privilege(domain, privileges.OUTBOUND_SMS) build_profile_access = domain_has_privilege(domain, privileges.BUILD_PROFILES) prompt_settings_form = PromptUpdateSettingsForm.from_app( app, request_user=request.couch_user) context = { 'release_manager': True, 'can_send_sms': can_send_sms, 'can_view_cloudcare': has_privilege(request, privileges.CLOUDCARE), 'has_mobile_workers': get_doc_count_in_domain_by_class(domain, CommCareUser) > 0, 'latest_released_version': get_latest_released_app_version(domain, app_id), 'sms_contacts': (get_sms_autocomplete_context( request, domain)['sms_contacts'] if can_send_sms else []), 'build_profile_access': build_profile_access, 'application_profile_url': reverse(LanguageProfilesView.urlname, args=[domain, app_id]), 'lastest_j2me_enabled_build': CommCareBuildConfig.latest_j2me_enabled_config().label, 'latest_build_id': get_latest_build_id(domain, app_id), 'prompt_settings_url': reverse(PromptSettingsUpdateView.urlname, args=[domain, app_id]), 'prompt_settings_form': prompt_settings_form, 'full_name': request.couch_user.full_name, 'can_manage_releases': can_manage_releases(request.couch_user, request.domain, app_id), 'can_edit_apps': request.couch_user.can_edit_apps(), } if not app.is_remote_app(): context.update({ 'enable_update_prompts': app.enable_update_prompts, }) if len(app.modules) == 0: context.update({'intro_only': True}) # Multimedia is not supported for remote applications at this time. try: multimedia_state = app.check_media_state() context.update({ 'multimedia_state': multimedia_state, }) except ReportConfigurationNotFoundError: pass return context
def paginate_releases(request, domain, app_id): limit = request.GET.get('limit') only_show_released = json.loads( request.GET.get('only_show_released', 'false')) build_comment = request.GET.get('build_comment') page = int(request.GET.get('page', 1)) page = max(page, 1) try: limit = int(limit) except (TypeError, ValueError): limit = 10 timezone = get_timezone_for_user(request.couch_user, domain) app_es = (AppES().start((page - 1) * limit).size(limit).sort( 'version', desc=True).domain(domain).is_build().app_id(app_id)) if only_show_released: app_es = app_es.is_released() if build_comment: app_es = app_es.build_comment(build_comment) results = app_es.exclude_source().run() app_ids = results.doc_ids apps = get_docs(Application.get_db(), app_ids) for app in apps: app.pop('translations') saved_apps = [ SavedAppBuild.wrap( app, scrap_old_conventions=False).to_saved_build_json(timezone) for app in apps ] j2me_enabled_configs = CommCareBuildConfig.j2me_enabled_config_labels() for app in saved_apps: app['include_media'] = app['doc_type'] != 'RemoteApp' app['j2me_enabled'] = app['menu_item_label'] in j2me_enabled_configs app['target_commcare_flavor'] = ( SavedAppBuild.get(app['_id']).target_commcare_flavor if toggles.TARGET_COMMCARE_FLAVOR.enabled(domain) else 'none') if toggles.APPLICATION_ERROR_REPORT.enabled(request.couch_user.username): versions = [app['version'] for app in saved_apps] num_errors_dict = _get_error_counts(domain, app_id, versions) for app in saved_apps: app['num_errors'] = num_errors_dict.get(app['version'], 0) total_apps = results.total num_pages = int(ceil(total_apps / limit)) return json_response({ 'apps': saved_apps, 'pagination': { 'total': total_apps, 'num_pages': num_pages, 'current_page': page, } })
def paginate_releases(request, domain, app_id): limit = request.GET.get('limit') only_show_released = json.loads( request.GET.get('only_show_released', 'false')) try: limit = int(limit) except (TypeError, ValueError): limit = 10 start_build_param = request.GET.get('start_build') if start_build_param and json.loads(start_build_param): start_build = json.loads(start_build_param) assert isinstance(start_build, int) else: start_build = {} timezone = get_timezone_for_user(request.couch_user, domain) saved_apps = [] batch = [None] while len(saved_apps) < limit and len(batch): batch = Application.get_db().view( 'app_manager/saved_app', startkey=[domain, app_id, start_build], endkey=[domain, app_id], descending=True, limit=limit, wrapper=lambda x: SavedAppBuild.wrap(x['value']). to_saved_build_json(timezone), ).all() if len(batch): start_build = batch[-1]['version'] - 1 saved_apps = saved_apps + [ app for app in batch if not only_show_released or app['is_released'] ] saved_apps = saved_apps[:limit] j2me_enabled_configs = CommCareBuildConfig.j2me_enabled_config_labels() for app in saved_apps: app['include_media'] = app['doc_type'] != 'RemoteApp' app['j2me_enabled'] = app['menu_item_label'] in j2me_enabled_configs app['target_commcare_flavor'] = ( SavedAppBuild.get(app['_id']).target_commcare_flavor if toggles.TARGET_COMMCARE_FLAVOR.enabled(domain) else 'none') if toggles.APPLICATION_ERROR_REPORT.enabled(request.couch_user.username): versions = [app['version'] for app in saved_apps] num_errors_dict = _get_error_counts(domain, app_id, versions) for app in saved_apps: app['num_errors'] = num_errors_dict.get(app['version'], 0) return json_response(saved_apps)
def get_releases_context(request, domain, app_id): app = get_app(domain, app_id) can_send_sms = domain_has_privilege(domain, privileges.OUTBOUND_SMS) build_profile_access = domain_has_privilege(domain, privileges.BUILD_PROFILES) prompt_settings_form = PromptUpdateSettingsForm.from_app(app, request_user=request.couch_user) context = { 'release_manager': True, 'can_send_sms': can_send_sms, 'can_view_cloudcare': has_privilege(request, privileges.CLOUDCARE), 'has_mobile_workers': get_doc_count_in_domain_by_class(domain, CommCareUser) > 0, 'latest_released_version': get_latest_released_app_version(domain, app_id), 'sms_contacts': ( get_sms_autocomplete_context(request, domain)['sms_contacts'] if can_send_sms else [] ), 'build_profile_access': build_profile_access, 'application_profile_url': reverse(LanguageProfilesView.urlname, args=[domain, app_id]), 'lastest_j2me_enabled_build': CommCareBuildConfig.latest_j2me_enabled_config().label, 'fetchLimit': request.GET.get('limit', DEFAULT_FETCH_LIMIT), 'latest_build_id': get_latest_build_id(domain, app_id), 'prompt_settings_url': reverse(PromptSettingsUpdateView.urlname, args=[domain, app_id]), 'prompt_settings_form': prompt_settings_form, 'full_name': request.couch_user.full_name, 'can_manage_releases': can_manage_releases(request.couch_user, request.domain, app_id) } if not app.is_remote_app(): context.update({ 'enable_update_prompts': app.enable_update_prompts, }) if len(app.modules) == 0: context.update({'intro_only': True}) # Multimedia is not supported for remote applications at this time. try: multimedia_state = app.check_media_state() context.update({ 'multimedia_state': multimedia_state, }) except ReportConfigurationNotFoundError: 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 = { '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
def get_commcare_versions(request_user): versions = [ i.build.version for i in CommCareBuildConfig.fetch().menu if request_user.is_superuser or not i.superuser_only ] return sorted(versions, key=version_key)
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 paginate_releases(request, domain, app_id): limit = request.GET.get('limit') only_show_released = json.loads(request.GET.get('only_show_released', 'false')) build_comment = request.GET.get('build_comment') page = int(request.GET.get('page', 1)) page = max(page, 1) try: limit = int(limit) except (TypeError, ValueError): limit = 10 skip = (page - 1) * limit timezone = get_timezone_for_user(request.couch_user, domain) def _get_batch(start_build=None, skip=None): start_build = {} if start_build is None else start_build return Application.get_db().view('app_manager/saved_app', startkey=[domain, app_id, start_build], endkey=[domain, app_id], descending=True, limit=limit, skip=skip, wrapper=lambda x: SavedAppBuild.wrap(x['value'], scrap_old_conventions=False).releases_list_json(timezone), ).all() if not bool(only_show_released or build_comment): # If user is limiting builds by released status or build comment, it's much # harder to be performant with couch. So if they're not doing so, take shortcuts. total_apps = len(get_built_app_ids_for_app_id(domain, app_id)) saved_apps = _get_batch(skip=skip) else: app_es = ( AppES() .start((page - 1) * limit) .size(limit) .sort('version', desc=True) .domain(domain) .is_build() .app_id(app_id) ) if only_show_released: app_es = app_es.is_released() if build_comment: app_es = app_es.build_comment(build_comment) results = app_es.exclude_source().run() app_ids = results.doc_ids apps = get_docs(Application.get_db(), app_ids) saved_apps = [ SavedAppBuild.wrap(app, scrap_old_conventions=False).releases_list_json(timezone) for app in apps ] total_apps = results.total j2me_enabled_configs = CommCareBuildConfig.j2me_enabled_config_labels() for app in saved_apps: app['include_media'] = app['doc_type'] != 'RemoteApp' app['j2me_enabled'] = app['menu_item_label'] in j2me_enabled_configs app['target_commcare_flavor'] = ( SavedAppBuild.get(app['_id']).target_commcare_flavor if toggles.TARGET_COMMCARE_FLAVOR.enabled(domain) else 'none' ) if toggles.APPLICATION_ERROR_REPORT.enabled(request.couch_user.username): versions = [app['version'] for app in saved_apps] num_errors_dict = _get_error_counts(domain, app_id, versions) for app in saved_apps: app['num_errors'] = num_errors_dict.get(app['version'], 0) num_pages = int(ceil(total_apps / limit)) return json_response({ 'apps': saved_apps, 'pagination': { 'total': total_apps, 'num_pages': num_pages, 'current_page': 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.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_commcare_versions(request_user): versions = [i.build.version for i in CommCareBuildConfig.fetch().menu if request_user.is_superuser or not i.superuser_only] return sorted(versions, key=version_key)
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_commcare_builds(request_user): return [ i.build for i in CommCareBuildConfig.fetch().menu if request_user.is_superuser or not i.superuser_only ]
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_commcare_version(request, app_id, app_version): options = CommCareBuildConfig.fetch().get_menu(app_version) return json_response(options)
def paginate_releases(request, domain, app_id): limit = request.GET.get('limit') only_show_released = json.loads(request.GET.get('only_show_released', 'false')) query = request.GET.get('query') page = int(request.GET.get('page', 1)) page = max(page, 1) try: limit = int(limit) except (TypeError, ValueError): limit = 10 skip = (page - 1) * limit timezone = get_timezone_for_user(request.couch_user, domain) def _get_batch(start_build=None, skip=None): start_build = {} if start_build is None else start_build return Application.get_db().view('app_manager/saved_app', startkey=[domain, app_id, start_build], endkey=[domain, app_id], descending=True, limit=limit, skip=skip, wrapper=lambda x: SavedAppBuild.wrap(x['value'], scrap_old_conventions=False).releases_list_json(timezone), ).all() if not bool(only_show_released or query): # If user is limiting builds by released status or build comment, it's much # harder to be performant with couch. So if they're not doing so, take shortcuts. total_apps = len(get_built_app_ids_for_app_id(domain, app_id)) saved_apps = _get_batch(skip=skip) else: app_es = ( AppES() .start((page - 1) * limit) .size(limit) .sort('version', desc=True) .domain(domain) .is_build() .app_id(app_id) ) if only_show_released: app_es = app_es.is_released() if query: app_es = app_es.add_query(build_comment(query), queries.SHOULD) app_es = app_es.add_query(version(query), queries.SHOULD) results = app_es.exclude_source().run() total_apps = results.total app_ids = results.doc_ids apps = get_docs(Application.get_db(), app_ids) saved_apps = [ SavedAppBuild.wrap(app, scrap_old_conventions=False).releases_list_json(timezone) for app in apps ] j2me_enabled_configs = CommCareBuildConfig.j2me_enabled_config_labels() for app in saved_apps: app['include_media'] = app['doc_type'] != 'RemoteApp' app['j2me_enabled'] = app['menu_item_label'] in j2me_enabled_configs app['target_commcare_flavor'] = ( SavedAppBuild.get(app['_id']).target_commcare_flavor if toggles.TARGET_COMMCARE_FLAVOR.enabled(domain) else 'none' ) if toggles.APPLICATION_ERROR_REPORT.enabled(request.couch_user.username): versions = [app['version'] for app in saved_apps] num_errors_dict = _get_error_counts(domain, app_id, versions) for app in saved_apps: app['num_errors'] = num_errors_dict.get(app['version'], 0) num_pages = int(ceil(total_apps / limit)) return json_response({ 'apps': saved_apps, 'pagination': { 'total': total_apps, 'num_pages': num_pages, 'current_page': page, 'more': page * limit < total_apps, # needed when select2 uses this endpoint } })
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_releases_context(request, domain, app_id): app = get_app(domain, app_id) context = get_apps_base_context(request, domain, app) can_send_sms = domain_has_privilege(domain, privileges.OUTBOUND_SMS) build_profile_access = domain_has_privilege(domain, privileges.BUILD_PROFILES) prompt_settings_form = PromptUpdateSettingsForm.from_app( app, request_user=request.couch_user) is_in_mobile_experiment = toggles.MOBILE_SIGNUP_REDIRECT_AB_TEST_CONTROLLER.enabled( request.couch_user.username) is_mobile_ab = toggles.MOBILE_SIGNUP_REDIRECT_AB_TEST.enabled( request.couch_user.username, toggles.NAMESPACE_USER) if is_in_mobile_experiment: context.update({ 'mobile_experience_ab_test': { 'name': 'mobile_signups_test_march2018test', 'version': 'variation' if is_mobile_ab else 'control', }, }) context.update({ 'release_manager': True, 'can_send_sms': can_send_sms, 'can_view_cloudcare': has_privilege(request, privileges.CLOUDCARE), 'has_mobile_workers': get_doc_count_in_domain_by_class(domain, CommCareUser) > 0, 'sms_contacts': (get_sms_autocomplete_context( request, domain)['sms_contacts'] if can_send_sms else []), 'build_profile_access': build_profile_access, 'application_profile_url': reverse(LanguageProfilesView.urlname, args=[domain, app_id]), 'lastest_j2me_enabled_build': CommCareBuildConfig.latest_j2me_enabled_config().label, 'fetchLimit': request.GET.get('limit', DEFAULT_FETCH_LIMIT), 'latest_build_id': get_latest_build_id(domain, app_id), 'prompt_settings_url': reverse(PromptSettingsUpdateView.urlname, args=[domain, app_id]), 'prompt_settings_form': prompt_settings_form, 'full_name': request.couch_user.full_name, 'is_mobile_experience': (is_in_mobile_experiment and is_mobile_ab), }) if not app.is_remote_app(): context.update({ 'enable_update_prompts': app.enable_update_prompts, }) if len(app.modules) == 0: context.update({'intro_only': True}) # Multimedia is not supported for remote applications at this time. try: multimedia_state = app.check_media_state() context.update({ 'multimedia_state': multimedia_state, }) except ReportConfigurationNotFoundError: pass return context