def register_domain(request, domain_type=None): domain_type = domain_type or 'commcare' assert domain_type in DOMAIN_TYPES _render = partial(render_registration_view, domain_type=domain_type) is_new = False referer_url = request.GET.get('referer', '') active_domains_for_user = Domain.active_for_user(request.user) if len(active_domains_for_user) <= 0 and not request.user.is_superuser: is_new = True domains_for_user = Domain.active_for_user(request.user, is_active=False) if len(domains_for_user) > 0: vals = dict(requested_domain=domains_for_user[0]) return _render(request, 'registration/confirmation_waiting.html', { 'requested_domain': domains_for_user[0] }) if request.method == 'POST': nextpage = request.POST.get('next') org = request.POST.get('org') form = DomainRegistrationForm(request.POST) if form.is_valid(): reqs_today = RegistrationRequest.get_requests_today() max_req = settings.DOMAIN_MAX_REGISTRATION_REQUESTS_PER_DAY if reqs_today >= max_req: vals = {'error_msg':'Number of domains requested today exceeds limit ('+str(max_req)+') - contact Dimagi', 'show_homepage_link': 1 } return _render(request, 'error.html', vals) request_new_domain( request, form, org, new_user=is_new, domain_type=domain_type) requested_domain = form.cleaned_data['domain_name'] if is_new: vals = dict(alert_message="An email has been sent to %s." % request.user.username, requested_domain=requested_domain) return _render(request, 'registration/confirmation_sent.html', vals) else: messages.success(request, '<strong>The project {project_name} was successfully created!</strong> An email has been sent to {username} for your records.'.format( username=request.user.username, project_name=requested_domain ), extra_tags="html") if nextpage: return HttpResponseRedirect(nextpage) if referer_url: return redirect(referer_url) return HttpResponseRedirect(reverse("domain_homepage", args=[requested_domain])) else: if nextpage: # messages.error(request, "The new project could not be created! Please make sure to fill out all fields of the form.") return orgs_landing(request, org, form=form) else: form = DomainRegistrationForm(initial={'domain_type': domain_type}) return _render(request, 'registration/domain_request.html', { 'form': form, 'is_new': is_new, })
def register_domain(request, domain_type=None): domain_type = domain_type or 'commcare' assert domain_type in DOMAIN_TYPES context = get_domain_context(domain_type) is_new = False referer_url = request.GET.get('referer', '') active_domains_for_user = Domain.active_for_user(request.user) if len(active_domains_for_user) <= 0 and not request.user.is_superuser: is_new = True domains_for_user = Domain.active_for_user(request.user, is_active=False) if len(domains_for_user) > 0: context['requested_domain'] = domains_for_user[0] return render(request, 'registration/confirmation_waiting.html', context) if request.method == 'POST': nextpage = request.POST.get('next') org = request.POST.get('org') form = DomainRegistrationForm(request.POST) if form.is_valid(): reqs_today = RegistrationRequest.get_requests_today() max_req = settings.DOMAIN_MAX_REGISTRATION_REQUESTS_PER_DAY if reqs_today >= max_req: context.update({ 'error_msg': _('Number of domains requested today exceeds limit (%d) - contact Dimagi' ) % max_req, 'show_homepage_link': 1 }) return render(request, 'error.html', context) request_new_domain(request, form, org, new_user=is_new, domain_type=domain_type) requested_domain = form.cleaned_data['domain_name'] if is_new: context.update({ 'alert_message': _("An email has been sent to %s.") % request.user.username, 'requested_domain': requested_domain }) return render(request, 'registration/confirmation_sent.html', context) else: messages.success( request, _('<strong>The project {project} was successfully created!</strong> ' 'An email has been sent to {user} for your records.' ).format(project=requested_domain, user=request.user.username), extra_tags="html") if nextpage: return HttpResponseRedirect(nextpage) if referer_url: return redirect(referer_url) return HttpResponseRedirect( reverse("domain_homepage", args=[requested_domain])) else: if nextpage: return orgs_landing(request, org, form=form) else: form = DomainRegistrationForm(initial={'domain_type': domain_type}) context.update({ 'form': form, 'is_new': is_new, }) return render(request, 'registration/domain_request.html', context)
def register_domain(request, domain_type=None): domain_type = domain_type or 'commcare' if domain_type not in DOMAIN_TYPES or request.couch_user.is_commcare_user(): raise Http404() context = get_domain_context(domain_type) is_new = False referer_url = request.GET.get('referer', '') active_domains_for_user = Domain.active_for_user(request.user) if len(active_domains_for_user) <= 0 and not request.user.is_superuser: is_new = True domains_for_user = Domain.active_for_user(request.user, is_active=False) if len(domains_for_user) > 0: context['requested_domain'] = domains_for_user[0] return render(request, 'registration/confirmation_waiting.html', context) if request.method == 'POST': nextpage = request.POST.get('next') org = request.POST.get('org') form = DomainRegistrationForm(request.POST) if form.is_valid(): reqs_today = RegistrationRequest.get_requests_today() max_req = settings.DOMAIN_MAX_REGISTRATION_REQUESTS_PER_DAY if reqs_today >= max_req: context.update({ 'error_msg': _( 'Number of domains requested today exceeds limit (%d) - contact Dimagi' ) % max_req, 'show_homepage_link': 1 }) return render(request, 'error.html', context) request_new_domain( request, form, org, new_user=is_new, domain_type=domain_type) requested_domain = form.cleaned_data['domain_name'] if is_new: context.update({ 'alert_message': _("An email has been sent to %s.") % request.user.username, 'requested_domain': requested_domain }) return render(request, 'registration/confirmation_sent.html', context) else: messages.success(request, _( '<strong>The project {project} was successfully created!</strong> ' 'An email has been sent to {user} for your records.').format( project=requested_domain, user=request.user.username), extra_tags="html") if nextpage: return HttpResponseRedirect(nextpage) if referer_url: return redirect(referer_url) return HttpResponseRedirect(reverse("domain_homepage", args=[requested_domain])) else: if nextpage: return orgs_landing(request, org, form=form) else: form = DomainRegistrationForm(initial={'domain_type': domain_type}) context.update({ 'form': form, 'is_new': is_new, }) return render(request, 'registration/domain_request.html', context)
def register_domain(request, domain_type=None): domain_type = domain_type or 'commcare' if domain_type not in DOMAIN_TYPES or (not request.couch_user) or request.couch_user.is_commcare_user(): raise Http404() context = get_domain_context(domain_type) is_new = False referer_url = request.GET.get('referer', '') active_domains_for_user = Domain.active_for_user(request.user) if len(active_domains_for_user) <= 0 and not request.user.is_superuser: is_new = True domains_for_user = Domain.active_for_user(request.user, is_active=False) if len(domains_for_user) > 0: context['requested_domain'] = domains_for_user[0] return render(request, 'registration/confirmation_waiting.html', context) if request.method == 'POST': nextpage = request.POST.get('next') org = request.POST.get('org') form = DomainRegistrationForm(request.POST) if form.is_valid(): reqs_today = RegistrationRequest.get_requests_today() max_req = settings.DOMAIN_MAX_REGISTRATION_REQUESTS_PER_DAY if reqs_today >= max_req: context.update({ 'error_msg': _( 'Number of domains requested today exceeds limit (%d) - contact Dimagi' ) % max_req, 'show_homepage_link': 1 }) return render(request, 'error.html', context) try: domain_name = request_new_domain( request, form, org, new_user=is_new, domain_type=domain_type) except NameUnavailableException: context.update({ 'error_msg': _('Project name already taken - please try another'), 'show_homepage_link': 1 }) return render(request, 'error.html', context) if is_new: context.update({ 'alert_message': _("An email has been sent to %s.") % request.user.username, 'requested_domain': domain_name, 'track_domain_registration': True, }) return render(request, 'registration/confirmation_sent.html', context) else: if nextpage: return HttpResponseRedirect(nextpage) if referer_url: return redirect(referer_url) return HttpResponseRedirect(reverse("domain_homepage", args=[domain_name])) else: if nextpage: return orgs_landing(request, org, form=form) else: form = DomainRegistrationForm(initial={'domain_type': domain_type}) context.update({ 'form': form, 'is_new': is_new, }) return render(request, 'registration/domain_request.html', context)
def register_domain(request, domain_type=None): domain_type = domain_type or "commcare" assert domain_type in DOMAIN_TYPES context = get_domain_context(domain_type) is_new = False referer_url = request.GET.get("referer", "") active_domains_for_user = Domain.active_for_user(request.user) if len(active_domains_for_user) <= 0 and not request.user.is_superuser: is_new = True domains_for_user = Domain.active_for_user(request.user, is_active=False) if len(domains_for_user) > 0: context["requested_domain"] = domains_for_user[0] return render(request, "registration/confirmation_waiting.html", context) if request.method == "POST": nextpage = request.POST.get("next") org = request.POST.get("org") form = DomainRegistrationForm(request.POST) if form.is_valid(): reqs_today = RegistrationRequest.get_requests_today() max_req = settings.DOMAIN_MAX_REGISTRATION_REQUESTS_PER_DAY if reqs_today >= max_req: context.update( { "error_msg": _("Number of domains requested today exceeds limit (%d) - contact Dimagi") % max_req, "show_homepage_link": 1, } ) return render(request, "error.html", context) request_new_domain(request, form, org, new_user=is_new, domain_type=domain_type) requested_domain = form.cleaned_data["domain_name"] if is_new: context.update( { "alert_message": _("An email has been sent to %s.") % request.user.username, "requested_domain": requested_domain, } ) return render(request, "registration/confirmation_sent.html", context) else: messages.success( request, _( "<strong>The project {project} was successfully created!</strong> " "An email has been sent to {user} for your records." ).format(project=requested_domain, user=request.user.username), extra_tags="html", ) if nextpage: return HttpResponseRedirect(nextpage) if referer_url: return redirect(referer_url) return HttpResponseRedirect(reverse("domain_homepage", args=[requested_domain])) else: if nextpage: return orgs_landing(request, org, form=form) else: form = DomainRegistrationForm(initial={"domain_type": domain_type}) context.update({"form": form, "is_new": is_new}) return render(request, "registration/domain_request.html", context)
def register_domain(request, domain_type=None): domain_type = domain_type or 'commcare' if domain_type not in DOMAIN_TYPES or request.couch_user.is_commcare_user( ): raise Http404() context = get_domain_context(domain_type) is_new = False referer_url = request.GET.get('referer', '') active_domains_for_user = Domain.active_for_user(request.user) if len(active_domains_for_user) <= 0 and not request.user.is_superuser: is_new = True domains_for_user = Domain.active_for_user(request.user, is_active=False) if len(domains_for_user) > 0: context['requested_domain'] = domains_for_user[0] return render(request, 'registration/confirmation_waiting.html', context) if request.method == 'POST': nextpage = request.POST.get('next') org = request.POST.get('org') form = DomainRegistrationForm(request.POST) if form.is_valid(): reqs_today = RegistrationRequest.get_requests_today() max_req = settings.DOMAIN_MAX_REGISTRATION_REQUESTS_PER_DAY if reqs_today >= max_req: context.update({ 'error_msg': _('Number of domains requested today exceeds limit (%d) - contact Dimagi' ) % max_req, 'show_homepage_link': 1 }) return render(request, 'error.html', context) try: domain_name = request_new_domain(request, form, org, new_user=is_new, domain_type=domain_type) except NameUnavailableException: context.update({ 'error_msg': _('Project name already taken - please try another'), 'show_homepage_link': 1 }) return render(request, 'error.html', context) if is_new: context.update({ 'alert_message': _("An email has been sent to %s.") % request.user.username, 'requested_domain': domain_name, 'track_domain_registration': True, }) return render(request, 'registration/confirmation_sent.html', context) else: if nextpage: return HttpResponseRedirect(nextpage) if referer_url: return redirect(referer_url) return HttpResponseRedirect( reverse("domain_homepage", args=[domain_name])) else: if nextpage: return orgs_landing(request, org, form=form) else: form = DomainRegistrationForm(initial={'domain_type': domain_type}) context.update({ 'form': form, 'is_new': is_new, }) return render(request, 'registration/domain_request.html', context)