def save_copy(request, domain, app_id): """ Saves a copy of the app to a new doc. See ApplicationBase.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: 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 = make_app_build(app, comment, user_id) CouchUser.get(user_id).set_has_built_app() except BuildConflictException: return JsonResponse( { 'error': _("There is already a version build in progress. Please wait." ) }, status=400) 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) return json_response({ "saved_app": copy, "error_html": render_to_string( "app_manager/partials/build_errors.html", { 'app': get_app(domain, app_id), 'build_errors': errors, 'domain': domain, 'langs': langs, }), })
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 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 return json_response({ "saved_app": copy, "error_html": render_to_string('app_manager/v1/partials/build_errors.html', { 'request': request, 'app': get_app(domain, app_id), 'build_errors': errors, 'domain': domain, 'langs': langs, 'lang': lang }), })
def save_copy(request, domain, app_id): """ Saves a copy of the app to a new doc. """ track_built_app_on_hubspot.delay(request.couch_user.get_id) comment = request.POST.get('comment') app = get_app(domain, app_id) try: user_id = request.couch_user.get_id with report_build_time(domain, app._id, 'new_release'): copy = make_app_build(app, comment, user_id) CouchUser.get(user_id).set_has_built_app() except AppValidationError as e: lang, langs = get_langs(request, app) return JsonResponse({ "saved_app": None, "error_html": render_to_string( "app_manager/partials/build_errors.html", { 'app': get_app(domain, app_id), 'build_errors': e.errors, 'domain': domain, 'langs': langs, 'toggles': toggles_enabled_for_request(request), }), }) except BuildConflictException: return JsonResponse( { 'error': _("There is already a version build in progress. Please wait.") }, status=400) except XFormValidationFailed: return JsonResponse({'error': _("Unable to validate forms.")}, status=400) 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') copy_json = copy and SavedAppBuild.wrap(copy.to_json()).releases_list_json( get_timezone_for_user(request.couch_user, domain)) return JsonResponse({ "saved_app": copy_json, "error_html": "", })
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) 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) return json_response( { "saved_app": copy, "error_html": render_to_string( "app_manager/partials/build_errors.html", { "app": get_app(domain, app_id), "build_errors": errors, "domain": domain, "langs": langs, "lang": lang, }, ), } )