예제 #1
0
    def clean(self):
        cleaned_data = super(MailSubmissionForm, self).clean()
        ccontroller = self.request.contest.controller

        if 'problem_instance_id' not in cleaned_data:
            return cleaned_data

        try:
            pi = ProblemInstance.objects.filter(contest=self.request.contest) \
                    .get(id=cleaned_data['problem_instance_id'])
            cleaned_data['problem_instance'] = pi
        except ProblemInstance.DoesNotExist:
            self._errors['problem_instance_id'] = \
                    self.error_class([_("Invalid problem")])
            del cleaned_data['problem_instance_id']
            return cleaned_data

        decision = is_mailsubmit_allowed(self.request) and \
            ccontroller.can_submit(self.request, pi, check_round_times=False)
        if not decision:
            raise ValidationError(getattr(decision, 'exc',
                                              _("Permission denied")))

        if cleaned_data['prog_lang'] and \
                cleaned_data['prog_lang'] not in \
                pi.controller.get_allowed_languages():
            self._errors['prog_lang'] = \
                    self.error_class([_("Disallowed language")])
            del cleaned_data['prog_lang']
            return cleaned_data

        return ccontroller.validate_submission_form(self.request, pi, self,
                                                    cleaned_data)
예제 #2
0
파일: forms.py 프로젝트: pragacz/oioioi
    def clean(self):
        cleaned_data = super(MailSubmissionForm,
                             self).clean(check_submission_limit=False,
                                         check_round_times=False)

        decision = is_mailsubmit_allowed(self.request)
        if not decision:
            raise ValidationError(
                getattr(decision, 'exc', _("Permission denied")))
        return cleaned_data
예제 #3
0
파일: forms.py 프로젝트: papedaniel/oioioi
    def clean(self):
        cleaned_data = super(MailSubmissionForm, self).clean()
        ccontroller = self.request.contest.controller

        if "problem_instance_id" not in cleaned_data:
            return cleaned_data

        try:
            pi = ProblemInstance.objects.filter(contest=self.request.contest).get(
                id=cleaned_data["problem_instance_id"]
            )
            cleaned_data["problem_instance"] = pi
        except ProblemInstance.DoesNotExist:
            self._errors["problem_instance_id"] = self.error_class([_("Invalid problem")])
            del cleaned_data["problem_instance_id"]
            return cleaned_data

        decision = is_mailsubmit_allowed(self.request) and ccontroller.can_submit(
            self.request, pi, check_round_times=False
        )
        if not decision:
            raise ValidationError(getattr(decision, "exc", _("Permission denied")))

        return ccontroller.validate_submission_form(self.request, pi, self, cleaned_data)