source: main/waeup.kofa/trunk/src/waeup/kofa/students/accommodation.py @ 9986

Last change on this file since 9986 was 9984, checked in by Henrik Bettermann, 12 years ago

FCEOkene wants to hide the bed coordinates if maintenance fee is not yet paid. Thus we need additional property attributes which return the p_item (payment tickets) and the bed_coordinates attributes (bed tickets) by default and can be easily customized to hide this information in certain cases. bed_coordinates and p_item must be omitted on forms. The new display_ attributes are displayed instead.

All packages must now be adjusted.

The 'cost-benefit ratio' of these kinds of customizations is quite bad and we should think about declining such customization requests. However, I started customization and these are the changed made in the base package.

  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1## $Id: accommodation.py 9984 2013-02-24 08:29:24Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""
19Student accommodation components.
20"""
21from datetime import datetime
22import grok
23from zope.component import getUtility
24from zope.component.interfaces import IFactory
25from zope.interface import implementedBy
26from waeup.kofa.interfaces import academic_sessions_vocab, IKofaUtils
27from waeup.kofa.students.interfaces import (
28    IStudentAccommodation, IStudentNavigation, IBedTicket)
29from waeup.kofa.utils.helpers import attrs_to_fields
30
31class StudentAccommodation(grok.Container):
32    """This is a container for bed tickets.
33    """
34    grok.implements(IStudentAccommodation, IStudentNavigation)
35    grok.provides(IStudentAccommodation)
36
37    def __init__(self):
38        super(StudentAccommodation, self).__init__()
39        return
40
41    def addBedTicket(self, bedticket):
42        """Add a bed ticket object.
43        """
44        if not IBedTicket.providedBy(bedticket):
45            raise TypeError(
46                'StudentAccommodation containers contain only IBedTicket instances')
47        self[str(bedticket.booking_session)] = bedticket
48        return
49
50    @property
51    def student(self):
52        return self.__parent__
53
54    def writeLogMessage(self, view, message):
55        return self.__parent__.writeLogMessage(view, message)
56
57StudentAccommodation = attrs_to_fields(StudentAccommodation)
58
59class BedTicket(grok.Model):
60    """This is a bed ticket which shows that the student has booked a bed.
61    """
62    grok.implements(IBedTicket, IStudentNavigation)
63    grok.provides(IBedTicket)
64
65    def __init__(self):
66        super(BedTicket, self).__init__()
67        self.booking_date = datetime.utcnow()
68        self.bed = None
69        return
70
71    @property
72    def student(self):
73        try:
74            return self.__parent__.__parent__
75        except AttributeError:
76            return None
77
78    @property
79    def display_coordinates(self):
80        return self.bed_coordinates
81
82    def writeLogMessage(self, view, message):
83        return self.__parent__.__parent__.writeLogMessage(view, message)
84
85    def getSessionString(self):
86        return academic_sessions_vocab.getTerm(
87            self.booking_session).title
88
89BedTicket = attrs_to_fields(BedTicket, omit=['display_coordinates'])
90
91
92# Bed tickets must be importable. So we might need a factory.
93class BedTicketFactory(grok.GlobalUtility):
94    """A factory for bed tickets.
95    """
96    grok.implements(IFactory)
97    grok.name(u'waeup.BedTicket')
98    title = u"Create a new bed ticket.",
99    description = u"This factory instantiates new bed ticket instances."
100
101    def __call__(self, *args, **kw):
102        return BedTicket()
103
104    def getInterfaces(self):
105        return implementedBy(BedTicket)
Note: See TracBrowser for help on using the repository browser.