source: main/waeup.sirp/trunk/src/waeup/sirp/students/accommodation.py @ 11102

Last change on this file since 11102 was 7599, checked in by Henrik Bettermann, 13 years ago

Adjust some docstrings.

  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1## $Id: accommodation.py 7599 2012-02-07 11:30:00Z 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.interfaces import IFactory
24from zope.interface import implementedBy
25from waeup.sirp.interfaces import academic_sessions_vocab
26from waeup.sirp.students.interfaces import (
27    IStudentAccommodation, IStudentNavigation, IBedTicket)
28from waeup.sirp.utils.helpers import attrs_to_fields
29
30class StudentAccommodation(grok.Container):
31    """This is a container for accommodation objects.
32    """
33    grok.implements(IStudentAccommodation, IStudentNavigation)
34    grok.provides(IStudentAccommodation)
35
36    def __init__(self):
37        super(StudentAccommodation, self).__init__()
38        return
39
40    def addBedTicket(self, bedticket):
41        """Add a bed ticket object.
42        """
43        if not IBedTicket.providedBy(bedticket):
44            raise TypeError(
45                'StudentAccommodation containers contain only IBedTicket instances')
46        self[bedticket.ticket_id] = bedticket
47        return
48
49    def getStudent(self):
50        return self.__parent__
51
52StudentAccommodation = attrs_to_fields(StudentAccommodation)
53
54class BedTicket(grok.Model):
55    """This is a bed ticket which shows that the student has booked a bed
56    and paid the maintenance fee.
57    """
58    grok.implements(IBedTicket, IStudentNavigation)
59    grok.provides(IBedTicket)
60
61    def __init__(self):
62        super(BedTicket, self).__init__()
63        self.booking_date = datetime.now()
64        self.bed = None
65        return
66
67    def getStudent(self):
68        return self.__parent__.__parent__
69
70    def getSessionString(self):
71        return academic_sessions_vocab.getTerm(
72            self.booking_session).title
73
74BedTicket = attrs_to_fields(BedTicket)
75
76# Bed tickets must be importable. So we might need a factory.
77class BedTicketFactory(grok.GlobalUtility):
78    """A factory for bed tickets.
79    """
80    grok.implements(IFactory)
81    grok.name(u'waeup.BedTicket')
82    title = u"Create a new bed ticket.",
83    description = u"This factory instantiates new bed ticket instances."
84
85    def __call__(self, *args, **kw):
86        return BedTicket()
87
88    def getInterfaces(self):
89        return implementedBy(BedTicket)
Note: See TracBrowser for help on using the repository browser.