From 0e2af4db827e5b3d447ef686beadd425c1e5ca62 Mon Sep 17 00:00:00 2001 From: Roven Gabriel Date: Wed, 11 Sep 2013 15:00:19 +0200 Subject: [PATCH] correction de bugs, renforcement de l'inscription --- Brie/brie/controllers/edit.py | 19 +++-- Brie/brie/controllers/members.py | 36 ++++----- Brie/brie/controllers/registration.py | 83 +++++++++++++++++++-- Brie/brie/controllers/search.py | 16 ++-- Brie/brie/lib/ldap_helper.py | 3 + Brie/brie/public/css/common.css | 4 + Brie/brie/templates/registration/error.html | 60 +++++++++++++++ Brie/brie/templates/search/member.html | 18 ++--- 8 files changed, 190 insertions(+), 49 deletions(-) create mode 100644 Brie/brie/templates/registration/error.html diff --git a/Brie/brie/controllers/edit.py b/Brie/brie/controllers/edit.py index 5599c5e..fbf1289 100644 --- a/Brie/brie/controllers/edit.py +++ b/Brie/brie/controllers/edit.py @@ -188,14 +188,23 @@ class MemberModificationController(AuthenticatedRestController): def post(self, residence, member_uid, sn, givenName, mail, comment): residence_dn = Residences.get_dn_by_name(self.user, residence) member = Member.get_by_uid(self.user, residence_dn, member_uid) + + # FIXME + sn = unicode.encode(sn, 'utf-8') + givenName = unicode.encode(givenName, 'utf-8') + comment = unicode.encode(comment, 'utf-8') member.sn.replace(member.sn.first(), sn) member.givenName.replace(member.givenName.first(), givenName) + member.cn.replace(member.cn.first(), givenName + " " + sn) member.mail.replace(member.mail.first(), mail) - member.get("x-comment").replace(member.get("x-comment").first(), comment) + if comment != "": + member.get("x-comment").replace(member.get("x-comment").first(), comment) self.user.ldap_bind.save(member) + + redirect("/edit/member/" + residence + "/" + member_uid) #end def """ Controller de gestion des machines """ @@ -583,7 +592,7 @@ class RoomMoveController(AuthenticatedRestController): """ Gestion des requêtes post sur ce controller """ @expose() - def post(self, residence, member_uid, room_uid, erase = False, go_redirect = True): + def post(self, residence, member_uid, room_uid, erase = True, go_redirect = True): residence_dn = Residences.get_dn_by_name(self.user, residence) # Récupération du membre et de la machine @@ -592,10 +601,10 @@ class RoomMoveController(AuthenticatedRestController): room = Room.get_by_uid(self.user, residence_dn, room_uid) if room is not None: - if room.get("x-memberIn") is not None and room.get('x-memberIn').first() is not None: + member_in = room.get('x-memberIn').first() + if member_in is not None: if erase: - room.delete("x-memberIn") - self.user.ldap_bind.save(room) + self.user.ldap_bind.delete_attr(room.dn, { "x-memberIn" : member_in }) else: raise Exception("chambre de destination non vide") #end if diff --git a/Brie/brie/controllers/members.py b/Brie/brie/controllers/members.py index 58d8ff3..554444b 100644 --- a/Brie/brie/controllers/members.py +++ b/Brie/brie/controllers/members.py @@ -21,37 +21,31 @@ class MembersController(AuthenticatedBaseController): def sort_name(name_items): return sorted(name_items, key=lambda t:t.sn.first()) - @expose("brie.templates.members.index") + @expose("brie.templates.search.member") def index(self, residence_name): - members = list(); - residence_dn = Residences.get_dn_by_name(self.user, residence_name) if residence_dn is None: raise Exception("unknown residence") #end if - for member in Member.get_all(self.user, residence_dn): - members.append(member); + members = Member.get_all(self.user, residence_dn) + members = MembersController.sort_name(members) - rooms = Room.get_rooms(self.user, residence_dn) - if rooms is None: - raise Exception("unable to retrieve rooms") - #end if - rooms = sorted(rooms, key=lambda t:t.uid.first()) + members_rooms = [ + (member, Room.get_by_member_dn(self.user, residence_dn, member.dn)) + for member in members + ] - for m in members: - for r in rooms: - if r.has("x-memberIn"): - if r.get("x-memberIn").first() == m.dn: - m.room = r + # machines = Machine.get_machine_tuples_of_member(self.user, member.dn) + + # groups = Groupes.get_by_user_dn(self.user, residence_dn, member.dn) + return { + "residence" : residence_name, + "user" : self.user, + "members_rooms" : members_rooms + } - return { - "user" : self.user, - "members" : members, - "residence" : residence_name, - "sort_name" : MembersController.sort_name - } #end def # @expose("brie.templates.members.index") diff --git a/Brie/brie/controllers/registration.py b/Brie/brie/controllers/registration.py index 2f01cab..cbaeb77 100644 --- a/Brie/brie/controllers/registration.py +++ b/Brie/brie/controllers/registration.py @@ -22,12 +22,14 @@ import re class RegistrationController(AuthenticatedBaseController): require_group = groups_enum.admin - new_member = None + member_edit_controller = None quick_last_registrations = [] def __init__(self, member_edit_controller): self.new = NewRegistrationController(member_edit_controller) + self.recover = ErrorRecoveryRegistrationController(member_edit_controller) + self.member_edit_controller = member_edit_controller #end def @expose("brie.templates.registration.index") @@ -91,7 +93,30 @@ class RegistrationController(AuthenticatedBaseController): "available_months_prices" : available_months_prices, "extras_available" : extras_available } + #end class + + @expose("brie.templates.registration.error") + def error(self, member_uid): + residence = None + if self.user is not None: + residence = Residences.get_name_by_dn(self.user, self.user.residence_dn) + #end if + + self.member_edit_controller.member.user = self.user + + edit_get_values = self.member_edit_controller.member.get(residence, member_uid) + + + rooms = Room.get_rooms(self.user, self.user.residence_dn) + rooms = sorted(rooms, key=lambda t:t.cn.first()) + + + + return edit_get_values + #end def + + #end class class NewRegistrationController(AuthenticatedRestController): @@ -114,16 +139,64 @@ class NewRegistrationController(AuthenticatedRestController): self.member_edit_controller.cotisation.add.user = self.user member_uid = self.member_edit_controller.add.post(residence, givenName, sn, mail, go_redirect = False) - self.member_edit_controller.machine.add.post(residence, member_uid, first_machine_name, first_machine_mac, go_redirect = False) - self.member_edit_controller.room.move.post(residence, member_uid, room_uid, erase = True, go_redirect = False) - self.member_edit_controller.cotisation.add.post(residence, member_uid, next_end, extra_name, go_redirect = False) - member = Member.get_by_uid(self.user, self.user.residence_dn, member_uid) if member is not None: RegistrationController.quick_last_registrations.append(member) #end if + + self.member_edit_controller.room.move.post(residence, member_uid, room_uid, erase = True, go_redirect = False) + try: + self.member_edit_controller.machine.add.post(residence, member_uid, first_machine_name, first_machine_mac, go_redirect = False) + self.member_edit_controller.cotisation.add.post(residence, member_uid, next_end, extra_name, go_redirect = False) + + except: + redirect("/registration/error/" + member_uid) + redirect("/registration/") #end def #end class + +class ErrorRecoveryRegistrationController(AuthenticatedRestController): + require_group = groups_enum.admin + + member_edit_controller = None + + def __init__(self, member_edit_controller): + self.member_edit_controller = member_edit_controller + + @expose() + def post(self, residence, member_uid, room_uid, + first_machine_name, first_machine_mac, + next_end, extra_name): + member = Member.get_by_uid(self.user, self.user.residence_dn, member_uid) + + if member is None: + raise Exception("Invalid member uid") + + + self.member_edit_controller.add.user = self.user + self.member_edit_controller.machine.add.user = self.user + self.member_edit_controller.room.move.user = self.user + self.member_edit_controller.cotisation.add.user = self.user + + if room_uid != "": + self.member_edit_controller.room.move.post(residence, member_uid, room_uid, erase = True, go_redirect = False) + + try: + if first_machine_mac != "": + self.member_edit_controller.machine.add.post(residence, member_uid, first_machine_name, first_machine_mac, go_redirect = False) + + + if next_end != "": + self.member_edit_controller.cotisation.add.post(residence, member_uid, next_end, extra_name, go_redirect = False) + except: + redirect("/registration/error/" + member_uid) + #end try + + redirect("/registration") + #end def +#end class + + diff --git a/Brie/brie/controllers/search.py b/Brie/brie/controllers/search.py index 52cd1d9..ff5e282 100644 --- a/Brie/brie/controllers/search.py +++ b/Brie/brie/controllers/search.py @@ -24,7 +24,6 @@ class SearchController(AuthenticatedBaseController): """ Affiche les résultats """ @expose("brie.templates.search.member") - @plugins("brie.controllers.search.member") def member(self, residence, name): residence_dn = Residences.get_dn_by_name(self.user, residence) members = Member.get_by_name(self.user, residence_dn, name) @@ -32,8 +31,13 @@ class SearchController(AuthenticatedBaseController): if members is None: return self.error_no_entry() - # room = Room.get_by_member_dn(self.user, residence_dn, member.dn) - + members = MembersController.sort_name(members) + + members_rooms = [ + (member, Room.get_by_member_dn(self.user, residence_dn, member.dn)) + for member in members + ] + # machines = Machine.get_machine_tuples_of_member(self.user, member.dn) # groups = Groupes.get_by_user_dn(self.user, residence_dn, member.dn) @@ -41,11 +45,7 @@ class SearchController(AuthenticatedBaseController): return { "residence" : residence, "user" : self.user, - "member_ldap" : members, - "sort_name" : MembersController.sort_name - # "room_ldap" : room, - # "machines" : machines, - # "groups" : groups + "members_rooms" : members_rooms } #end def diff --git a/Brie/brie/lib/ldap_helper.py b/Brie/brie/lib/ldap_helper.py index 3feb3dc..4fa6f72 100644 --- a/Brie/brie/lib/ldap_helper.py +++ b/Brie/brie/lib/ldap_helper.py @@ -340,6 +340,9 @@ class LdapAttribute(object): return unicode(value) #end for + if default is None: + return None + return unicode(default) #end def diff --git a/Brie/brie/public/css/common.css b/Brie/brie/public/css/common.css index b290c4c..0046e7a 100644 --- a/Brie/brie/public/css/common.css +++ b/Brie/brie/public/css/common.css @@ -47,6 +47,10 @@ a:hover, input[type="button"] margin-left: 20px; } +.seventy_percent { + width: 70%; +} + input[type="submit"] { border: none; diff --git a/Brie/brie/templates/registration/error.html b/Brie/brie/templates/registration/error.html new file mode 100644 index 0000000..0bc7844 --- /dev/null +++ b/Brie/brie/templates/registration/error.html @@ -0,0 +1,60 @@ + + + + + + + + +
+ + +
+ ERREUR MACHINE OU CHAMBRE
${member_ldap.cn.first()}
+
+
+ CHAMBRE +
+ ${room_ldap.cn.first()} + +
+
+ + +
+
+
+ MACHINE +
+
+ ${name} + ${mac} : ${ip} +
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + diff --git a/Brie/brie/templates/search/member.html b/Brie/brie/templates/search/member.html index 32634ad..f5f2fb9 100644 --- a/Brie/brie/templates/search/member.html +++ b/Brie/brie/templates/search/member.html @@ -8,18 +8,16 @@ - +
- - - + + - - - - - - + + + + +
prenomnomchambresmembrechambre
${member.givenName.first()}${member.sn.first()}${member.room.cn.first()}
${member.cn.first()}sdf${room.cn.first()}