This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
glasnost/shared/common/PeopleCommon.py

387 lines
11 KiB
Python

# -*- coding: iso-8859-15 -*-
# Glasnost
# By: Odile Bénassy <obenassy@entrouvert.com>
# Romain Chantereau <rchantereau@entrouvert.com>
# Nicolas Clapiès <nclapies@easter-eggs.org>
# Pierre-Antoine Dejace <padejace@entrouvert.be>
# Thierry Dulieu <tdulieu@easter-eggs.com>
# Florent Monnier <monnier@codelutin.com>
# Cédric Musso <cmusso@easter-eggs.org>
# Frédéric Péters <fpeters@entrouvert.be>
# Benjamin Poussin <poussin@codelutin.com>
# Emmanuel Raviart <eraviart@entrouvert.com>
# Sébastien Régnier <regnier@codelutin.com>
# Emmanuel Saracco <esaracco@easter-eggs.com>
#
# Copyright (C) 2000, 2001 Easter-eggs & Emmanuel Raviart
# Copyright (C) 2002 Odile Bénassy, Code Lutin, Thierry Dulieu, Easter-eggs,
# Entr'ouvert, Frédéric Péters, Benjamin Poussin, Emmanuel Raviart,
# Emmanuel Saracco & Théridion
# Copyright (C) 2003 Odile Bénassy, Romain Chantereau, Nicolas Clapiès,
# Code Lutin, Pierre-Antoine Dejace, Thierry Dulieu, Easter-eggs,
# Entr'ouvert, Florent Monnier, Cédric Musso, Ouvaton, Frédéric Péters,
# Benjamin Poussin, Rodolphe Quiédeville, Emmanuel Raviart, Sébastien
# Régnier, Emmanuel Saracco, Théridion & Vecam
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
__doc__ = """Glasnost People Common Models"""
__version__ = '$Revision$'[11:-2]
from ObjectsCommon import AdminCommon, ObjectCommon, ObjectsCommonMixin
class AdminPeopleCommon(AdminCommon):
defaultGroupId = None
defaultGroupId_kind_balloonHelp = N_(
'Select the group new users will be automatically added to.')
defaultGroupId_kind_serverRoles = ['groups']
defaultGroupId_kindName = 'Id'
serverRole = 'people'
def getOrderedLayoutSlotNames(self, parentSlot = None):
slotNames = AdminCommon.getOrderedLayoutSlotNames(
self, parentSlot = parentSlot)
slotNames += ['defaultGroupId']
return slotNames
class PersonCommon(ObjectCommon):
"""Person super class used to be inherited with a Mixin Class.
This is the definition of the attributes of a person object.
This object is used by the PeopleProxy.
Attributes
==========
*creationTime*:
+ Is a kind.
+ Set to None.
+ Is public to Xml Rpc
+ kindName : 'CreationTime'
*email*:
+ Is a kind.
+ Set to None.
+ Is required
+ Is public for Xml Rpc
+ kindName : 'Email'
*fingerprint*:
+ This is the GnuPG fingerprint.
+ Is a kind.
+ Set to None.
+ Is public for Xml Rpc
+ kindName : 'Fingerprint'
*firstName*:
+ Is a kind.
+ Set to None.
+ Is public for Xml Rpc
+ Is required
+ Is not translatable
+ kindName : 'String'
*language*:
+ Is a kind.
+ Not set
+ kindName : None
*lastName*:
+ Is a kind.
+ Set to None.
+ Is public for Xml Rpc
+ Is not translatable
+ kindName : 'String'
*modificationTime*:
+ The last modification date.
+ Is a kind.
+ Set to None.
+ Is public for Xml Rpc
+ kindName : 'ModificationTime'
*nickname*:
+ Is a kind.
+ Set to None.
+ Is public for Xml Rpc
+ Is not translatable
+ kindName : 'String'
*serverRole*:
The server name string that manage theses objects isntances. Default :
'people'.
*voteTokens*
+ The map of the user vote tokens, this is like a dictionnary with 'Id'
kind for key and 'Token' kinds as values.
+ Is a kind.
+ Set to None.
+ Is public for Xml Rpc
+ kindName : 'Mapping'
"""
creationTime = None
creationTime_kindName = 'CreationTime'
email = None
email_kind_balloonHelp = N_('Enter the e-mail address.')
email_kind_isRequired = 1
email_kindName = 'Email'
fingerprint = None
fingerprint_kind_balloonHelp = N_(
'Enter the GnuPG public key fingerprint; '\
'mandatory to receive encrypted e-mails.')
fingerprint_kindName = 'Fingerprint'
firstName = None
firstName_kind_balloonHelp = N_('Enter the first name.')
firstName_kind_isTranslatable = 0
firstName_kind_isRequired = 1
firstName_kindName = 'String'
language_kindName = None
lastName = None
lastName_kind_balloonHelp = N_('Enter the last name.')
lastName_kind_isTranslatable = 0
lastName_kindName = 'String'
modificationTime = None
modificationTime_kindName = 'ModificationTime'
nickname = None
nickname_kind_balloonHelp = N_('Enter an eventual nickname here.')
nickname_kind_isTranslatable = 0
nickname_kindName = 'String'
serverRole = 'people'
voteTokens = None
voteTokens_kind_importExport = 'from-server-only'
voteTokens_kind_keyKind_valueName = 'Id'
voteTokens_kind_keyKind_value_serverRoles = ['elections']
voteTokens_kind_valueKind_valueName = 'Token'
voteTokens_kindName = 'Mapping'
def canCache(self):
return 0
def containsText(self, text):
"""Lookup up text in some instance attributes.
The search is performed in the following attributes:
+ firstName
+ lastName
+ nickname
Keyword argument
================
*text*:
The wanted text.
Return
======
*1*:
The text was found.
*0*:
The text was not found.
"""
text = text.lower()
for attributeName in [
'firstName',
'lastName',
'nickname',
]:
attribute = getattr(self, attributeName)
if type(attribute) is type('') \
and attribute.lower().find(text) >= 0:
return 1
return 0
def getFullName(self):
"""Return the full person name string.
Return concatenation of firstName, lastName and nickname.
"""
return getFullName(self.firstName, self.lastName, self.nickname)
def getLabel(self):
"""Return the full person name string.
Return concatenation of firstName, lastName and nickname.
If this concatenation is impossible, and produce None, an empty string
is returned.
"""
label = self.getFullName()
if not label:
return self.email
return label
def getLabelLanguage(self):
"""Return an empty string."""
return ''
def getLanguage(self):
"""Return an empty string."""
return ''
def getOrderedLayoutSlotNames(self, parentSlot = None):
"""Return the layout slots names sequences.
The layout slots names of the parent are taken, and to them, the
class slot names are added.
Keyword argument
================
*parentSlot*:
The slot where the object is instanciated.
Return the slot names sequence, minimum slot names are the current
object slots.
"""
slotNames = ObjectCommon.getOrderedLayoutSlotNames(
self, parentSlot = parentSlot)
slotNames += [
'firstName', 'lastName', 'nickname', 'email',
'fingerprint', 'creationTime', 'modificationTime']
return slotNames
def getSortString(self):
"""Return the object string used for sorting.
Return the concatenation of the lastName and firstName string.
"""
if self.lastName:
sortString = self.lastName
else:
sortString = ''
if self.firstName:
sortString += ' ' + self.firstName
return sortString
class PeopleCommonMixin(ObjectsCommonMixin):
"""Abstract class designed to be inherited with another class.
The product of a multiple inheritance is a fonctionnal People server/proxy.
All methods can be overriden or extended, in fact, this class define their
default behavior.
Attributes:
===========
*adminClassName*:
The class name string used for administrative purposes.
*newObjectNameCapitalized*:
The illustrating string explaining what do a new object creation.
The objects are the objects handled by the subclass (not the class
itself).
*objectClassName*:
The handled object class name string.
*objectName*:
The 'gettextized' handled object class name string.
*objectNameCapitalized*:
The capitalized 'gettextized' handled object class name string.
*objectsName*:
The 'gettextized' functionnal class name string (Usualy the class name
without the type (proxy or server, etc...)).
*objectsNameCapitalized*:
The capitalized 'gettextized' class name string (Usualy the class name
without the type (proxy or server, etc...)).
*serverRole*:
The class server role string.
"""
adminClassName = 'AdminPeople'
newObjectNameCapitalized = N_('New Person')
objectClassName = 'Person'
objectName = N_('person')
objectNameCapitalized = N_('Person')
objectsName = N_('people')
objectsNameCapitalized = N_('People')
serverRole = 'people'
def getFullName(firstName, lastName, nickname = None):
"""Return the full person name string.
Return concatenation of firstName, lastName and nickname.
Keyword arguments
=================
*firstName*:
The first name string
*lastName*:
The last name string
*nickname*:
The nickname string (default: None).
"""
fullName = ''
if firstName:
if not fullName:
fullName = firstName
else:
fullName = fullName + ' ' + firstName
if nickname:
if not fullName:
fullName = '"' + nickname + '"'
else:
fullName = fullName + ' ' + '"' + nickname + '"'
if lastName:
if not fullName:
fullName = lastName
else:
fullName = fullName + ' ' + lastName
return fullName