hg add pour search module
This commit is contained in:
parent
42fd23caa8
commit
62cdeeebbd
74
Brie/brie/controllers/search.py
Normal file
74
Brie/brie/controllers/search.py
Normal file
@ -0,0 +1,74 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from tg import session
|
||||
from tg.controllers import redirect
|
||||
from tg.decorators import expose, validate
|
||||
from brie.config import ldap_config
|
||||
from brie.lib.ldap_helper import *
|
||||
from brie.lib.aurore_helper import *
|
||||
from brie.lib.plugins import *
|
||||
from brie.model.ldap import *
|
||||
|
||||
from brie.controllers import auth
|
||||
from brie.controllers.auth import AuthenticatedBaseController, AuthenticatedRestController
|
||||
from brie.controllers.members import MembersController
|
||||
|
||||
from operator import itemgetter
|
||||
|
||||
""" Controller de recherche """
|
||||
class SearchController(AuthenticatedBaseController):
|
||||
|
||||
@expose("brie.templates.search.error")
|
||||
def error_no_entry(self):
|
||||
return { "error" : "Entrée non existante" }
|
||||
|
||||
""" 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)
|
||||
|
||||
if members is None:
|
||||
return self.error_no_entry()
|
||||
|
||||
# room = Room.get_by_member_dn(self.user, residence_dn, member.dn)
|
||||
|
||||
# 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,
|
||||
"user" : self.user,
|
||||
"member_ldap" : members,
|
||||
"sort_name" : MembersController.sort_name
|
||||
# "room_ldap" : room,
|
||||
# "machines" : machines,
|
||||
# "groups" : groups
|
||||
}
|
||||
#end def
|
||||
|
||||
@expose("brie.templates.show.room")
|
||||
def room(self, residence, room_id):
|
||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||
|
||||
room = Room.get_by_uid(self.user, residence_dn, room_id)
|
||||
|
||||
if room is None:
|
||||
return self.error_no_entry()
|
||||
|
||||
member = None
|
||||
if room.has("x-memberIn"):
|
||||
member = Member.get_by_dn(self.user, room.get("x-memberIn").first())
|
||||
|
||||
return {
|
||||
"residence" : residence,
|
||||
"user" : self.user,
|
||||
"room_ldap" : room,
|
||||
"member_ldap" : member
|
||||
}
|
||||
#end def
|
||||
|
||||
#end class
|
||||
|
0
Brie/brie/templates/search/__init__.py
Normal file
0
Brie/brie/templates/search/__init__.py
Normal file
6
Brie/brie/templates/search/error.html
Normal file
6
Brie/brie/templates/search/error.html
Normal file
@ -0,0 +1,6 @@
|
||||
<html
|
||||
xmlns:py="http://genshi.edgewall.org/"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
||||
>
|
||||
<span class="section_name">${error}</span>
|
||||
</html>
|
25
Brie/brie/templates/search/member.html
Normal file
25
Brie/brie/templates/search/member.html
Normal file
@ -0,0 +1,25 @@
|
||||
<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/rooms.css" />
|
||||
</head>
|
||||
<body>
|
||||
<table>
|
||||
<tr>
|
||||
<th>prenom</th>
|
||||
<th>nom</th>
|
||||
<th>chambres</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">
|
||||
<td py:when="None"></td>
|
||||
<td py:otherwise=""><a href="/show/room/${residence}/${member.room.cn.first()}">${member.room.cn.first()}</a></td>
|
||||
</py:choose>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user