8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-30 08:32:26 +00:00

Evaluation dynamique de la date

This commit is contained in:
Gabriel Detraz 2018-01-10 21:20:54 +01:00 committed by root
parent dcb52d938b
commit dfa62464c6

View file

@ -82,8 +82,6 @@ from machines.models import Domain, Interface, Machine, regen
from preferences.models import GeneralOption, AssoOption, OptionalUser from preferences.models import GeneralOption, AssoOption, OptionalUser
from preferences.models import OptionalMachine, MailMessageOption from preferences.models import OptionalMachine, MailMessageOption
DT_NOW = timezone.now()
# Utilitaires généraux # Utilitaires généraux
@ -334,7 +332,7 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
end = self.end_adhesion() end = self.end_adhesion()
if not end: if not end:
return False return False
elif end < DT_NOW: elif end < timezone.now():
return False return False
else: else:
return True return True
@ -345,7 +343,7 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
end = self.end_connexion() end = self.end_connexion()
if not end: if not end:
return False return False
elif end < DT_NOW: elif end < timezone.now():
return False return False
else: else:
return self.is_adherent() return self.is_adherent()
@ -369,7 +367,7 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
end = self.end_ban() end = self.end_ban()
if not end: if not end:
return False return False
elif end < DT_NOW: elif end < timezone.now():
return False return False
else: else:
return True return True
@ -379,7 +377,7 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
end = self.end_whitelist() end = self.end_whitelist()
if not end: if not end:
return False return False
elif end < DT_NOW: elif end < timezone.now():
return False return False
else: else:
return True return True
@ -1282,7 +1280,7 @@ class Ban(models.Model):
def is_active(self): def is_active(self):
"""Ce ban est-il actif?""" """Ce ban est-il actif?"""
return self.date_end > DT_NOW return self.date_end > timezone.now()
def get_instance(banid, *args, **kwargs): def get_instance(banid, *args, **kwargs):
return Ban.objects.get(pk=banid) return Ban.objects.get(pk=banid)
@ -1388,7 +1386,7 @@ class Whitelist(models.Model):
) )
def is_active(self): def is_active(self):
return self.date_end > DT_NOW return self.date_end > timezone.now()
def get_instance(whitelistid, *args, **kwargs): def get_instance(whitelistid, *args, **kwargs):
return Whitelist.objects.get(pk=whitelistid) return Whitelist.objects.get(pk=whitelistid)
@ -1497,7 +1495,7 @@ class Request(models.Model):
def save(self): def save(self):
if not self.expires_at: if not self.expires_at:
options, _created = GeneralOption.objects.get_or_create() options, _created = GeneralOption.objects.get_or_create()
self.expires_at = DT_NOW \ self.expires_at = timezone.now() \
+ datetime.timedelta(hours=options.req_expire_hrs) + datetime.timedelta(hours=options.req_expire_hrs)
if not self.token: if not self.token:
self.token = str(uuid.uuid4()).replace('-', '') # remove hyphens self.token = str(uuid.uuid4()).replace('-', '') # remove hyphens