diff --git a/Brie/brie/controllers/edit.py b/Brie/brie/controllers/edit.py index 6d07b05..74dbd16 100644 --- a/Brie/brie/controllers/edit.py +++ b/Brie/brie/controllers/edit.py @@ -75,9 +75,27 @@ class MemberAddController(AuthenticatedRestController): phone = ' ' #end if - member = Member.entry_attr(member_uid, prenom, nom, mail, phone, -1) - residence_dn = Residences.get_dn_by_name(self.user, residence) + + # On modifie silencieusement le nom de la machine si il existe déjà + def try_name(name, number): + actual_name = name + if number > 0: + actual_name = name + str(number) + #end if + + member = Member.get_by_uid(self.user, residence_dn, actual_name) + if member is not None: + return try_name(name, number + 1) + else: + return actual_name + #end if + #endif + + member_uid = try_name(member_uid, 0) + + + member = Member.entry_attr(member_uid, prenom, nom, mail, phone, -1) now = datetime.now() year = 0 @@ -864,9 +882,10 @@ class RoomMoveController(AuthenticatedRestController): else: old_room = Room.get_by_member_dn(self.user, residence_dn, member.dn) memberIn_attribute = Room.memberIn_attr(str(member.dn)) - self.user.ldap_bind.delete_attr(old_room.dn, memberIn_attribute) - - print("[LOG] retrait de chambre pour le member "+member_uid+" from "+ old_room.uid.first() +" by "+self.user.attrs.dn) + if old_room is not None: + self.user.ldap_bind.delete_attr(old_room.dn, memberIn_attribute) + print("[LOG] retrait de chambre pour le member "+member_uid+" from "+ old_room.uid.first() +" by "+self.user.attrs.dn) + #end if #end if #self.user.ldap_bind.delete_entry_subtree(machine.dn) diff --git a/Brie/brie/controllers/registration.py b/Brie/brie/controllers/registration.py index ac61d66..f884230 100644 --- a/Brie/brie/controllers/registration.py +++ b/Brie/brie/controllers/registration.py @@ -24,7 +24,7 @@ class RegistrationController(AuthenticatedBaseController): member_edit_controller = None - quick_last_registrations = [] + quick_last_registrations = dict() def __init__(self, member_edit_controller): self.new = NewRegistrationController(member_edit_controller) @@ -91,11 +91,17 @@ class RegistrationController(AuthenticatedBaseController): extras_available = Cotisation.get_all_extras(self.user, self.user.residence_dn) + if residence in RegistrationController.quick_last_registrations: + quick_last = RegistrationController.quick_last_registrations[residence] + else: + quick_last = [] + #end if + return { "user" : self.user, "residence" : residence, "rooms" : rooms, - "quick_last" : RegistrationController.quick_last_registrations, + "quick_last" : quick_last, "available_months_prices" : available_months_prices, "extras_available" : extras_available } @@ -152,10 +158,15 @@ class NewRegistrationController(AuthenticatedRestController): member = Member.get_by_uid(self.user, self.user.residence_dn, member_uid) if member is not None: - RegistrationController.quick_last_registrations.append(member) + if residence not in RegistrationController.quick_last_registrations: + RegistrationController.quick_last_registrations[residence] = [] + #end if + RegistrationController.quick_last_registrations[residence].append(member) #end if - self.member_edit_controller.room.move.post(residence, member_uid, room_uid, erase = True, go_redirect = False) + if room_uid != "": + self.member_edit_controller.room.move.post(residence, member_uid, room_uid, erase = True, go_redirect = False) + #end if 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)