Utilise les nouvelles variables de config et fonctions de crans_utils
This commit is contained in:
parent
6ae6e54101
commit
955dd379c7
3 changed files with 13 additions and 13 deletions
|
@ -18,11 +18,10 @@ import re
|
||||||
|
|
||||||
import affichage
|
import affichage
|
||||||
import lc_ldap.shortcuts
|
import lc_ldap.shortcuts
|
||||||
from lc_ldap.crans_utils import to_generalized_time_format as to_gtf
|
|
||||||
|
|
||||||
import mail as mail_module
|
import mail as mail_module
|
||||||
from config import demenagement_delai as delai, \
|
from config import demenagement_delai as delai, \
|
||||||
debut_periode_transitoire, periode_transitoire
|
gtf_debut_periode_transitoire, periode_transitoire
|
||||||
|
|
||||||
ERASE_DAY = { 'second': 0, 'minute': 0, 'microsecond': 0, 'hour': 0, }
|
ERASE_DAY = { 'second': 0, 'minute': 0, 'microsecond': 0, 'hour': 0, }
|
||||||
DAY = datetime.timedelta(days=1)
|
DAY = datetime.timedelta(days=1)
|
||||||
|
@ -113,7 +112,7 @@ if __name__ == '__main__':
|
||||||
conn = lc_ldap.shortcuts.lc_ldap_admin()
|
conn = lc_ldap.shortcuts.lc_ldap_admin()
|
||||||
|
|
||||||
if periode_transitoire:
|
if periode_transitoire:
|
||||||
date = to_gtf(debut_periode_transitoire)
|
date = gtf_debut_periode_transitoire
|
||||||
else:
|
else:
|
||||||
date = now.strftime(FORMAT_LDAP) + 'Z'
|
date = now.strftime(FORMAT_LDAP) + 'Z'
|
||||||
|
|
||||||
|
|
|
@ -12,15 +12,16 @@ import calendar
|
||||||
|
|
||||||
from lc_ldap.shortcuts import lc_ldap_readonly
|
from lc_ldap.shortcuts import lc_ldap_readonly
|
||||||
from lc_ldap.variables import base_dn
|
from lc_ldap.variables import base_dn
|
||||||
|
from lc_ldap import crans_utils
|
||||||
import ldap
|
import ldap
|
||||||
from affich_tools import coul
|
from affich_tools import coul
|
||||||
import gestion.mail as mail_module
|
import gestion.mail as mail_module
|
||||||
import gestion.config as config
|
import gestion.config as config
|
||||||
|
|
||||||
PERIODE_TRANSITOIRE = [
|
PERIODE_TRANSITOIRE = [
|
||||||
datetime.datetime.utcfromtimestamp(date).replace(tzinfo=pytz.UTC)
|
crans_utils.datetime_from_generalized_time_format(date)
|
||||||
for date in
|
for date in
|
||||||
[config.debut_periode_transitoire, config.fin_periode_transitoire]
|
[config.gtf_debut_periode_transitoire, config.gtf_fin_periode_transitoire]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@ ERASE_DAY = {'second': 0, 'minute': 0, 'microsecond': 0, 'hour': 0, }
|
||||||
# NB: finConnexion est un attribut ldap multivalué, et on s'intéresse ici
|
# NB: finConnexion est un attribut ldap multivalué, et on s'intéresse ici
|
||||||
# à sa valeur max pour un adhérent.
|
# à sa valeur max pour un adhérent.
|
||||||
# Les filtres ldap recherchent, de manière existentielle, une valeur valide.
|
# Les filtres ldap recherchent, de manière existentielle, une valeur valide.
|
||||||
# Ainsi, en notant F l'ensemble des valeurs :
|
# Ainsi, en notant F l'ensemble des valeurs :
|
||||||
# max(F) >= v <=> \exists x\in F x>= v <=> finConnexion>=v
|
# max(F) >= v <=> \exists x\in F x>= v <=> finConnexion>=v
|
||||||
# L'autre inégalité ( < ) est plus délicate :
|
# L'autre inégalité ( < ) est plus délicate :
|
||||||
# max(F) < v <=> \forall x\in F x < v <=> \not( \exists x\in F x >= v )
|
# max(F) < v <=> \forall x\in F x < v <=> \not( \exists x\in F x >= v )
|
||||||
|
@ -144,7 +145,7 @@ def brief(c, debut, fin):
|
||||||
to_warn = select(c, debut, fin)
|
to_warn = select(c, debut, fin)
|
||||||
print ("%d adhérents seront prévenus que leur connexion expire entre le %s " + \
|
print ("%d adhérents seront prévenus que leur connexion expire entre le %s " + \
|
||||||
"et le %s") % (len(to_warn), debut, fin)
|
"et le %s") % (len(to_warn), debut, fin)
|
||||||
|
|
||||||
if "--list" in sys.argv:
|
if "--list" in sys.argv:
|
||||||
for adh in to_warn:
|
for adh in to_warn:
|
||||||
valeurs = [max(parse_gtf(v.value) for v in adh[l]) \
|
valeurs = [max(parse_gtf(v.value) for v in adh[l]) \
|
||||||
|
@ -158,10 +159,10 @@ def prev_calendar(c, date):
|
||||||
"""Prévisualise l'expiration des connexions sur le mois courant"""
|
"""Prévisualise l'expiration des connexions sur le mois courant"""
|
||||||
month = date.month
|
month = date.month
|
||||||
year = date.year
|
year = date.year
|
||||||
|
|
||||||
cal = calendar.Calendar()
|
cal = calendar.Calendar()
|
||||||
|
|
||||||
first = datetime.datetime(day=1, month=month, year=year, tzinfo=pytz.UTC)
|
first = datetime.datetime(day=1, month=month, year=year, tzinfo=pytz.UTC)
|
||||||
last = first.replace(month=1+month%12, year=year+int(month == 12))
|
last = first.replace(month=1+month%12, year=year+int(month == 12))
|
||||||
|
|
||||||
disconnect = select(c, first, last)
|
disconnect = select(c, first, last)
|
||||||
|
@ -173,7 +174,7 @@ def prev_calendar(c, date):
|
||||||
if date.tzinfo:
|
if date.tzinfo:
|
||||||
date -= date.tzinfo.utcoffset(date)
|
date -= date.tzinfo.utcoffset(date)
|
||||||
by_day[date.day] += 1
|
by_day[date.day] += 1
|
||||||
|
|
||||||
yield ['L', 'M', 'Me', 'J', 'V', 'S', 'D']
|
yield ['L', 'M', 'Me', 'J', 'V', 'S', 'D']
|
||||||
l = []
|
l = []
|
||||||
for d in cal.itermonthdays(year, month):
|
for d in cal.itermonthdays(year, month):
|
||||||
|
@ -221,7 +222,7 @@ def prev_mail(calendar):
|
||||||
mailtxt = mail_module.generate('fin_connexion_stats', data)
|
mailtxt = mail_module.generate('fin_connexion_stats', data)
|
||||||
with mail_module.ServerConnection() as mail_conn:
|
with mail_module.ServerConnection() as mail_conn:
|
||||||
mail_conn.sendmail(From, [To], mailtxt.as_string())
|
mail_conn.sendmail(From, [To], mailtxt.as_string())
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
db = lc_ldap_readonly()
|
db = lc_ldap_readonly()
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ def adherents(regen=False):
|
||||||
adhérents"""
|
adhérents"""
|
||||||
|
|
||||||
if regen or not adherents.data:
|
if regen or not adherents.data:
|
||||||
adherents.data = DB.search(u'(&(debutAdhesion>=%s)(aid=*))' % (crans_utils.to_generalized_time_format(config.debut_periode_transitoire)), sizelimit=2000)
|
adherents.data = DB.search(u'(&(debutAdhesion>=%s)(aid=*))' % (config.gtf_debut_periode_transitoire,), sizelimit=2000)
|
||||||
return list(adherents.data)
|
return list(adherents.data)
|
||||||
|
|
||||||
@static_var(("data", []))
|
@static_var(("data", []))
|
||||||
|
@ -59,7 +59,7 @@ def factures(regen=False):
|
||||||
|
|
||||||
if regen or not factures.data:
|
if regen or not factures.data:
|
||||||
factures.data = DB.search(u'(&(|(debutAdhesion>=%(now)s)(debutConnexion>=%(now)s))(fid=*))' % {
|
factures.data = DB.search(u'(&(|(debutAdhesion>=%(now)s)(debutConnexion>=%(now)s))(fid=*))' % {
|
||||||
'now': crans_utils.to_generalized_time_format(config.debut_periode_transitoire),
|
'now': config.gtf_debut_periode_transitoire,
|
||||||
}, sizelimit=0)
|
}, sizelimit=0)
|
||||||
return list(factures.data)
|
return list(factures.data)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue