def copy_snapshot(request, domain): user = request.couch_user if not user.is_eula_signed(): messages.error(request, 'You must agree to our eula to download an app') return project_info(request, domain) dom = Domain.get(domain) if request.method == "POST" and dom.is_snapshot: from corehq.apps.registration.forms import DomainRegistrationForm args = { 'domain_name': request.POST['new_project_name'], 'eula_confirmed': True } form = DomainRegistrationForm(args) if request.POST.get('new_project_name', ""): if not dom.published: messages.error( request, "This project is not published and can't be downloaded") return project_info(request, domain) if form.is_valid(): new_domain = dom.save_copy(form.cleaned_data['domain_name'], user=user) else: messages.error(request, form.errors) return project_info(request, domain) if new_domain is None: messages.error(request, _("A project by that name already exists")) return project_info(request, domain) def inc_downloads(d): d.downloads += 1 apply_update(dom, inc_downloads) # sign project up for trial create_30_day_trial(new_domain) messages.success(request, render_to_string( "appstore/partials/view_wiki.html", {"pre": _("Project copied successfully!")}), extra_tags="html") return HttpResponseRedirect( reverse('view_app', args=[ new_domain.name, new_domain.full_applications()[0].get_id ])) else: messages.error(request, _("You must specify a name for the new project")) return project_info(request, domain) else: return HttpResponseRedirect(reverse('project_info', args=[domain]))
def copy_snapshot(request, domain): user = request.couch_user if not user.is_eula_signed(): messages.error(request, 'You must agree to our eula to download an app') return project_info(request, domain) dom = Domain.get(domain) if request.method == "POST" and dom.is_snapshot: assert dom.full_applications(include_builds=False), 'Bad attempt to copy project without any apps!' from corehq.apps.registration.forms import DomainRegistrationForm args = { 'domain_name': request.POST['new_project_name'], 'hr_name': request.POST['new_project_name'], 'eula_confirmed': True, } form = DomainRegistrationForm(args) if request.POST.get('new_project_name', ""): if not dom.published: messages.error(request, _("This project is not published and can't be downloaded")) return project_info(request, domain) if not form.is_valid(): messages.error(request, form.errors) return project_info(request, domain) new_domain_name = name_to_url(form.cleaned_data['hr_name'], "project") with CriticalSection(['copy_domain_snapshot_{}_to_{}'.format(dom.name, new_domain_name)]): try: new_domain = dom.save_copy(new_domain_name, new_hr_name=form.cleaned_data['hr_name'], user=user) except NameUnavailableException: messages.error(request, _("A project by that name already exists")) return project_info(request, domain) # sign new project up for trial create_30_day_trial(new_domain) def inc_downloads(d): d.downloads += 1 apply_update(dom, inc_downloads) messages.success(request, render_to_string("appstore/partials/view_wiki.html", {"pre": _("Project copied successfully!")}), extra_tags="html") return HttpResponseRedirect(reverse('view_app', args=[new_domain.name, new_domain.full_applications()[0].get_id])) else: messages.error(request, _("You must specify a name for the new project")) return project_info(request, domain) else: return HttpResponseRedirect(reverse('project_info', args=[domain]))
def copy_snapshot(request, domain): user = request.couch_user if not user.is_eula_signed(): messages.error(request, 'You must agree to our eula to download an app') return project_info(request, domain) dom = Domain.get(domain) if request.method == "POST" and dom.is_snapshot: from corehq.apps.registration.forms import DomainRegistrationForm args = {'domain_name': request.POST['new_project_name'], 'eula_confirmed': True} form = DomainRegistrationForm(args) if request.POST.get('new_project_name', ""): if not dom.published: messages.error(request, "This project is not published and can't be downloaded") return project_info(request, domain) if form.is_valid(): new_domain = dom.save_copy(form.cleaned_data['domain_name'], user=user) else: messages.error(request, form.errors) return project_info(request, domain) if new_domain is None: messages.error(request, _("A project by that name already exists")) return project_info(request, domain) def inc_downloads(d): d.downloads += 1 apply_update(dom, inc_downloads) # sign project up for trial create_30_day_trial(new_domain) messages.success(request, render_to_string("appstore/partials/view_wiki.html", {"pre": _("Project copied successfully!")}), extra_tags="html") return HttpResponseRedirect(reverse('view_app', args=[new_domain.name, new_domain.full_applications()[0].get_id])) else: messages.error(request, _("You must specify a name for the new project")) return project_info(request, domain) else: return HttpResponseRedirect(reverse('project_info', args=[domain]))
def copy_snapshot(request, domain): user = request.couch_user if not user.is_eula_signed(): messages.error(request, 'You must agree to our eula to download an app') return project_info(request, domain) dom = Domain.get(domain) if request.method == "POST" and dom.is_snapshot: assert dom.full_applications( include_builds=False ), 'Bad attempt to copy project without any apps!' from corehq.apps.registration.forms import DomainRegistrationForm args = { 'domain_name': request.POST['new_project_name'], 'hr_name': request.POST['new_project_name'], 'eula_confirmed': True, } form = DomainRegistrationForm(args) if request.POST.get('new_project_name', ""): if not dom.published: messages.error( request, _("This project is not published and can't be downloaded")) return project_info(request, domain) if not form.is_valid(): messages.error(request, form.errors) return project_info(request, domain) new_domain_name = form.cleaned_data['hr_name'] with CriticalSection([ 'copy_domain_snapshot_{}_to_{}'.format( dom.name, new_domain_name) ]): try: new_domain = dom.save_copy( new_domain_name, new_hr_name=form.cleaned_data['hr_name'], user=user) except NameUnavailableException: messages.error(request, _("A project by that name already exists")) return project_info(request, domain) # sign new project up for trial create_30_day_trial(new_domain) def inc_downloads(d): d.downloads += 1 apply_update(dom, inc_downloads) messages.success(request, render_to_string( "appstore/partials/view_wiki.html", {"pre": _("Project copied successfully!")}), extra_tags="html") return HttpResponseRedirect( reverse('view_app', args=[ new_domain.name, new_domain.full_applications()[0].get_id ])) else: messages.error(request, _("You must specify a name for the new project")) return project_info(request, domain) else: return HttpResponseRedirect(reverse('project_info', args=[domain]))