diff --git a/attributs.py b/attributs.py index 7c1e897..5358be2 100644 --- a/attributs.py +++ b/attributs.py @@ -638,26 +638,30 @@ class generalizedTimeFormat(Attr): """ __slots__ = ("stamp", "datetime",) - default = "19700101000000Z" + python_type = datetime.datetime + default = datetime_from_generalized_time_format("19700101000000Z") + + def __unicode__(self): + return unicode(datetime_to_generalized_time_format(self.value)) def __float__(self): - return self.stamp + return from_generalized_time_format(unicode(self)) def __int__(self): - return int(self.stamp) + return int(float(self)) def __eq__(self, othertime): if isinstance(othertime, generalizedTimeFormat): - return self.stamp == othertime.stamp + return self.value == othertime.value elif isinstance(othertime, float): - return self.stamp == othertime + return float(self) == othertime elif isinstance(othertime, int): - return self.stamp == othertime + return int(self) == othertime elif isinstance(othertime, unicode) or isinstance(othertime, str): resource = generalizedTimeFormat(othertime, conn=None, Parent=None) - return self.stamp == resource.stamp + return self == resource elif isinstance(othertime, datetime.datetime): - return self.datetime == othertime + return self.value == othertime else: return False @@ -666,16 +670,16 @@ class generalizedTimeFormat(Attr): def __lt__(self, othertime): if isinstance(othertime, generalizedTimeFormat): - return self.stamp < othertime.stamp + return self.value < othertime.value elif isinstance(othertime, float): - return self.stamp < othertime + return float(self) < othertime elif isinstance(othertime, int): - return self.stamp < othertime + return int(self) < othertime elif isinstance(othertime, unicode) or isinstance(othertime, str): resource = generalizedTimeFormat(othertime, conn=None, Parent=None) - return self.stamp < resource.stamp + return self < resource elif isinstance(othertime, datetime.datetime): - return self.datetime < othertime + return self.value < othertime else: return False @@ -690,21 +694,9 @@ class generalizedTimeFormat(Attr): def parse_value(self, gtf): if isinstance(gtf, str) or isinstance(gtf, unicode): - if not ('Z' in gtf or '+' in gtf or '-' in gtf): - self.stamp = gtf - self.value = to_generalized_time_format(float(gtf)) - self.datetime = datetime_from_generalized_time_format(self.value) - else: - self.stamp = from_generalized_time_format(gtf) - self.datetime = datetime_from_generalized_time_format(gtf) - self.value = gtf - elif isinstance(gtf, float): - self.stamp = gtf - self.value = to_generalized_time_format(gtf) - self.datetime = datetime_from_generalized_time_format(self.value) + self.value = datetime_from_generalized_time_format(gtf) elif isinstance(gtf, datetime.datetime): - self.datetime = gtf - self.value = datetime_to_generalized_time_format(gtf) + self.value = gtf self.stamp = from_generalized_time_format(self.value) @crans_attribute diff --git a/objets.py b/objets.py index ebe3886..be26b70 100644 --- a/objets.py +++ b/objets.py @@ -1038,33 +1038,42 @@ class proprio(CransLdapObject): def fin_adhesion(self): """Retourne la date de fin d'adhésion""" return max([ - float(facture.get('finAdhesion', [crans_utils.from_generalized_time_format(attributs.finAdhesion.default)])[0]) + facture.get('finAdhesion', [attributs.finAdhesion.default])[0] for facture in self.factures(refresh=(time.time() - self._factures_last_update > FACTURES_REFRESH_PERIOD)) if facture.get('controle', [''])[0] != u"FALSE" and facture.get('recuPaiement', []) - ] + [0.0]) - - def fin_connexion_datetime(self): - return datetime.datetime.fromtimestamp(self.fin_connexion()) - - def fin_adhesion_datetime(self): - return datetime.datetime.fromtimestamp(self.fin_adhesion()) + ] + [attributs.finAdhesion.default]) def fin_connexion(self): """Retourne la date de fin de connexion""" return max([ - float(facture.get('finConnexion', [crans_utils.from_generalized_time_format(attributs.finConnexion.default)])[0]) + facture.get('finConnexion', [attributs.finConnexion.default])[0] for facture in self.factures(refresh=(time.time() - self._factures_last_update > FACTURES_REFRESH_PERIOD)) if facture.get('controle', [''])[0] != u"FALSE" and facture.get('recuPaiement', []) - ] + [0.0]) + ] + [attributs.finConnexion.default]) def adhesion_ok(self, no_bl=False): """Renvoie si le propriétaire a une adhésion en cours.""" + if self.dn == variables.base_dn: return True + _now = crans_utils.localized_datetime() + fin_paiement = self.fin_adhesion() - paiement = time.time() < fin_paiement or (config.periode_transitoire and config.debut_periode_transitoire <= fin_paiement <= config.fin_periode_transitoire) + paiement = ( + _now < fin_paiement + or + ( + config.periode_transitoire + and + ( + crans_utils.datetime_from_generalized_time_format(config.gtf_debut_periode_transitoire) + <= fin_paiement + <= crans_utils.datetime_from_generalized_time_format(config.gtf_fin_periode_transitoire) + ) + ) + ) return paiement @@ -1081,12 +1090,26 @@ class proprio(CransLdapObject): if bl['type'] == 'paiement': return False + _now = crans_utils.localized_datetime() + if isinstance(self, adherent): fin_paiement = min(self.fin_adhesion(), self.fin_connexion()) else: fin_paiement = self.fin_adhesion() - paiement = time.time() < fin_paiement or (config.periode_transitoire and config.debut_periode_transitoire <= fin_paiement <= config.fin_periode_transitoire) + paiement = ( + _now < fin_paiement + or + ( + config.periode_transitoire + and + ( + crans_utils.datetime_from_generalized_time_format(config.gtf_debut_periode_transitoire) + <= fin_paiement + <= crans_utils.datetime_from_generalized_time_format(config.gtf_fin_periode_transitoire) + ) + ) + ) return paiement diff --git a/printing/templates/templates.py b/printing/templates/templates.py index 4686f80..29d33cb 100644 --- a/printing/templates/templates.py +++ b/printing/templates/templates.py @@ -267,25 +267,31 @@ def list_clubs(clubs, width=None): ) def proprio(proprio, params): - params['o']=proprio - etat_administratif=[] + _now = crans_utils.localized_datetime() + params['o'] = proprio + etat_administratif = [] + if proprio.paiement_ok(): etat_administratif.append(style(u"à jour", "vert")) + if not proprio.paiement_ok(): etat_administratif.append(style(u"cotisation non réglée", "violet")) - if proprio.fin_adhesion() >= time.time(): + + if proprio.fin_adhesion() >= _now: adh = style(u"Adhésion jusqu'au %s" % (time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(proprio.fin_adhesion())),), "vert") elif proprio.paiement_ok(): adh = style(u"Adhésion terminée, mais il y a un sursis.", 'orange') else: adh = style(u"Pas adhérent actuellement.", 'rouge') + params["adh"] = adh - if proprio.fin_connexion() >= time.time(): + if proprio.fin_connexion() >= _now: conn = style(u"Connexion jusqu'au %s" % (time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(proprio.fin_connexion())),), "vert") elif proprio.paiement_ok(): conn = style(u"Connexion terminée, mais il y a un sursis.", 'orange') else: conn = style(u"Pas connecté actuellement.", 'rouge') + params["conn"] = conn params['etat_administratif'] = etat_administratif