Skip to content
Snippets Groups Projects
Commit 25bbd55b authored by Julian's avatar Julian
Browse files

Add property `isCurrent` to validityranges

parent e59bcad1
No related branches found
No related tags found
1 merge request!29Resolve "Switch validity range and group select"
...@@ -122,6 +122,7 @@ query timeGrids($orderBy: [String], $filters: JSONString) { ...@@ -122,6 +122,7 @@ query timeGrids($orderBy: [String], $filters: JSONString) {
validityRange { validityRange {
id id
name name
isCurrent
dateStart dateStart
dateEnd dateEnd
} }
......
...@@ -72,6 +72,10 @@ class ValidityRange(ExtensibleModel): ...@@ -72,6 +72,10 @@ class ValidityRange(ExtensibleModel):
"""Get the currently active validity range.""" """Get the currently active validity range."""
return cls.get_current() return cls.get_current()
@property
def is_current(self) -> bool:
return self.date_start <= (today := timezone.now().date()) and self.date_end >= today
def clean(self): def clean(self):
"""Ensure that there is only one validity range at each point of time.""" """Ensure that there is only one validity range at each point of time."""
if self.date_end < self.date_start: if self.date_end < self.date_start:
......
...@@ -18,6 +18,7 @@ from ..models import ValidityRange ...@@ -18,6 +18,7 @@ from ..models import ValidityRange
class ValidityRangeType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectType): class ValidityRangeType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectType):
is_current = graphene.Boolean()
class Meta: class Meta:
model = ValidityRange model = ValidityRange
fields = ("id", "school_term", "name", "date_start", "date_end", "status", "time_grids") fields = ("id", "school_term", "name", "date_start", "date_end", "status", "time_grids")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment