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

Commit

Permalink
docs(apps/contests): add some documentation for confusing methods/pro…
Browse files Browse the repository at this point in the history
…perties
  • Loading branch information
bitterteriyaki committed Nov 15, 2023
1 parent b8285b2 commit 5298df5
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions apps/contests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,47 @@ def __str__(self) -> str:

@property
def status(self) -> ContestStatus:
"""
Retorna o status atual do contest baseado no horário atual.
.. list-table:: Status do contest
:header-rows: 1
* - Status
- Descrição
* - :attr:`ContestStatus.PENDING`
- Quando o contest ainda não começou.
* - :attr:`ContestStatus.RUNNING`
- Quando o contest está acontecendo.
* - :attr:`ContestStatus.FINISHED`
- Quando o contest já terminou.
* - :attr:`ContestStatus.CANCELLED`
- Quando o contest foi cancelado.
Returns
-------
:class:`ContestStatus`
O status atual do contest.
"""
if self.cancelled:
return ContestStatus.CANCELLED

if self.start_time > now():
elif self.start_time > now():
return ContestStatus.PENDING
elif self.end_time < now():
return ContestStatus.FINISHED
else:
return ContestStatus.RUNNING

def clean(self) -> None:
"""
Validação do contest. Verifica se o :attr:`start_time` é menor
que o :attr:`end_time`, ou seja, se o contest começa antes de
terminar. Se não for, lança um :class:`ValidationError`.
Raises
------
:class:`ValidationError`
Se o :attr:`start_time` for maior que o :attr:`end_time`.
"""
if self.start_time > self.end_time:
raise ValidationError("Start time must be before end time.")

0 comments on commit 5298df5

Please sign in to comment.