mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Simplify models.py
This commit is contained in:
parent
7db8872bc8
commit
21f95fbc9d
1 changed files with 9 additions and 15 deletions
|
@ -528,27 +528,21 @@ class Mandate(RevMixin, AclMixin, models.Model):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_mandate(cls, date=timezone.now):
|
def get_mandate(cls, date=timezone.now):
|
||||||
""""Find the mandate taking place at the given date. If none is found
|
""""Find the mandate taking place at the given date."""
|
||||||
look for the nearest in the future. If none is found (again), look
|
|
||||||
for the nearest in the past."""
|
|
||||||
if callable(date):
|
if callable(date):
|
||||||
date = date()
|
date = date()
|
||||||
try:
|
mandate = cls.objects.filter(start_date__lte=date).order_by('-start_date').first()
|
||||||
return cls.objects.get(
|
if not mandate:
|
||||||
start_date__gte=date, end_date__lte=date
|
raise cls.DoesNotExist("No mandate have been created. Please go to the preferences page to create one.")
|
||||||
)
|
return mandate
|
||||||
except cls.DoesNotExist:
|
|
||||||
try:
|
|
||||||
return cls.objects.filter(start_date__gte=date).earliest('start_date')
|
|
||||||
except cls.DoesNotExist:
|
|
||||||
try:
|
|
||||||
return cls.objects.filter(start_date__lte=date).latest('start_date')
|
|
||||||
except cls.DoesNotExist:
|
|
||||||
raise cls.DoesNotExist("No mandate have been created. Please go to the preferences page to create one.")
|
|
||||||
|
|
||||||
|
|
||||||
def is_over(self):
|
def is_over(self):
|
||||||
return self.end_date is None
|
return self.end_date is None
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.president) + ' ' + str(self.start_date.year)
|
||||||
|
|
||||||
|
|
||||||
class AssoOption(AclMixin, PreferencesModel):
|
class AssoOption(AclMixin, PreferencesModel):
|
||||||
"""Options générales de l'asso : siret, addresse, nom, etc"""
|
"""Options générales de l'asso : siret, addresse, nom, etc"""
|
||||||
|
|
Loading…
Reference in a new issue