Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
feat(validators): contest admin form validator - fix errors.3
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizaMaluf committed Nov 14, 2023
1 parent be6fc1d commit 8daf84f
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions apps/contests/models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from typing import Any

from django import forms
from django.core.exceptions import ValidationError
from django.db.models import (
BooleanField,
CharField,
DateTimeField,
ManyToManyField,
)
from django.utils import timezone
from django.utils.timezone import now

from apps.contests.enums import ContestStatus
Expand Down Expand Up @@ -48,22 +46,8 @@ def status(self) -> ContestStatus:
else:
return ContestStatus.RUNNING

def clean(self) -> Any:
super().clean()

Check warning on line 50 in apps/contests/models.py

View check run for this annotation

Codecov / codecov/patch

apps/contests/models.py#L50

Added line #L50 was not covered by tests

class ContestAdminForm(forms.ModelForm["Contest"]):
def clean_start_time(self) -> Any:
start_time = self.cleaned_data.get("start_time")
if start_time and start_time <= timezone.now():
raise ValidationError("A data de início deve estar no futuro.")

return start_time

def clean_end_time(self) -> Any:
end_time = self.cleaned_data.get("end_time")
start_time = self.cleaned_data.get("start_time")

if end_time and end_time <= start_time:
raise ValidationError(
"A data de término deve ser posterior a data de início."
)

return end_time
if self.start_time > self.end_time:
raise ValidationError("Start time must be before end time.")

Check warning on line 53 in apps/contests/models.py

View check run for this annotation

Codecov / codecov/patch

apps/contests/models.py#L52-L53

Added lines #L52 - L53 were not covered by tests

0 comments on commit 8daf84f

Please sign in to comment.