Beispiel #1
0
 def get_success_url(self, *args, **kwargs):
     try:
         if hasattr(self.object, self.object._meta.get_field('profile').get_cache_name()):
             profile = self.object.profile
         else:
             profile = Profile.get_basic_data(user=self.object)
         return profile.get_edit_url()
     except Profile.DoesNotExist:
         return reverse_lazy('profile_create')
Beispiel #2
0
 def get_authenticated_redirect_url(self):
     redirect_to = sanitize_next(self.request)
     if redirect_to:
         return redirect_to
     try:
         # When user is already authenticated, redirect to profile's page.
         profile = Profile.get_basic_data(user=self.request.user)
         return profile.get_absolute_url()
     except Profile.DoesNotExist:
         # If profile does not exist yet, redirect to home.
         return reverse_lazy('home')
Beispiel #3
0
 def get_authenticated_redirect_url(self):
     redirect_to = sanitize_next(self.request)
     if redirect_to:
         return redirect_to
     try:
         # When user is already authenticated, redirect to profile edit page.
         profile = Profile.get_basic_data(user=self.request.user)
         return profile.get_edit_url()
     except Profile.DoesNotExist:
         # If profile does not exist yet, redirect to profile creation page.
         return self.success_url
Beispiel #4
0
 def get(self, request, *args, **kwargs):
     try:
         profile = Profile.get_basic_data(user=request.user)
         return HttpResponseRedirect(
             reverse_lazy('profile_settings',
                          kwargs={
                              'pk': profile.pk,
                              'slug': profile.autoslug
                          }))
     except Profile.DoesNotExist:
         # Cache the result for the reverse related descriptor, to spare further DB queries.
         setattr(request.user,
                 request.user._meta.fields_map['profile'].get_cache_name(),
                 None)
         return super().get(request, *args, **kwargs)
Beispiel #5
0
 def get(self, request, *args, **kwargs):
     self.object = self.get_object()
     if not request.user.is_active:
         return HttpResponseRedirect(self.get_success_url())
     else:
         try:
             profile = Profile.get_basic_data(user=request.user)
         except Profile.DoesNotExist:
             return super().get(request, *args, **kwargs)
         else:
             return HttpResponseRedirect(
                 reverse_lazy('profile_delete',
                              kwargs={
                                  'pk': profile.pk,
                                  'slug': profile.autoslug
                              }))
Beispiel #6
0
    def get(self, request, *args, **kwargs):
        try:
            profile = Profile.get_basic_data(user=request.user)
            settings_url = reverse_lazy('profile_settings',
                                        kwargs={
                                            'pk': profile.pk,
                                            'slug': profile.autoslug
                                        })
        except Profile.DoesNotExist:
            settings_url = reverse_lazy('account_settings')

        return HttpResponseRedirect(
            format_lazy(
                '{settings_url}#{section_email}',
                settings_url=settings_url,
                section_email=pgettext_lazy("URL", "email-addr"),
            ))