def clean(self): if not is_registration_open(): raise forms.ValidationError( _("You cannot change teams after registration has closed."), code="registration_closed", ) return super().clean()
def dispatch(self, request, *args, **kwargs): if hasattr(request.user, "application"): return redirect(reverse_lazy("event:dashboard")) if not is_registration_open(): return redirect(reverse_lazy("event:dashboard")) return super().dispatch(request, *args, **kwargs)
def clean(self): if not is_registration_open(): raise forms.ValidationError(_("Registration has closed."), code="registration_closed") cleaned_data = super().clean() if hasattr(self.user, "application"): raise forms.ValidationError( _("User has already submitted an application."), code="invalid") return cleaned_data
def get_form(self, form_class=None): """ The dashboard can have different forms, but not at the same time: - When no application has been submitted, no form. - Once an application has been submitted and registration is open, the JoinTeamForm. - Once the application has been reviewed and accepted, no form, but will show buttons to RSVP Yes or RSVP No - Once the application has been reviewed and rejected, no form. """ if form_class is not None: return form_class(**self.get_form_kwargs()) if not hasattr(self.request.user, "application"): return None if hasattr(self.request.user.application, "review"): return None if is_registration_open(): return JoinTeamForm(**self.get_form_kwargs()) return None
def leave_team(self, request): if not is_registration_open(): return HttpResponseBadRequest( "You cannot change teams after registration has closed.". encode(encoding="utf-8")) if not hasattr(request.user, "application"): return HttpResponseBadRequest( "You have not submitted an application.".encode( encoding="utf-8")) application = self.request.user.application team = application.team # Leaving a team automatically puts them on a new team application.team = RegistrationTeam.objects.create() application.save() # Delete the team if it is empty if not team.applications.exists(): team.delete() return redirect(reverse_lazy("event:dashboard"))
def test_not_open_anymore(self, mock_datetime): mock_datetime.now.return_value.replace.return_value = datetime( 2020, 1, 2, tzinfo=settings.TZ_INFO) self.assertFalse(is_registration_open())
def registration_allowed(self): return is_registration_open()