Merge with Yohan
This commit is contained in:
commit
d609a5dc51
@ -37,10 +37,23 @@ class MembersController(AuthenticatedBaseController):
|
|||||||
members = Member.get_all(self.user, residence_dn)
|
members = Member.get_all(self.user, residence_dn)
|
||||||
members = MembersController.sort_name(members)
|
members = MembersController.sort_name(members)
|
||||||
|
|
||||||
members_rooms = [
|
rooms = Room.get_rooms(self.user, residence_dn)
|
||||||
(member, Room.get_by_member_dn(self.user, residence_dn, member.dn))
|
rooms_dict = dict()
|
||||||
for member in members
|
for room in rooms:
|
||||||
]
|
if room.get("x-memberIn").first is not None:
|
||||||
|
rooms_dict[room.get("x-memberIn").first()] = room
|
||||||
|
#end if
|
||||||
|
#end for
|
||||||
|
|
||||||
|
#raise Exception("ee")
|
||||||
|
members_rooms = []
|
||||||
|
for member in members:
|
||||||
|
if member.dn in rooms_dict:
|
||||||
|
members_rooms.append((member, rooms_dict[member.dn]))
|
||||||
|
else:
|
||||||
|
members_rooms.append((member, None))
|
||||||
|
#end if
|
||||||
|
#end for
|
||||||
|
|
||||||
# machines = Machine.get_machine_tuples_of_member(self.user, member.dn)
|
# machines = Machine.get_machine_tuples_of_member(self.user, member.dn)
|
||||||
|
|
||||||
|
@ -45,26 +45,34 @@ class RoomsController(AuthenticatedBaseController):
|
|||||||
status = dict()
|
status = dict()
|
||||||
areas = dict()
|
areas = dict()
|
||||||
|
|
||||||
print "here 1"
|
|
||||||
|
|
||||||
residence_dn = Residences.get_dn_by_name(self.user, residence_name)
|
residence_dn = Residences.get_dn_by_name(self.user, residence_name)
|
||||||
if residence_dn is None:
|
if residence_dn is None:
|
||||||
raise Exception("unknown residence")
|
raise Exception("unknown residence")
|
||||||
#end if
|
#end if
|
||||||
|
|
||||||
print "here 1 bis"
|
current_year = CotisationComputes.current_year()
|
||||||
|
cotisations_year = Cotisation.get_all_cotisation_by_year(self.user, residence_dn, current_year)
|
||||||
|
|
||||||
stats = CotisationComputes.members_status_from_residence(self.user, residence_dn)
|
stats = CotisationComputes.members_status_from_list_cotisations(self.user, residence_dn, cotisations_year)
|
||||||
print "here 2"
|
|
||||||
|
|
||||||
members = dict()
|
members = dict()
|
||||||
|
members_entries = Member.get_all(self.user, residence_dn)
|
||||||
|
members_entries_dict = dict()
|
||||||
|
for member in members_entries:
|
||||||
|
members_entries_dict[member.dn] = member
|
||||||
|
#end for
|
||||||
for label in stats:
|
for label in stats:
|
||||||
for member in stats[label]:
|
liste = []
|
||||||
members[member.dn] = label
|
for member_dn in stats[label]:
|
||||||
|
members[member_dn] = label
|
||||||
|
liste.append(member_dn)
|
||||||
#end for member
|
#end for member
|
||||||
|
for item in liste:
|
||||||
|
stats[label].remove(item)
|
||||||
|
stats[label].append(members_entries_dict[item])
|
||||||
|
#end for item liste
|
||||||
#end for stats
|
#end for stats
|
||||||
|
|
||||||
print "here 3"
|
|
||||||
|
|
||||||
stats['number_of_rooms'] = Room.get_number_of_rooms(self.user, residence_dn)
|
stats['number_of_rooms'] = Room.get_number_of_rooms(self.user, residence_dn)
|
||||||
stats['empty_rooms'] = []
|
stats['empty_rooms'] = []
|
||||||
|
@ -29,6 +29,8 @@ class ShowController(AuthenticatedBaseController):
|
|||||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||||
|
|
||||||
member = Member.get_by_uid(self.user, residence_dn, uid)
|
member = Member.get_by_uid(self.user, residence_dn, uid)
|
||||||
|
# truc = self.user.ldap_bind.get_childs("uid=romain.beuque,ou=2012,ou=membres,dc=emilie,dc=u-psud,dc=fr")
|
||||||
|
# raise Exception("")
|
||||||
|
|
||||||
if member is None:
|
if member is None:
|
||||||
return self.error_no_entry()
|
return self.error_no_entry()
|
||||||
|
@ -157,10 +157,12 @@ class CotisationComputes:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
# old = SDF or no cotisation this year
|
# old = SDF or no cotisation this year
|
||||||
def is_old_member(member, user_session, residence_dn):
|
def is_old_member(member_dn, user_session, residence_dn, cotisations = None):
|
||||||
|
if cotisations is None:
|
||||||
current_year = CotisationComputes.current_year()
|
current_year = CotisationComputes.current_year()
|
||||||
cotisations = Cotisation.cotisations_of_member(user_session, member.dn, current_year)
|
cotisations = Cotisation.cotisations_of_member(user_session, member_dn, current_year)
|
||||||
return Room.get_by_member_dn(user_session, residence_dn, member.dn) == None or cotisations == []
|
#end if
|
||||||
|
return Room.get_by_member_dn(user_session, residence_dn, member_dn) == None or cotisations == []
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -174,29 +176,35 @@ class CotisationComputes:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
# 7 days grace period
|
# 7 days grace period
|
||||||
def is_cotisation_paid(member, user_session, residence_dn):
|
def is_cotisation_paid(member_dn, user_session, residence_dn, cotisations = None):
|
||||||
if CotisationComputes.is_old_member(member, user_session, residence_dn):
|
if CotisationComputes.is_old_member(member_dn, user_session, residence_dn, cotisations):
|
||||||
return False
|
return False
|
||||||
|
if cotisations is None:
|
||||||
current_year = CotisationComputes.current_year()
|
current_year = CotisationComputes.current_year()
|
||||||
|
#end if
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
|
|
||||||
cotisations = Cotisation.cotisations_of_member(user_session, member.dn, current_year)
|
if cotisations is None:
|
||||||
|
cotisations = Cotisation.cotisations_of_member(user_session, member_dn, current_year)
|
||||||
|
#end if
|
||||||
anniversary = CotisationComputes.anniversary_from_ldap_items(cotisations)
|
anniversary = CotisationComputes.anniversary_from_ldap_items(cotisations)
|
||||||
delta = (now - anniversary)
|
delta = (now - anniversary)
|
||||||
if member.dn == "uid=emir.kort,ou=2013,ou=membres,dc=ile,dc=u-psud,dc=fr":
|
|
||||||
print "member :" + member.dn + "delta :" + str(delta) + "now :" + str(now) + "anniversary :" + str(anniversary)
|
|
||||||
return delta.days <= 7
|
return delta.days <= 7
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
# less than a month late but more than a week
|
# less than a month late but more than a week
|
||||||
def is_cotisation_late(member, user_session, residence_dn):
|
def is_cotisation_late(member_dn, user_session, residence_dn, cotisations = None):
|
||||||
if CotisationComputes.is_old_member(member, user_session, residence_dn):
|
if CotisationComputes.is_old_member(member_dn, user_session, residence_dn, cotisations):
|
||||||
return False
|
return False
|
||||||
|
if cotisations is None:
|
||||||
current_year = CotisationComputes.current_year()
|
current_year = CotisationComputes.current_year()
|
||||||
|
#end if
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
|
|
||||||
cotisations = Cotisation.cotisations_of_member(user_session, member.dn, current_year)
|
if cotisations is None:
|
||||||
|
cotisations = Cotisation.cotisations_of_member(user_session, member_dn, current_year)
|
||||||
|
#end if
|
||||||
anniversary = CotisationComputes.anniversary_from_ldap_items(cotisations)
|
anniversary = CotisationComputes.anniversary_from_ldap_items(cotisations)
|
||||||
delta = (now - anniversary)
|
delta = (now - anniversary)
|
||||||
#print("[DEBUG] cotisation en retard pour l'utilisateur "+ member.dn +" now="+ str(now) +" anniversary="+ str(anniversary) +" delta="+ str(delta))
|
#print("[DEBUG] cotisation en retard pour l'utilisateur "+ member.dn +" now="+ str(now) +" anniversary="+ str(anniversary) +" delta="+ str(delta))
|
||||||
@ -205,13 +213,17 @@ class CotisationComputes:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
# more than a month late
|
# more than a month late
|
||||||
def is_no_cotisation(member, user_session, residence_dn):
|
def is_no_cotisation(member_dn, user_session, residence_dn, cotisations = None):
|
||||||
if CotisationComputes.is_old_member(member, user_session, residence_dn):
|
if CotisationComputes.is_old_member(member_dn, user_session, residence_dn, cotisations):
|
||||||
return False
|
return False
|
||||||
|
if cotisations is None:
|
||||||
current_year = CotisationComputes.current_year()
|
current_year = CotisationComputes.current_year()
|
||||||
|
#end if
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
|
|
||||||
cotisations = Cotisation.cotisations_of_member(user_session, member.dn, current_year)
|
if cotisations is None:
|
||||||
|
cotisations = Cotisation.cotisations_of_member(user_session, member_dn, current_year)
|
||||||
|
#end if
|
||||||
anniversary = CotisationComputes.anniversary_from_ldap_items(cotisations)
|
anniversary = CotisationComputes.anniversary_from_ldap_items(cotisations)
|
||||||
delta = (now - anniversary)
|
delta = (now - anniversary)
|
||||||
return delta.days > 30
|
return delta.days > 30
|
||||||
@ -226,14 +238,16 @@ class CotisationComputes:
|
|||||||
cotisation_late_members = []
|
cotisation_late_members = []
|
||||||
no_cotisation_members = []
|
no_cotisation_members = []
|
||||||
for member in members:
|
for member in members:
|
||||||
if CotisationComputes.is_old_member(member, user_session, residence_dn):
|
current_year = CotisationComputes.current_year()
|
||||||
|
cotisations = Cotisation.cotisations_of_member(user_session, member.dn, current_year)
|
||||||
|
if CotisationComputes.is_old_member(member.dn, user_session, residence_dn, cotisations):
|
||||||
old_members.append(member)
|
old_members.append(member)
|
||||||
elif CotisationComputes.is_cotisation_paid(member, user_session, residence_dn):
|
elif CotisationComputes.is_cotisation_paid(member.dn, user_session, residence_dn, cotisations):
|
||||||
cotisation_paid_members.append(member)
|
cotisation_paid_members.append(member)
|
||||||
elif CotisationComputes.is_cotisation_late(member, user_session, residence_dn):
|
elif CotisationComputes.is_cotisation_late(member.dn, user_session, residence_dn, cotisations):
|
||||||
cotisation_late_members.append(member)
|
cotisation_late_members.append(member)
|
||||||
#print("[DEBUG] cotisation en retard pour l'utilisateur "+ member.dn)
|
#print("[DEBUG] cotisation en retard pour l'utilisateur "+ member.dn)
|
||||||
elif CotisationComputes.is_no_cotisation(member, user_session, residence_dn):
|
elif CotisationComputes.is_no_cotisation(member.dn, user_session, residence_dn, cotisations):
|
||||||
no_cotisation_members.append(member)
|
no_cotisation_members.append(member)
|
||||||
else:
|
else:
|
||||||
print "DEBUG : member with weird status !"
|
print "DEBUG : member with weird status !"
|
||||||
@ -243,4 +257,45 @@ class CotisationComputes:
|
|||||||
return dict(old_members=old_members, cotisation_paid_members=cotisation_paid_members, cotisation_late_members=cotisation_late_members, no_cotisation_members=no_cotisation_members)
|
return dict(old_members=old_members, cotisation_paid_members=cotisation_paid_members, cotisation_late_members=cotisation_late_members, no_cotisation_members=no_cotisation_members)
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def members_status_from_list_cotisations(user_session, residence_dn, cotisations):
|
||||||
|
members_dict = dict()
|
||||||
|
for cotisation in cotisations:
|
||||||
|
cotisation_dn = cotisation.dn.split(",")
|
||||||
|
member_dn = ""
|
||||||
|
for i in range(3, len(cotisation_dn)):
|
||||||
|
if i != 3:
|
||||||
|
member_dn += ","
|
||||||
|
#end if
|
||||||
|
member_dn += cotisation_dn[i]
|
||||||
|
#end for
|
||||||
|
if not member_dn in members_dict:
|
||||||
|
members_dict[member_dn] = [cotisation]
|
||||||
|
else:
|
||||||
|
members_dict[member_dn].append(cotisation)
|
||||||
|
#end if
|
||||||
|
#end for
|
||||||
|
|
||||||
|
old_members = []
|
||||||
|
cotisation_paid_members = []
|
||||||
|
cotisation_late_members = []
|
||||||
|
no_cotisation_members = []
|
||||||
|
for member_dn, cotisations in members_dict.iteritems():
|
||||||
|
if CotisationComputes.is_old_member(member_dn, user_session, residence_dn, cotisations):
|
||||||
|
old_members.append(member_dn)
|
||||||
|
elif CotisationComputes.is_cotisation_paid(member_dn, user_session, residence_dn, cotisations):
|
||||||
|
cotisation_paid_members.append(member_dn)
|
||||||
|
elif CotisationComputes.is_cotisation_late(member_dn, user_session, residence_dn, cotisations):
|
||||||
|
cotisation_late_members.append(member_dn)
|
||||||
|
#print("[DEBUG] cotisation en retard pour l'utilisateur "+ member.dn)
|
||||||
|
elif CotisationComputes.is_no_cotisation(member_dn, user_session, residence_dn, cotisations):
|
||||||
|
no_cotisation_members.append(member_dn)
|
||||||
|
else:
|
||||||
|
print "DEBUG : member with weird status !"
|
||||||
|
#end if
|
||||||
|
|
||||||
|
#end for
|
||||||
|
return dict(old_members=old_members, cotisation_paid_members=cotisation_paid_members, cotisation_late_members=cotisation_late_members, no_cotisation_members=no_cotisation_members)
|
||||||
|
#end def
|
||||||
|
|
||||||
#end class
|
#end class
|
||||||
|
@ -108,6 +108,33 @@ class Ldap(object):
|
|||||||
return ldap_results
|
return ldap_results
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
|
def get_childs(self, dn, filter = "(objectClass=*)"):
|
||||||
|
results = self.search(dn, filter)
|
||||||
|
tree = [None, dict()]
|
||||||
|
|
||||||
|
for result in results:
|
||||||
|
if result.dn == dn:
|
||||||
|
tree[0] = result
|
||||||
|
else:
|
||||||
|
result_dn = result.dn.replace(dn, "").split(",")
|
||||||
|
tree_c = tree
|
||||||
|
result_dn.reverse()
|
||||||
|
for dn_split in result_dn:
|
||||||
|
if dn_split != "":
|
||||||
|
if not dn_split in tree_c[1]:
|
||||||
|
tree_c[1][dn_split] = [None, dict()]
|
||||||
|
tree_c = tree_c[1][dn_split]
|
||||||
|
else:
|
||||||
|
tree_c = tree_c[1][dn_split]
|
||||||
|
#end if
|
||||||
|
#end if
|
||||||
|
#end for
|
||||||
|
tree_c[0] = result
|
||||||
|
#end if
|
||||||
|
#end for
|
||||||
|
return LdapEntryTree(tree[0], tree[1])
|
||||||
|
#end def
|
||||||
|
|
||||||
""" Recherche le premier resultat sur la base
|
""" Recherche le premier resultat sur la base
|
||||||
appel la methode "search" en interne
|
appel la methode "search" en interne
|
||||||
"""
|
"""
|
||||||
@ -500,3 +527,27 @@ class LdapAttribute(object):
|
|||||||
|
|
||||||
#end class
|
#end class
|
||||||
|
|
||||||
|
class LdapEntryTree(LdapEntry):
|
||||||
|
childs = None
|
||||||
|
val = None
|
||||||
|
|
||||||
|
def __init__(self, val, childs):
|
||||||
|
self.__dict__ = val.__dict__
|
||||||
|
if len(childs) > 0:
|
||||||
|
self.childs = dict()
|
||||||
|
for key,child in childs.iteritems():
|
||||||
|
key = key.split("=")[1]
|
||||||
|
self.childs[key] = LdapEntryTree(child[0], child[1])
|
||||||
|
self.__dict__[key] = self.childs[key]
|
||||||
|
#end for
|
||||||
|
#end if
|
||||||
|
#end def
|
||||||
|
|
||||||
|
def __getattr__(self, name):
|
||||||
|
attr = LdapAttribute(name, [])
|
||||||
|
self.__dict__[name] = attr
|
||||||
|
|
||||||
|
return attr
|
||||||
|
#end def
|
||||||
|
|
||||||
|
#end class
|
||||||
|
@ -419,6 +419,18 @@ class Cotisation:
|
|||||||
return user_session.ldap_bind.search_first(dn, "(uid=" + name + ")")
|
return user_session.ldap_bind.search_first(dn, "(uid=" + name + ")")
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_all_cotisation_by_year(user_session, residence_dn, year):
|
||||||
|
dn = ldap_config.username_base_dn + residence_dn
|
||||||
|
return user_session.ldap_bind.search(dn, "(&(objectClass=auroreCotisation)(x-year=" + str(year) + "))")
|
||||||
|
#end def
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_all_cotisation(user_session, residence_dn):
|
||||||
|
dn = ldap_config.username_base_dn + residence_dn
|
||||||
|
return user_session.ldap_bind.search(dn, "(objectClass=auroreCotisation)")
|
||||||
|
#end def
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all_payment_by_year(user_session, residence_dn, year):
|
def get_all_payment_by_year(user_session, residence_dn, year):
|
||||||
dn = ldap_config.username_base_dn + residence_dn
|
dn = ldap_config.username_base_dn + residence_dn
|
||||||
|
Loading…
Reference in New Issue
Block a user