ajout page inscription, adaptation des fonctions d'édition pour réutilisation
This commit is contained in:
parent
28e4c456bf
commit
3bb7f266ba
@ -9,6 +9,7 @@ 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.lib.name_translation_helpers import Translations
|
||||
|
||||
from brie.controllers import auth
|
||||
from brie.controllers.auth import AuthenticatedBaseController, AuthenticatedRestController
|
||||
@ -39,12 +40,15 @@ class EditController(AuthenticatedBaseController):
|
||||
|
||||
member = None
|
||||
|
||||
add = None
|
||||
|
||||
def __init__(self, new_show):
|
||||
self.show = new_show
|
||||
self.wifi = WifiRestController(new_show)
|
||||
self.machine = MachineController()
|
||||
self.room = RoomController(new_show)
|
||||
self.member = MemberModificationController()
|
||||
self.add = MemberAddController()
|
||||
|
||||
|
||||
""" Affiche les détails éditables de la chambre """
|
||||
@ -55,6 +59,42 @@ class EditController(AuthenticatedBaseController):
|
||||
|
||||
#end class
|
||||
|
||||
class MemberAddController(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, go_redirect = True):
|
||||
|
||||
member_uid = Translations.to_uid(prenom, nom)
|
||||
member = Member.entry_attr(member_uid, prenom, nom, mail, -1)
|
||||
|
||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||
|
||||
now = datetime.now()
|
||||
year = 0
|
||||
|
||||
if now.month >= 8:
|
||||
year = now.year
|
||||
else:
|
||||
year = now.year - 1
|
||||
#endif
|
||||
|
||||
member_dn = "uid=" + member_uid + ",ou=" + str(year) + "," + ldap_config.username_base_dn + residence_dn
|
||||
self.user.ldap_bind.add_entry(member_dn, member)
|
||||
|
||||
|
||||
#preview = member, room
|
||||
#index_result["preview"] = preview
|
||||
|
||||
if go_redirect:
|
||||
redirect("/edit/member/" + residence + "/" + member_uid)
|
||||
else:
|
||||
return member_uid
|
||||
#end if
|
||||
#end def
|
||||
#end class
|
||||
|
||||
class MemberModificationController(AuthenticatedRestController):
|
||||
require_group = groups_enum.admin
|
||||
|
||||
@ -132,7 +172,7 @@ class MachineAddController(AuthenticatedRestController):
|
||||
|
||||
""" Fonction de gestion de requete post sur le controller d'ajout """
|
||||
@expose()
|
||||
def post(self, residence, member_uid, name, mac):
|
||||
def post(self, residence, member_uid, name, mac, go_redirect = True):
|
||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||
|
||||
#Vérification que l'adresse mac soit correcte
|
||||
@ -176,12 +216,25 @@ class MachineAddController(AuthenticatedRestController):
|
||||
|
||||
# Vérification que le nom de machine n'existe pas déjà
|
||||
# Note : on cherche sur toute la résidence (residence_dn)
|
||||
machine = Machine.get_dns_by_name(self.user, residence_dn, name)
|
||||
if machine is not None:
|
||||
#TODO : gérer l'exception
|
||||
raise Exception("dns name already exist")
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
machine = Machine.get_dns_by_name(self.user, residence_dn, actual_name)
|
||||
if machine is not None:
|
||||
return try_name(name, number + 1)
|
||||
else:
|
||||
return actual_name
|
||||
#end if
|
||||
#endif
|
||||
|
||||
name = try_name(name, 0)
|
||||
|
||||
# Génération de l'id de la machine et recherche d'une ip libre
|
||||
ip = IpReservation.get_first_free(self.user, residence_dn)
|
||||
|
||||
@ -219,8 +272,9 @@ class MachineAddController(AuthenticatedRestController):
|
||||
self.user.ldap_bind.add_entry(dns_dn, machine_dns)
|
||||
|
||||
|
||||
|
||||
redirect("/edit/member/" + residence + "/" + member_uid)
|
||||
if go_redirect:
|
||||
redirect("/edit/member/" + residence + "/" + member_uid)
|
||||
#end if
|
||||
#end def
|
||||
#end class
|
||||
|
||||
@ -345,7 +399,7 @@ class RoomMoveController(AuthenticatedRestController):
|
||||
|
||||
""" Gestion des requêtes post sur ce controller """
|
||||
@expose()
|
||||
def post(self, residence, member_uid, room_uid):
|
||||
def post(self, residence, member_uid, room_uid, erase = False, go_redirect = True):
|
||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||
|
||||
# Récupération du membre et de la machine
|
||||
@ -353,18 +407,21 @@ class RoomMoveController(AuthenticatedRestController):
|
||||
member = Member.get_by_uid(self.user, residence_dn, member_uid)
|
||||
room = Room.get_by_uid(self.user, residence_dn, room_uid)
|
||||
|
||||
# Si la machine existe effectivement, on la supprime
|
||||
if room is not None:
|
||||
if room.get("x-memberIn") is not None and room.get('x-memberIn').first() != 'None':
|
||||
raise Exception("chambre de destination non vide")
|
||||
#TODO passer sur une page d'erreur au lieu d'une exception
|
||||
else:
|
||||
old_room = Room.get_by_member_dn(self.user, residence_dn, member.dn)
|
||||
memberIn_attribute = Room.memberIn_attr(str(member.dn))
|
||||
if old_room is not None:
|
||||
self.user.ldap_bind.delete_attr(old_room.dn, memberIn_attribute)
|
||||
if room.get("x-memberIn") is not None and room.get('x-memberIn').first() is not None:
|
||||
if erase:
|
||||
room.delete("x-memberIn")
|
||||
self.user.ldap_bind.save(room)
|
||||
else:
|
||||
raise Exception("chambre de destination non vide")
|
||||
#end if
|
||||
self.user.ldap_bind.add_attr(room.dn, memberIn_attribute)
|
||||
#end if
|
||||
old_room = Room.get_by_member_dn(self.user, residence_dn, member.dn)
|
||||
memberIn_attribute = Room.memberIn_attr(str(member.dn))
|
||||
if old_room is not None:
|
||||
self.user.ldap_bind.delete_attr(old_room.dn, memberIn_attribute)
|
||||
#end if
|
||||
self.user.ldap_bind.add_attr(room.dn, memberIn_attribute)
|
||||
#end if
|
||||
else:
|
||||
old_room = Room.get_by_member_dn(self.user, residence_dn, member.dn)
|
||||
@ -378,8 +435,10 @@ class RoomMoveController(AuthenticatedRestController):
|
||||
#self.user.ldap_bind.delete_attr(ip.dn, taken_attribute)
|
||||
#end if
|
||||
|
||||
# On redirige sur la page d'édition du membre
|
||||
redirect("/edit/member/" + residence + "/" + member_uid)
|
||||
if go_redirect:
|
||||
# On redirige sur la page d'édition du membre
|
||||
redirect("/edit/member/" + residence + "/" + member_uid)
|
||||
#end if
|
||||
#end def
|
||||
#end def
|
||||
|
||||
|
@ -6,7 +6,6 @@ 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.name_translation_helpers import Translations
|
||||
from brie.lib.aurore_helper import *
|
||||
from brie.model.ldap import *
|
||||
|
||||
@ -18,10 +17,6 @@ from brie.controllers.auth import AuthenticatedBaseController, AuthenticatedRest
|
||||
class MembersController(AuthenticatedBaseController):
|
||||
require_group = groups_enum.admin
|
||||
|
||||
add = None
|
||||
|
||||
def __init__(self):
|
||||
self.add = MembersAddController()
|
||||
@staticmethod
|
||||
def sort_name(name_items):
|
||||
return sorted(name_items, key=lambda t:t.sn.first())
|
||||
@ -67,34 +62,3 @@ class MembersController(AuthenticatedBaseController):
|
||||
|
||||
|
||||
|
||||
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 = Translations.to_uid(prenom, nom)
|
||||
member = Member.entry_attr(member_uid, prenom, nom, mail, -1)
|
||||
|
||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||
|
||||
now = datetime.datetime.now()
|
||||
year = 0
|
||||
|
||||
if now.month >= 8:
|
||||
year = now.year
|
||||
else:
|
||||
year = now.year - 1
|
||||
#endif
|
||||
|
||||
member_dn = "uid=" + member_uid + ",ou=" + str(year) + "," + 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
|
||||
|
81
Brie/brie/controllers/registration.py
Normal file
81
Brie/brie/controllers/registration.py
Normal file
@ -0,0 +1,81 @@
|
||||
# -*- 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.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
|
||||
|
||||
from operator import itemgetter
|
||||
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
import re
|
||||
|
||||
class RegistrationController(AuthenticatedBaseController):
|
||||
require_group = groups_enum.admin
|
||||
|
||||
new_member = None
|
||||
|
||||
quick_last_registrations = []
|
||||
|
||||
def __init__(self, member_edit_controller):
|
||||
self.new = NewRegistrationController(member_edit_controller)
|
||||
#end def
|
||||
|
||||
@expose("brie.templates.registration.index")
|
||||
def index(self):
|
||||
residence = None
|
||||
if self.user is not None:
|
||||
residence = Residences.get_name_by_dn(self.user, self.user.residence_dn)
|
||||
#end if
|
||||
|
||||
rooms = Room.get_rooms(self.user, self.user.residence_dn)
|
||||
rooms = sorted(rooms, key=lambda t:t.cn.first())
|
||||
|
||||
return {
|
||||
"user" : self.user,
|
||||
"residence" : residence,
|
||||
"rooms" : rooms,
|
||||
"quick_last" : RegistrationController.quick_last_registrations
|
||||
}
|
||||
|
||||
#end class
|
||||
|
||||
class NewRegistrationController(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, sn, givenName, mail,
|
||||
room_uid, first_machine_name, first_machine_mac
|
||||
):
|
||||
# Initialisation des Users des Controllers Existant appellés
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
redirect("/registration/")
|
||||
#end def
|
||||
#end class
|
@ -20,6 +20,7 @@ from brie.controllers.search import SearchController
|
||||
from brie.controllers.edit import EditController
|
||||
from brie.controllers.administration import AdministrationController
|
||||
from brie.controllers.error import ErrorController
|
||||
from brie.controllers.registration import RegistrationController
|
||||
|
||||
|
||||
__all__ = ['RootController']
|
||||
@ -49,6 +50,7 @@ class RootController(BaseController):
|
||||
administration = AdministrationController()
|
||||
error = ErrorController()
|
||||
search = SearchController()
|
||||
registration = RegistrationController(edit)
|
||||
|
||||
@expose('brie.templates.index')
|
||||
def index(self):
|
||||
|
@ -12,29 +12,30 @@
|
||||
${edit_banner()}
|
||||
${back_show("member", member_ldap.uid.first())}
|
||||
<div py:choose="member_ldap">
|
||||
<span class="section_name" py:when="None">Entrée inexistante</span>
|
||||
<span class="section_name show_section_name" py:when="None">Entrée inexistante</span>
|
||||
<div py:otherwise="">${member_view(member_ldap)}</div>
|
||||
</div>
|
||||
<div py:choose="room_ldap">
|
||||
<div class="section_name" py:when="None">Pas de chambre associée
|
||||
<div py:if="rooms is not None">
|
||||
<form method="post" action="/edit/room/move">
|
||||
<span class="item_name">Changer de chambre</span>
|
||||
<select name="room_uid">
|
||||
<option value=""><vide></option>
|
||||
<py:for each="target_room in rooms">
|
||||
<option value="${target_room.uid.first()}">${target_room.cn.first()}</option>
|
||||
</py:for>
|
||||
</select>
|
||||
<input type="hidden" name="residence" value="${residence}"/>
|
||||
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}"/>
|
||||
<span>
|
||||
<input type="submit" class="button" value="Envoyer!" />
|
||||
</span>
|
||||
</form>
|
||||
</div>
|
||||
<div class="section" py:when="None">
|
||||
<div class="section_name show_section_name">PAS DE CHAMBRE</div>
|
||||
</div>
|
||||
<div py:otherwise="">${room_view(room_ldap, rooms, member_ldap)}</div>
|
||||
<div class="section">
|
||||
<form method="post" action="/edit/room/move">
|
||||
<span class="item_name">Changer de chambre</span>
|
||||
<select name="room_uid">
|
||||
<option value=""><vide></option>
|
||||
<py:for each="target_room in rooms">
|
||||
<option value="${target_room.uid.first()}">${target_room.cn.first()}</option>
|
||||
</py:for>
|
||||
</select>
|
||||
<input type="hidden" name="residence" value="${residence}"/>
|
||||
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}"/>
|
||||
<span>
|
||||
<input type="submit" class="button" value="Envoyer" />
|
||||
</span>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -74,6 +74,7 @@
|
||||
<a href="/show/member/${residence}/${member_in.uid.first()}">${member_in.cn.first()}</a>
|
||||
</span>
|
||||
</div>-->
|
||||
<!--
|
||||
<div py:if="rooms is not None">
|
||||
<form method="post" action="/edit/room/move">
|
||||
<span class="item_name">Changer de chambre</span>
|
||||
@ -92,7 +93,7 @@
|
||||
<input type="submit" class="button" value="Envoyer!" />
|
||||
</span>
|
||||
</form>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
</py:def>
|
||||
|
@ -9,7 +9,7 @@
|
||||
<a href="${tg.url('/auth/login')}">Connexion</a>
|
||||
</div>
|
||||
<div py:otherwise="">
|
||||
<span>${user.attrs.cn.first()}</span>
|
||||
<span>${user.attrs.cn.first()}</span> - <span>${residence}</span>
|
||||
<a href="${tg.url('/auth/logout')}">Deconnexion</a>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -12,6 +12,7 @@
|
||||
<ul class="nav">
|
||||
<li py:if="user.groups.admin"><a href="/rooms/index/${residence}">CHAMBRES</a></li>
|
||||
<li py:if="user.groups.admin"><a href="/members/index/${residence}">MEMBRES</a></li>
|
||||
<li py:if="user.groups.admin"><a href="/registration/">INSCRIPTION</a></li>
|
||||
<li py:if="user.groups.responsablereseau"><a href="/administration/">ADMINISTRATION</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
0
Brie/brie/templates/registration/__init__.py
Normal file
0
Brie/brie/templates/registration/__init__.py
Normal file
77
Brie/brie/templates/registration/index.html
Normal file
77
Brie/brie/templates/registration/index.html
Normal file
@ -0,0 +1,77 @@
|
||||
<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/new" method="POST">
|
||||
<input type="hidden" name="residence" value="${residence}" />
|
||||
<div class="section">
|
||||
<span class="section_name show_section_name">INSCRIPTION MEMBRE</span>
|
||||
<div>
|
||||
<div>
|
||||
<span class="item_name">Prénom</span>
|
||||
<input type="text" name="givenName" value="" />
|
||||
</div>
|
||||
<div>
|
||||
<span class="item_name">Nom</span>
|
||||
<input type="text" name="sn" value="" />
|
||||
</div>
|
||||
<div>
|
||||
<span class="item_name">E-mail</span>
|
||||
<input type="text" name="mail" value="" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section_name show_section_name">CHAMBRE</span>
|
||||
<div>
|
||||
<span class="item_name"></span>
|
||||
<select name="room_uid">
|
||||
<option value=""><vide></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>
|
||||
<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">
|
||||
<span class="section_name show_section_name">COTISATION</span>
|
||||
<div>
|
||||
<div>
|
||||
<span class="item_name">Mois fin</span>
|
||||
<span>TODO</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div>
|
||||
<div>
|
||||
<span class="item_name"></span>
|
||||
<input type="submit" value="Soumettre" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="section">
|
||||
<span class="section_name show_section_name">QUICK PICK LAST</span>
|
||||
<div py:for="member_ldap in quick_last">
|
||||
<div class="item_name"></div>
|
||||
<span><a href="/show/member/${residence}/${member_ldap.uid.first()}">${member_ldap.cn.first()}</a></span>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -11,11 +11,11 @@
|
||||
<xi:include href="navbar.html" />
|
||||
${back_rooms(room_ldap)}
|
||||
<div py:choose="member_ldap">
|
||||
<span class="section_name" py:when="None">Entrée inexistante</span>
|
||||
<span class="section_name show_section_name" py:when="None">Entrée inexistante</span>
|
||||
<div py:otherwise="">${member_view(member_ldap)}</div>
|
||||
</div>
|
||||
<div py:choose="room_ldap">
|
||||
<span class="section_name" py:when="None">Pas de chambre associée</span>
|
||||
<span class="section_name show_section_name" py:when="None">PAS DE CHAMBRE</span>
|
||||
<div py:otherwise="">${room_view(room_ldap)}</div>
|
||||
</div>
|
||||
<xi:include href="plugins.html" />
|
||||
|
Loading…
Reference in New Issue
Block a user