debut travail ajout de members

This commit is contained in:
Romain Beuque 2013-05-21 11:23:07 +02:00
parent be6f4dd8d2
commit c5b1f779a5
4 changed files with 132 additions and 0 deletions

View File

@ -0,0 +1,79 @@
from tg import session
from tg.controllers import redirect
from tg.decorators import expose, validate
from brie.lib.base import BaseController
from brie.config import ldap_config
from brie.config import groups_enum
from brie.lib.ldap_helper import *
from brie.lib.aurore_helper import *
from brie.model.ldap import *
from brie.controllers import auth
from brie.controllers.auth import AuthenticatedBaseController, AuthenticatedRestController
class MembersController(AuthenticatedBaseController):
require_group = groups_enum.admin
add = None
def __init__(self):
self.add = MembersAddController()
def sort_name(self, name_items):
return sorted(name_items, key=lambda t:t[0].cn.first())
@expose("brie.templates.members.index")
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);
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.cn.first())
for m in members:
for r in rooms:
if r.has("x-memberIn"):
if r.get("x-memberIn").first() == m.dn:
m.room = r
return {
"members" : members,
"residence" : residence_name
}
#end def
class MembersAddController(AuthenticatedRestController):
require_group = groups_enum.admin
""" Fonction de gestion de requete post sur le controller d'ajout """
@expose()
def post(self, residence, prenom, nom, mail):
member_uid = prenom.lower() + "." + nom.lower()
member = Member.entry_attr(member_uid, prenom, nom, mail, 1)
residence_dn = Residences.get_dn_by_name(self.user, residence)
member_dn = "uid=" + member_uid + "," + ldap_config.username_base_dn + residence_dn
self.user.ldap_bind.add_entry(member_dn, member)
#preview = member, room
#index_result["preview"] = preview
redirect("/edit/member/" + residence + "/" + member_uid)
#end def
#end class

View File

@ -14,6 +14,7 @@ from brie import model
import brie.controllers.auth as auth_handler
from brie.controllers.auth import AuthRestController
from brie.controllers.rooms import RoomsController
from brie.controllers.members import MembersController
from brie.controllers.show import ShowController
from brie.controllers.edit import EditController
from brie.controllers.administration import AdministrationController
@ -41,6 +42,7 @@ class RootController(BaseController):
auth = AuthRestController()
rooms = RoomsController()
members = MembersController()
show = ShowController()
edit = EditController(show)
administration = AdministrationController()

View File

View File

@ -0,0 +1,51 @@
<html
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
>
<head>
<link rel="stylesheet" type="text/css" href="/css/rooms.css" />
<link rel="stylesheet" type="text/css" href="/css/common.css" />
</head>
<!--
<div class="rooms_legend">
<py:def function="display_stat(name)">
<div class="room_number ${name}">${"%03d" % stats[name]}</div>
</py:def>
<div>
${display_stat("ok_color")}
<span>ordinateurs connectés</span>
</div>
<div>
${display_stat("non_certif_color")}
<span>certifs manquants</span>
</div>
<div>
${display_stat("non_paye_color")}
<span>fins de connexions passées</span>
</div>
<div>
${display_stat("vide_color")}
<span>chambres vides</span>
</div>
</div>
-->
<div class="area section">
<span class="section_name">PREVIEW</span>
</div>
<div>
<form method="post" action="/members/add/">
<input type="text" placeholder="prenom" name="prenom" /><br />
<input type="text" placeholder="nom" name="nom" /><br />
<input type="email" placeholder="e-mail" name="mail" />
<input type="hidden" name="residence" value="${residence}" />
<input type="submit" value="GO!" />
</form>
</div>
<div py:for="member in members" class="area section">
<div>
<span>${member.cn.first()}</span>
<span py:if="member.room">${member.room.cn.first()}</span>
</div>
</div>
</html>