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

Last change on this file since 7003 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
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.interfaces import academic_sessions_vocab
24from waeup.sirp.students.interfaces import (
25    IStudentAccommodation, IStudentNavigation, IBedTicket)
26from waeup.sirp.utils.helpers import attrs_to_fields
27
28class StudentAccommodation(grok.Container):
29    """This is a container for accommodation objects.
30    """
31    grok.implements(IStudentAccommodation, IStudentNavigation)
32    grok.provides(IStudentAccommodation)
33
34    def __init__(self):
35        super(StudentAccommodation, self).__init__()
36        return
37
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
47    def getStudent(self):
48        return self.__parent__
49
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__()
61        self.booking_date = datetime.now()
62        self.bed = None
63        return
64
65    def getStudent(self):
66        return self.__parent__.__parent__
67
68    def getSessionString(self):
69        return academic_sessions_vocab.getTerm(
70            self.booking_session).title
71
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.