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/AppointmentsCommon.py

177 lines
5.6 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 Appointments Common Models"""
__version__ = '$Revision$'[11:-2]
import calendar
import time
from ObjectsCommon import AdminCommon, ObjectCommon, ObjectsCommonMixin
ONE_MINUTE = 60
ONE_HOUR = ONE_MINUTE * 60
ONE_DAY = ONE_HOUR * 24
ONE_WEEK = ONE_DAY * 7
ONE_MONTH = ONE_DAY * 28
ONE_YEAR = ONE_DAY * 365
MONTHS = ['', 'January', 'February', 'March', 'April', 'May', 'June', \
'July', 'August', 'September', 'October', 'November', 'December']
DAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', \
'Saturday', 'Sunday']
class AdminAppointmentsCommon(AdminCommon):
categoriesGroupId = None
categoriesGroupId_kind_balloonHelp = N_(
'Select the group that holds categories for the appointments.')
categoriesGroupId_kind_serverRoles = ['groups']
categoriesGroupId_kindName = 'Id'
serverRole = 'appointments'
class AppointmentCommon(ObjectCommon):
body = None
body_kind_balloonHelp = N_('Enter the text of this appointment.')
body_kindName = 'String'
creationTime = None
creationTime_kindName = 'CreationTime'
end = None
end_kindName = 'Time'
participantsSet = None
participantsSet_kind_itemKind_valueName = 'Id'
participantsSet_kind_itemKind_value_serverRoles = ['groups', 'people']
participantsSet_kind_requiredCount = 0
participantsSet_kindName = 'Sequence'
readersSet = None
readersSet_kindName = 'ReadersSet'
serverRole = 'appointments'
start = None
start_kind_balloonHelp = N_('Enter the day of the appointment.')
start_kind_isRequired = 1
start_kindName = 'Time'
title = None
title_kind_balloonHelp = N_('Enter a title for this appointment.')
title_kind_isRequired = 1
title_kindName = 'String'
writersSet = None
writersSet_kindName = 'WritersSet'
def canCache(self):
return 1
def getCategory(self):
result = self.category
if result is None:
result = ''
return result
def getLabel(self):
label = self.getTitle()
if label is None:
return ''
hourTime = self.getBeginningHourAndMinute()
if label and hourTime:
return '%s - %s' % (hourTime, label)
return label
def getTitle(self):
return self.title
def getBeginningHourAndMinute(self):
"""Returns a string with the start time of the appointment (or None
if no time set)"""
hour = '%02d:%02d' % time.localtime(self.start)[3:5]
if hour == '00:00' and not self.end:
return None
if self.end:
hourEnd = '%02d:%02d' % time.localtime(self.end)[3:5]
if hour == '00:00' and self.end - self.start < 86400 and \
hourEnd == '23:59':
return None
return hour
def getEndHourAndMinute(self):
if not self.end:
return None
hour = '%02d:%02d' % time.localtime(self.end)[3:5]
return hour
def getOrderedLayoutSlotNames(self, parentSlot = None):
slotNames = ObjectCommon.getOrderedLayoutSlotNames(
self, parentSlot = parentSlot)
slotNames += [
'title',
'start',
'end',
'body',
'participantsSet',
'creationTime',
'writersSet',
'readersSet',
]
return slotNames
class AppointmentsCommonMixin(ObjectsCommonMixin):
adminClassName = 'AdminAppointments'
objectClassName = 'Appointment'
newObjectNameCapitalized = N_('New Appointment')
objectName = N_('appointment')
objectNameCapitalized = N_('Appointment')
objectsName = N_('appointments')
objectsNameCapitalized = N_('Appointments')
serverRole = 'appointments'