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

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

Add Views for IBedTicket instances.

To get the old ZODB working, the following commands have to executed in the debug mode:

rootwaeup?configuration?.accommodation_states = []
import transaction
transaction.commit()

(provided that the University instance is called 'waeup').

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