mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 01:32:05 +01:00 
			
		
		
		
	Fix registration dates test
This commit is contained in:
		@@ -7,8 +7,6 @@ from django.contrib.auth.forms import UserCreationForm
 | 
			
		||||
from django.contrib.auth.models import User
 | 
			
		||||
from django.core.exceptions import ValidationError
 | 
			
		||||
from django.forms import FileInput
 | 
			
		||||
from django.utils import timezone
 | 
			
		||||
from django.utils.text import format_lazy
 | 
			
		||||
from django.utils.translation import gettext_lazy as _
 | 
			
		||||
 | 
			
		||||
from .models import CoachRegistration, ParticipantRegistration, Payment, \
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ from django.http import FileResponse, Http404
 | 
			
		||||
from django.shortcuts import redirect, resolve_url
 | 
			
		||||
from django.template.loader import render_to_string
 | 
			
		||||
from django.urls import reverse_lazy
 | 
			
		||||
from django.utils import translation
 | 
			
		||||
from django.utils import timezone, translation
 | 
			
		||||
from django.utils.crypto import get_random_string
 | 
			
		||||
from django.utils.http import urlsafe_base64_decode
 | 
			
		||||
from django.utils.text import format_lazy
 | 
			
		||||
@@ -60,22 +60,24 @@ class SignupView(CreateView):
 | 
			
		||||
 | 
			
		||||
        return context
 | 
			
		||||
 | 
			
		||||
    @transaction.atomic
 | 
			
		||||
    def form_valid(self, form):
 | 
			
		||||
        if not self.request.user.registration.is_admin:
 | 
			
		||||
    def get_form(self, form_class=None):
 | 
			
		||||
        form = super().get_form(form_class)
 | 
			
		||||
        if self.request.method in ("POST", "PUT") \
 | 
			
		||||
                and (not self.request.user.is_authenticated or not self.request.user.registration.is_admin):
 | 
			
		||||
            # Check that registrations are opened
 | 
			
		||||
            now = timezone.now()
 | 
			
		||||
            if now < settings.REGISTRATION_DATES['open']:
 | 
			
		||||
                form.add_error(None, format_lazy(_("Registrations are not opened yet. "
 | 
			
		||||
                                                "They will open on the {opening_date:%Y-%m-%d %H:%M}."),
 | 
			
		||||
                                                opening_date=settings.REGISTRATION_DATES['open']))
 | 
			
		||||
                                                   "They will open on the {opening_date:%Y-%m-%d %H:%M}."),
 | 
			
		||||
                                                 opening_date=settings.REGISTRATION_DATES['open']))
 | 
			
		||||
            elif now > settings.REGISTRATION_DATES['close']:
 | 
			
		||||
                form.add_error(None, format_lazy(_("Registrations for this year are closed since "
 | 
			
		||||
                                                "{closing_date:%Y-%m-%d %H:%M}."),
 | 
			
		||||
                                                closing_date=settings.REGISTRATION_DATES['close']))
 | 
			
		||||
            if not form.is_valid():
 | 
			
		||||
                return self.form_invalid(form)
 | 
			
		||||
                                                   "{closing_date:%Y-%m-%d %H:%M}."),
 | 
			
		||||
                                                 closing_date=settings.REGISTRATION_DATES['close']))
 | 
			
		||||
        return form
 | 
			
		||||
 | 
			
		||||
    @transaction.atomic
 | 
			
		||||
    def form_valid(self, form):
 | 
			
		||||
        role = form.cleaned_data["role"]
 | 
			
		||||
        if role == "participant":
 | 
			
		||||
            registration_form = StudentRegistrationForm(self.request.POST)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user