mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2024-12-05 02:06:52 +00:00
Add a method to query the current phase
This commit is contained in:
parent
1d0246af8f
commit
ab315a69ed
@ -193,6 +193,16 @@ class Phase(models.Model):
|
||||
default=timezone.now,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def current_phase(cls):
|
||||
qs = Phase.objects.filter(start__lte=timezone.now(), end__gte=timezone.now())
|
||||
if qs.exists():
|
||||
return qs.get()
|
||||
qs = Phase.objects.order_by("phase_number").all()
|
||||
if timezone.now() < qs.first().start:
|
||||
return qs.first()
|
||||
return qs.last()
|
||||
|
||||
def __str__(self):
|
||||
return _("Phase {phase_number:d} starts on {start:%Y-%m-%d %H:%M} and ends on {end:%Y-%m-%d %H:%M}")\
|
||||
.format(phase_number=self.phase_number, start=self.start, end=self.end)
|
||||
|
Loading…
Reference in New Issue
Block a user