コード例 #1
0
ファイル: forms.py プロジェクト: ieeeuoft/newhacks-site-2020
    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()
コード例 #2
0
ファイル: views.py プロジェクト: ieeeuoft/makeuoft-site-2021
    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)
コード例 #3
0
ファイル: forms.py プロジェクト: ieeeuoft/newhacks-site-2020
    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
コード例 #4
0
ファイル: views.py プロジェクト: ieeeuoft/newhacks-site-2020
    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
コード例 #5
0
ファイル: views.py プロジェクト: ieeeuoft/newhacks-site-2020
    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"))
コード例 #6
0
 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())
コード例 #7
0
ファイル: views.py プロジェクト: ieeeuoft/makeuoft-site-2021
 def registration_allowed(self):
     return is_registration_open()