def post(self, request, *args, **kwargs): self.request_form = DomainRequestForm(request.POST) if self.request_form.is_valid(): data = self.request_form.cleaned_data with CriticalSection(["domain_request_%s" % data['domain']]): if DomainRequest.by_email(data['domain'], data['email']) is not None: messages.error( request, _("A request is pending for this email. " "You will receive an email when the request is approved." )) else: domain_request = DomainRequest(**data) domain_request.send_request_email() domain_request.save() domain = Domain.get_by_name(domain_request.domain) return render( request, "users/confirmation_sent.html", { 'hr_name': domain.display_name() if domain else domain_request.domain, 'url': reverse("appstore"), }) return self.get(request, *args, **kwargs)
def page_context(self): domain_obj = Domain.get_by_name(self.request.domain) if self.request_form is None: initial = {'domain': domain_obj.name} if self.request.user.is_authenticated: initial.update({ 'email': self.request.user.get_username(), 'full_name': self.request.user.get_full_name(), }) self.request_form = DomainRequestForm(initial=initial) return { 'domain': domain_obj.name, 'hr_name': domain_obj.display_name(), 'request_form': self.request_form, }