I came up with a solution by overriding the handle_no_permission method from the UserPassesTestMixin:
On Thursday, December 15, 2016 at 3:53:38 PM UTC-2, Igor Belo wrote:
-- class FulfillAccountRequired(UserPassesTestMixin):
def test_func(self):
return self.request.user.account_completed
def handle_no_permission(self):
return redirect('website:account-detail')Not an elegant solution at all but solved my problem. Wondering if it worths to open a pull request.
Well, hope it helps someone in the future.
On Thursday, December 15, 2016 at 3:53:38 PM UTC-2, Igor Belo wrote:
Let me describe my scenario.I got some views that I want to check two conditions before render:1. user is logged in2. user fulfilled account details formIf user is not logged in -> redirect to login page.If user have not fulfilled its account details -> redirect to the form page.I'm using the LoginRequiredMixin to check 1 and the UserPassesTest to check 2 and the problem is that both mixins use the same login_url attribute (or method if I implement get_login_url) and as my views include both mixins, it always takes the most-left mixin login_url.Here's my code:class LoginRequired(LoginRequiredMixin): login_url = 'website:join'redirect_field_name = Noneclass FulfillAccountRequired(UserPassesTestMixin):
login_url = 'website:account-detail'
def test_func(self):
...
class MyView(FulfillAccountRequired, LoginRequired, ListView):
...Would be nice if there's a way to set a callable name for login_url (which after diving into mixins source I think is not possible).Is there another clean way to go through?Thanks,
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1a77c004-dab2-4c30-89e3-5bb753177cfd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment