debut du travail sur l'ajout de membres
This commit is contained in:
commit
6f3a256da4
9
BSD_LICENSE.txt
Normal file
9
BSD_LICENSE.txt
Normal file
@ -0,0 +1,9 @@
|
||||
Copyright (c) 2013, Roven Gabriel
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -6,6 +6,7 @@ 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 *
|
||||
|
||||
@ -23,7 +24,7 @@ class MembersController(AuthenticatedBaseController):
|
||||
self.add = MembersAddController()
|
||||
|
||||
def sort_name(self, name_items):
|
||||
return sorted(name_items, key=lambda t:t[0].cn.first())
|
||||
return sorted(name_items, key=lambda t:t.sn.first())
|
||||
|
||||
@expose("brie.templates.members.index")
|
||||
def index(self, residence_name):
|
||||
@ -52,7 +53,8 @@ class MembersController(AuthenticatedBaseController):
|
||||
|
||||
return {
|
||||
"members" : members,
|
||||
"residence" : residence_name
|
||||
"residence" : residence_name,
|
||||
"sort_name" : self.sort_name
|
||||
}
|
||||
#end def
|
||||
|
||||
@ -71,7 +73,7 @@ class MembersAddController(AuthenticatedRestController):
|
||||
@expose()
|
||||
def post(self, residence, prenom, nom, mail):
|
||||
|
||||
member_uid = prenom.lower() + "." + nom.lower()
|
||||
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)
|
||||
|
42
Brie/brie/lib/name_translation_helpers.py
Normal file
42
Brie/brie/lib/name_translation_helpers.py
Normal file
@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import unicodedata
|
||||
|
||||
|
||||
class Translations(object):
|
||||
|
||||
@staticmethod
|
||||
def to_uid(name, surname):
|
||||
clean_name = Translations.strip_accents(name.replace(" ", "")).lower()[:15]
|
||||
clean_surname = Translations.strip_accents(surname.replace(" ", "")).lower()[:15]
|
||||
|
||||
return clean_name + "." + clean_surname
|
||||
#end def
|
||||
|
||||
@staticmethod
|
||||
def floor_of_room(room):
|
||||
return room / 100
|
||||
#end def
|
||||
|
||||
@staticmethod
|
||||
def area_of_room(room):
|
||||
if Translations.floor_of_room(room) == 5:
|
||||
return "crous"
|
||||
|
||||
floor_number = room % 100
|
||||
|
||||
if floor_number <= 33:
|
||||
return "sud"
|
||||
else:
|
||||
return "nord"
|
||||
#end if
|
||||
#end def
|
||||
|
||||
#end class
|
||||
|
||||
|
||||
|
||||
# http://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-in-a-python-unicode-string
|
||||
@staticmethod
|
||||
def strip_accents(s):
|
||||
return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn'))
|
||||
#end def
|
@ -49,7 +49,7 @@
|
||||
<th>chambres</th>
|
||||
</tr>
|
||||
|
||||
<tr py:for="member in members">
|
||||
<tr py:for="member in sort_name(members)">
|
||||
<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">
|
||||
|
@ -31,7 +31,7 @@
|
||||
</div>
|
||||
-->
|
||||
<div class="area section">
|
||||
<span class="section_name">PREVIEW</span> <a href="/members/index/${residence}">Membres</a>
|
||||
<span class="section_name">PREVIEW</span>
|
||||
<div py:if="defined('preview')">
|
||||
<py:with vars="member_ldap, room_preview = preview">
|
||||
<div class="room_number">
|
||||
|
Loading…
Reference in New Issue
Block a user