mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-07-04 23:04:03 +02:00
Enable registration form
This commit is contained in:
@ -1,3 +1,41 @@
|
||||
from django.shortcuts import render
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import transaction
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import CreateView
|
||||
|
||||
# Create your views here.
|
||||
from .forms import SignupForm, StudentRegistrationForm, CoachRegistrationForm
|
||||
|
||||
|
||||
class SignupView(CreateView):
|
||||
model = User
|
||||
form_class = SignupForm
|
||||
template_name = "registration/signup.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data()
|
||||
|
||||
context["student_registration_form"] = StudentRegistrationForm(self.request.POST or None)
|
||||
context["coach_registration_form"] = CoachRegistrationForm(self.request.POST or None)
|
||||
|
||||
return context
|
||||
|
||||
@transaction.atomic
|
||||
def form_valid(self, form):
|
||||
role = form.cleaned_data["role"]
|
||||
if role == "participant":
|
||||
registration_form = StudentRegistrationForm(self.request.POST)
|
||||
else:
|
||||
registration_form = CoachRegistrationForm(self.request.POST)
|
||||
|
||||
if not registration_form.is_valid():
|
||||
return self.form_invalid(form)
|
||||
|
||||
ret = super().form_valid(form)
|
||||
registration = registration_form.instance
|
||||
registration.user = form.instance
|
||||
registration.save()
|
||||
|
||||
return ret
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy("index")
|
||||
|
Reference in New Issue
Block a user