mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-02-06 15:33:01 +00:00
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from django.contrib.auth.models import User
|
|
from django.db import transaction
|
|
from django.urls import reverse_lazy
|
|
from django.views.generic import CreateView
|
|
|
|
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")
|