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

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

Implement bed booking algorithm (work in progress!).

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