def handle(self, **options): domain = options['domain'] usernames = options['usernames'].split(',') app_id = options['app_id'] users = [CouchUser.get_by_username(username) for username in usernames] for username in usernames: if not CouchUser.get_by_username(username): print("User '{}' not found".format(username)) return if app_id: try: get_current_app_doc(domain, app_id) except ResourceNotFound: print("App '{}' not found".format(app_id)) return headers, rows = _get_headers_and_rows(domain, users, app_id) totals_row = _calculate_totals_row(headers, rows) filename = "restore_timings_{}.csv".format(get_timestamp_for_filename()) with open(filename, 'w') as f: writer = csv.DictWriter(f, headers) writer.writeheader() writer.writerows(rows) writer.writerow(totals_row)
def pull_master_app(request, domain, app_id): app = get_current_app_doc(domain, app_id) master_app = get_app(None, app['master']) latest_master_build = get_app(None, app['master'], latest=True) if app['domain'] in master_app.linked_whitelist: try: overwrite_app(app, latest_master_build) except AppEditingError: messages.error( request, _('This linked application uses mobile UCRs ' 'which are currently not supported. For this application ' 'to function correctly, you will need to remove those modules ' 'or revert to a previous version that did not include them.') ) else: messages.success( request, _('Your linked application was successfully updated to the latest version.' )) else: messages.error( request, _('This project is not authorized to update from the master application. ' 'Please contact the maintainer of the master app if you believe this is a mistake. ' )) return HttpResponseRedirect( reverse_util('view_app', params={}, args=[domain, app_id]))
def handle(self, from_domain, from_app_id, to_domain, to_app_id, *args, **options): self.from_domain = from_domain self.to_domain = to_domain app = get_current_app_doc(self.to_domain, to_app_id) latest_master_build = get_app(None, from_app_id, latest=True) overwrite_app(app, latest_master_build, self.report_map, maintain_ids=True)
def pull_master_app(request, domain, app_id): app = get_current_app_doc(domain, app_id) master_app = get_app(None, app['master']) latest_master_build = get_app(None, app['master'], latest=True) params = {} if app['domain'] in master_app.linked_whitelist: excluded_fields = set(Application._meta_fields).union([ 'date_created', 'build_profiles', 'copy_history', 'copy_of', 'name', 'comment', 'doc_type' ]) master_json = latest_master_build.to_json() for key, value in master_json.iteritems(): if key not in excluded_fields: app[key] = value app['version'] = master_json['version'] wrapped_app = wrap_app(app) mobile_ucrs = False for module in wrapped_app.modules: if isinstance(module, ReportModule): mobile_ucrs = True break if mobile_ucrs: messages.error( request, _('This linked application uses mobile UCRs ' 'which are currently not supported. For this application ' 'to function correctly, you will need to remove those modules ' 'or revert to a previous version that did not include them.') ) else: messages.success( request, _('Your linked application was successfully updated to the latest version.' )) wrapped_app.copy_attachments(latest_master_build) wrapped_app.save(increment_version=False) else: messages.error( request, _('This project is not authorized to update from the master application. ' 'Please contact the maintainer of the master app if you believe this is a mistake. ' )) return HttpResponseRedirect( reverse_util('view_app', params=params, args=[domain, app_id]))
def update_linked_whitelist(request, domain, app_id): app = wrap_app(get_current_app_doc(domain, app_id)) new_whitelist = json.loads(request.POST.get('whitelist')) app.linked_whitelist = new_whitelist app.save() return HttpResponse()
def fetch_app(self, domain, app_id): return get_current_app_doc(domain, app_id)