Skip to content
Snippets Groups Projects
Commit be218a1e authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[ui][registration][all] Pre-commit cleanup

parent 2ab6dfac
No related branches found
No related tags found
2 merge requests!367Cleanup ui registration,!342Django 3 migration
Pipeline #42695 passed
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
from django.contrib import admin from django.contrib import admin
from .models import RegistrationProfile
from .models import PreregistrationProfile from .models import PreregistrationProfile
from .models import RegistrationProfile
class RegistrationAdmin(admin.ModelAdmin): class RegistrationAdmin(admin.ModelAdmin):
......
This diff is collapsed.
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
from django.dispatch import Signal from django.dispatch import Signal
# A new user has registered. # A new user has registered.
user_registered = Signal(providing_args=["user"]) user_registered = Signal(providing_args=["user"])
......
...@@ -29,12 +29,10 @@ ...@@ -29,12 +29,10 @@
Views which allow users to create and activate accounts. Views which allow users to create and activate accounts.
""" """
from django.conf import settings from django.conf import settings
from django.urls import reverse
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.shortcuts import render from django.shortcuts import render
from django.urls import reverse
from django.views.decorators.csrf import csrf_protect from django.views.decorators.csrf import csrf_protect
from .forms import RegistrationFormTermsOfService from .forms import RegistrationFormTermsOfService
...@@ -43,9 +41,12 @@ from .forms import RegistrationSupervisorForm ...@@ -43,9 +41,12 @@ from .forms import RegistrationSupervisorForm
from .models import RegistrationProfile from .models import RegistrationProfile
def activate(request, activation_key, def activate(
template_name='registration/activate.html', request,
extra_context=None): activation_key,
template_name="registration/activate.html",
extra_context=None,
):
""" """
Activate a ``User``'s account from an activation key, if their key Activate a ``User``'s account from an activation key, if their key
is valid and hasn't expired. is valid and hasn't expired.
...@@ -89,11 +90,10 @@ def activate(request, activation_key, ...@@ -89,11 +90,10 @@ def activate(request, activation_key,
registration/activate.html or ``template_name`` keyword argument. registration/activate.html or ``template_name`` keyword argument.
""" """
activationKey = activation_key.lower() # Normalize before trying anything with it.
account = RegistrationProfile.objects.activate_user(activation_key) account = RegistrationProfile.objects.activate_user(activation_key)
context = { 'account': account, context = {"account": account, "expiration_days": settings.ACCOUNT_ACTIVATION_DAYS}
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS }
if extra_context is not None: if extra_context is not None:
for key, value in extra_context.items(): for key, value in extra_context.items():
...@@ -103,10 +103,13 @@ def activate(request, activation_key, ...@@ -103,10 +103,13 @@ def activate(request, activation_key,
@csrf_protect @csrf_protect
def register(request, success_url=None, def register(
form_class=RegistrationFormTermsOfService, request,
template_name='registration/registration_form.html', success_url=None,
extra_context=None): form_class=RegistrationFormTermsOfService,
template_name="registration/registration_form.html",
extra_context=None,
):
""" """
Allow a new user to register an account. Allow a new user to register an account.
...@@ -164,17 +167,19 @@ def register(request, success_url=None, ...@@ -164,17 +167,19 @@ def register(request, success_url=None,
supervisor_form_active = False supervisor_form_active = False
if request.GET.get('registration') == "supervisor": if request.GET.get("registration") == "supervisor":
supervisor_form_active = True supervisor_form_active = True
if request.method == 'POST': if request.method == "POST":
# Check the form # Check the form
if 'supervisor' not in request.POST: if "supervisor" not in request.POST:
supervisor_form_active = True supervisor_form_active = True
form_supervisor = RegistrationSupervisorForm(data=request.POST, files=request.FILES) form_supervisor = RegistrationSupervisorForm(
data=request.POST, files=request.FILES
)
form = form_class() form = form_class()
if form_supervisor.is_valid(): if form_supervisor.is_valid():
new_user = form_supervisor.save() form_supervisor.save()
# success_url needs to be dynamically generated here; setting a # success_url needs to be dynamically generated here; setting a
# a default value using reverse() will cause circular-import # a default value using reverse() will cause circular-import
# problems with the default URLConf for this application, which # problems with the default URLConf for this application, which
...@@ -185,7 +190,7 @@ def register(request, success_url=None, ...@@ -185,7 +190,7 @@ def register(request, success_url=None,
form = form_class(data=request.POST, files=request.FILES) form = form_class(data=request.POST, files=request.FILES)
form_supervisor = RegistrationSupervisorForm() form_supervisor = RegistrationSupervisorForm()
if form.is_valid(): if form.is_valid():
new_user = form.save() form.save()
# success_url needs to be dynamically generated here; setting a # success_url needs to be dynamically generated here; setting a
# a default value using reverse() will cause circular-import # a default value using reverse() will cause circular-import
# problems with the default URLConf for this application, which # problems with the default URLConf for this application, which
...@@ -195,12 +200,13 @@ def register(request, success_url=None, ...@@ -195,12 +200,13 @@ def register(request, success_url=None,
form = form_class() form = form_class()
form_supervisor = RegistrationFormTermsOfServiceSupervisor() form_supervisor = RegistrationFormTermsOfServiceSupervisor()
context = {
context = { 'form': form, "form": form,
'form_supervisor': form_supervisor, "form_supervisor": form_supervisor,
'supervisor_form_active': supervisor_form_active, "supervisor_form_active": supervisor_form_active,
'documentation_link': settings.DOCUMENTATION_LINK, "documentation_link": settings.DOCUMENTATION_LINK,
'url_prefix':settings.URL_PREFIX } "url_prefix": settings.URL_PREFIX,
}
if extra_context is not None: if extra_context is not None:
for key, value in extra_context.items(): for key, value in extra_context.items():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment