Django - What is the best way to have multi level status before login
<p>I have one scenario, there is a user registration and it should have multiple status(may be is_active - but this is boolean by default)</p>

<ol>
<li>List item Code - 0 -> Pending for Email Confirmation</li>
<li>List item Code - 1 -> Account Activated/Active(Only after email confirmed admin will approve it)</li>
<li>List item Code - 2 -> Email Confirmed</li>
</ol>

<p>I am using django allauth, I was browsing to achieve it, but unable to find some close match of it. For your info I also have <code>Profile OnetoOne model for User model</code></p>

<p><strong>Updated</strong> </p>

<pre><code>class CustomConfirmEmailView(ConfirmEmailView):
    def get(self):
        raise Exception('GET')
    def post(self,*args,**kwargs):
        raise Exception('POST')
</code></pre>

<p><strong>Settings file</strong></p>

<pre><code>ACCOUNT_CONFIRM_EMAIL_ON_GET = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
</code></pre>

<p>You can use <code>decorators</code> for these kinds of scenarios. Decorators are just methods that accepts another method as argument. What you have to do is to <code>pass the get/post or any other methods together with its arguments to decorator</code> then check for email confirmation/account active. </p>

<pre><code>from functools import wraps
from .permissions import is_admin_or_manager
from .utils import get_user_on_user_identifier


def is_manager(method):
    @wraps(method)
    def wrapper(self, *args, **kwargs):
        user_identifier = kwargs.get('user_identifier') if kwargs.get('user_identifier') else args[0]
    user = get_user_on_user_identifier(user_identifier)
    if user:
        if is_admin_or_manager(user):
            return method(self, *args, **kwargs)
        else:
            return {'status': 403, 'description': 'Only Manager/Admin roles can create items.'}
    else:
        return {'status': 404, 'description': 'No user with given username/email exists.'}
return wrapper

class PermissionException(Exception):
    pass
</code></pre>

<p>And in your views,</p>

<pre><code>class Home(View):
    @is_manager
    def get(self, request):
        ...
</code></pre>

<p>Above code exemplifies on usage of decorators. In your case, pass method with args. get user from request arg passed to decorator, then check if email is confirmed/ account is activated. If not return message using <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/messages/" rel="nofollow">django messages framework</a> json/string can be also be used to pass maessages.</p>

<p>In case you want to use the same with class based views consider <a href="https://docs.djangoproject.com/en/1.10/topics/class-based-views/mixins/" rel="nofollow">mixins</a>. You can override <code>dispatch(self, request, *args, **kwargs)</code> method. I think using decorators/mixins will be better since you do your checks on every views that you write with one line of code.</p>

python django