Esempio n. 1
0
    def form_valid(self, form):
        existing_contacts = zcontacts.list_contacts(self.request.user)
        if not existing_contacts:
            new_contact = zcontacts.contact_create_from_profile(
                self.request.user, form.instance)
            if not zmaster.contact_create_update(new_contact):
                messages.error(self.request, self.error_message)
                return HttpResponseRedirect(self.request.path_info)

        existing_registrant = zcontacts.get_registrant(self.request.user)
        if not existing_registrant:
            new_registrant = zcontacts.registrant_create_from_profile(
                self.request.user, form.instance)
            if not zmaster.contact_create_update(new_registrant):
                messages.error(self.request, self.error_message)
                return HttpResponseRedirect(self.request.path_info)
        else:
            zcontacts.registrant_update_from_profile(existing_registrant,
                                                     form.instance)
            if not zmaster.contact_create_update(existing_registrant):
                messages.error(self.request, self.error_message)
                return HttpResponseRedirect(self.request.path_info)

        if existing_registrant and existing_contacts:
            messages.success(
                self.request,
                'Your profile information was successfully updated')
        else:
            messages.success(
                self.request,
                'Profile information successfully updated, you can register new domains now'
            )
        return super().form_valid(form)
Esempio n. 2
0
 def dispatch(self, request, *args, **kwargs):
     if not request.user.profile.is_complete():
         messages.info(request, 'Please provide your contact information to be able to register new domains.')
         return shortcuts.redirect('account_profile')
     if len(zcontacts.list_contacts(request.user)) == 0:
         messages.info(request, 'Please create your first contact person and provide your contact information '
                                'to be able to register new domains.')
         return shortcuts.redirect('account_contacts')
     return super().dispatch(request, *args, **kwargs)
Esempio n. 3
0
 def get_queryset(self):
     return zcontacts.list_contacts(self.request.user)