correction de bugs, renforcement de l'inscription

This commit is contained in:
Roven Gabriel 2013-09-11 15:00:19 +02:00
parent f03b3e0104
commit 0e2af4db82
8 changed files with 190 additions and 49 deletions

View File

@ -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

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -340,6 +340,9 @@ class LdapAttribute(object):
return unicode(value)
#end for
if default is None:
return None
return unicode(default)
#end def

View File

@ -47,6 +47,10 @@ a:hover, input[type="button"]
margin-left: 20px;
}
.seventy_percent {
width: 70%;
}
input[type="submit"]
{
border: none;

View File

@ -0,0 +1,60 @@
<html
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude">
<head>
<link type="text/css" rel="Stylesheet" href="/css/common.css" />
<link type="text/css" rel="Stylesheet" href="/css/show.css" />
<xi:include href="common-css-header.html" />
</head>
<body>
<xi:include href="navbar.html" />
<form action="/registration/recover" method="POST">
<input type="hidden" name="residence" value="${residence}" />
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}" />
<div class="section">
<span class="section_name show_section_name">ERREUR MACHINE OU CHAMBRE <br />${member_ldap.cn.first()}</span>
</div>
<div class="section">
<span class="section_name show_section_name">CHAMBRE</span>
<div py:if="room_ldap is not None" class="item_name">
<span>${room_ldap.cn.first()}</span>
<input type="hidden" name="room_uid" value="" />
</div>
<div py:if="room_ldap is None">
<span class="item_name"></span>
<select name="room_uid">
<option value="">&lt;vide&gt;</option>
<py:for each="target_room in rooms">
<option value="${target_room.uid.first()}" >${target_room.cn.first()}</option>
</py:for>
</select>
</div>
</div>
<div class="section">
<span class="section_name show_section_name">MACHINE</span>
<div>
<div py:for="name, mac, ip in machines">
<span class="item_name">${name}</span>
<span>${mac} : ${ip}</span>
</div>
<div>
<input type="text" name="first_machine_name" placeholder="nom de la machine" class="item_name" />
<input type="text" name="first_machine_mac" placeholder="adresse mac" />
</div>
</div>
</div>
<div class="section">
<xi:include href="../show/cotisation.html" />
<xi:include href="../edit/cotisation-edit.html" />
</div>
<div class="section">
<div>
<div>
<span class="item_name"></span>
<input type="submit" value="Soumettre" />
</div>
</div>
</div>
</form>
</body>
</html>

View File

@ -8,18 +8,16 @@
</head>
<body>
<xi:include href="navbar.html" />
<table>
<table class="table table-hover">
<tr>
<th>prenom</th>
<th>nom</th>
<th>chambres</th>
<th>membre</th>
<th>chambre</th>
</tr>
<tr py:for="member in sort_name(member_ldap)">
<td><a href="/show/member/${residence}/${member.uid.first()}">${member.givenName.first()}</a></td>
<td><a href="/show/member/${residence}/${member.uid.first()}">${member.sn.first()}</a></td>
<py:choose test="member.room.first()">
<td py:when="None"></td>
<td py:otherwise=""><a href="/show/room/${residence}/${member.room.cn.first()}">${member.room.cn.first()}</a></td>
<tr py:for="member, room in members_rooms">
<td><a href="/show/member/${residence}/${member.uid.first()}">${member.cn.first()}</a></td>
<py:choose test="room">
<td py:when="None">sdf</td>
<td py:otherwise=""><a href="/show/room/${residence}/${room.cn.first()}">${room.cn.first()}</a></td>
</py:choose>
</tr>
</table>