Revert des deux commits précédents : c'était un problème de types

* tuple vs list dans les results.
This commit is contained in:
Pierre-Elliott Bécue 2015-03-30 17:18:54 +02:00
parent 93ee03aee9
commit fdfdd23022

View file

@ -30,34 +30,11 @@ import gestion.mail as mail_module
# Ça printe au lieu de faire bobo quand c'est à True # Ça printe au lieu de faire bobo quand c'est à True
DEBUG = False DEBUG = False
LDAP = shortcuts.lc_ldap_admin()
EPOCH = pytz.utc.localize(datetime.datetime(1970, 1, 1)) EPOCH = pytz.utc.localize(datetime.datetime(1970, 1, 1))
TZ = pytz.timezone('Europe/Paris') TZ = pytz.timezone('Europe/Paris')
DELTA = datetime.timedelta(0, upload.interval * 3600, 0) DELTA = datetime.timedelta(0, upload.interval * 3600, 0)
CUR_DATE = TZ.normalize(TZ.localize(datetime.datetime.now())) CUR_DATE = TZ.normalize(TZ.localize(datetime.datetime.now()))
# Connection à la base sql via pgsql
PGSQL = psycopg2.connect(database='filtrage', user='crans')
PGSQL.set_session(autocommit=True)
CURSEUR = PGSQL.cursor(cursor_factory=psycopg2.extras.DictCursor)
# Avertis upload hard
REQUETE = "SELECT type, id FROM avertis_upload_hard WHERE date > now() - %(interval)s;"
CURSEUR.execute(REQUETE, {
'interval': DELTA,
})
AVERTIS_UPLOAD_HARD = CURSEUR.fetchall()
# Avertis upload soft
REQUETE = "SELECT type, id FROM avertis_upload_soft WHERE date > now() - %(interval)s"
CURSEUR.execute(REQUETE, {
'interval': DELTA,
})
AVERTIS_UPLOAD_SOFT = CURSEUR.fetchall()
QUERY = """WITH QUERY = """WITH
machines_sans_doublon machines_sans_doublon
AS AS
@ -408,7 +385,7 @@ def single_check(eltype, elid, elupload, ldap, curseur):
if elupload >= upload.hard: if elupload >= upload.hard:
# L'adhérent a t il été blacklisté ? # L'adhérent a t il été blacklisté ?
#################################### ####################################
if (eltype, elid) in AVERTIS_UPLOAD_HARD and not DEBUG: if [eltype, int(elid)] in AVERTIS_UPLOAD_HARD and not DEBUG:
return return
# Propriétaire issu de LDAP # Propriétaire issu de LDAP
@ -430,7 +407,7 @@ def single_check(eltype, elid, elupload, ldap, curseur):
elif elupload >= upload.soft: elif elupload >= upload.soft:
# L'adhérent a t il été averti ou est déjà déco ? # L'adhérent a t il été averti ou est déjà déco ?
################################################# #################################################
if ((eltype, elid) in AVERTIS_UPLOAD_SOFT or (eltype, elid) in AVERTIS_UPLOAD_HARD) and not DEBUG: if ([eltype, int(elid)] in AVERTIS_UPLOAD_SOFT or [eltype, int(elid)] in AVERTIS_UPLOAD_HARD) and not DEBUG:
return return
# Objets LDAP # Objets LDAP
@ -496,4 +473,27 @@ def reperage_chambre(mac):
return "Inconnue", "Inconnue" return "Inconnue", "Inconnue"
if __name__ == "__main__": if __name__ == "__main__":
LDAP = shortcuts.lc_ldap_admin()
# Connection à la base sql via pgsql
PGSQL = psycopg2.connect(database='filtrage', user='crans')
PGSQL.set_session(autocommit=True)
CURSEUR = PGSQL.cursor(cursor_factory=psycopg2.extras.DictCursor)
# Avertis upload hard
REQUETE = "SELECT type, id FROM avertis_upload_hard WHERE date > now() - %(interval)s;"
CURSEUR.execute(REQUETE, {
'interval': DELTA,
})
AVERTIS_UPLOAD_HARD = CURSEUR.fetchall()
# Avertis upload soft
REQUETE = "SELECT type, id FROM avertis_upload_soft WHERE date > now() - %(interval)s"
CURSEUR.execute(REQUETE, {
'interval': DELTA,
})
AVERTIS_UPLOAD_SOFT = CURSEUR.fetchall()
main(CURSEUR, LDAP) main(CURSEUR, LDAP)