/usr/lib/python2.7/dist-packages/registration/views.py is in python-django-registration 2.0.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | """
Base view classes for all registration workflows.
"""
from django.conf import settings
from django.shortcuts import redirect
from django.views.generic.base import TemplateView
from django.views.generic.edit import FormView
from registration.forms import RegistrationForm
class RegistrationView(FormView):
"""
Base class for user registration views.
"""
disallowed_url = 'registration_disallowed'
form_class = RegistrationForm
success_url = None
template_name = 'registration/registration_form.html'
def dispatch(self, *args, **kwargs):
"""
Check that user signup is allowed before even bothering to
dispatch or do other processing.
"""
if not self.registration_allowed():
return redirect(self.disallowed_url)
return super(RegistrationView, self).dispatch(*args, **kwargs)
def form_valid(self, form):
new_user = self.register(form)
success_url = self.get_success_url(new_user)
# success_url may be a simple string, or a tuple providing the
# full argument set for redirect(). Attempting to unpack it
# tells us which one it is.
try:
to, args, kwargs = success_url
return redirect(to, *args, **kwargs)
except ValueError:
return redirect(success_url)
def registration_allowed(self):
"""
Override this to enable/disable user registration, either
globally or on a per-request basis.
"""
return getattr(settings, 'REGISTRATION_OPEN', True)
def register(self, form):
"""
Implement user-registration logic here. Access to both the
request and the registration form is available here.
"""
raise NotImplementedError
class ActivationView(TemplateView):
"""
Base class for user activation views.
"""
template_name = 'registration/activate.html'
def get(self, *args, **kwargs):
"""
The base activation logic; subclasses should leave this method
alone and implement activate(), which is called from this
method.
"""
activated_user = self.activate(*args, **kwargs)
if activated_user:
success_url = self.get_success_url(activated_user)
try:
to, args, kwargs = success_url
return redirect(to, *args, **kwargs)
except ValueError:
return redirect(success_url)
return super(ActivationView, self).get(*args, **kwargs)
def activate(self, *args, **kwargs):
"""
Implement account-activation logic here.
"""
raise NotImplementedError
def get_success_url(self, user):
"""
Implement this to return the URL (either a 3-tuple for
redirect(), or a simple string name of a URL pattern) to
redirect to after successful activation.
This differs from most get_success_url() methods of Django
views in that it receives an extra argument: the user whose
account was activated.
"""
raise NotImplementedError
|