本文整理汇总了Python中corehq.apps.builds.models.CommCareBuildConfig类的典型用法代码示例。如果您正苦于以下问题:Python CommCareBuildConfig类的具体用法?Python CommCareBuildConfig怎么用?Python CommCareBuildConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommCareBuildConfig类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: commcare_version_report
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)
示例2: get_commcare_builds
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
]
示例3: save_copy
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
}),
})
示例4: get_releases_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,
'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
示例5: get_app_view_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
示例6: paginate_releases
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,
}
})
示例7: get_commcare_versions
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)
示例8: get_commcare_version
def get_commcare_version(request, app_id, app_version):
options = CommCareBuildConfig.fetch().get_menu(app_version)
return json_response(options)
示例9: get_app_view_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