1 | ## $Id: accommodation.py 8194 2012-04-17 11:40:06Z 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 | """ |
---|
19 | Student accommodation components. |
---|
20 | """ |
---|
21 | from datetime import datetime |
---|
22 | import grok |
---|
23 | from zope.component import getUtility |
---|
24 | from zope.component.interfaces import IFactory |
---|
25 | from zope.interface import implementedBy |
---|
26 | from waeup.kofa.interfaces import academic_sessions_vocab, IKofaUtils |
---|
27 | from waeup.kofa.students.interfaces import ( |
---|
28 | IStudentAccommodation, IStudentNavigation, IBedTicket) |
---|
29 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
30 | |
---|
31 | class StudentAccommodation(grok.Container): |
---|
32 | """This is a container for accommodation objects. |
---|
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[bedticket.ticket_id] = bedticket |
---|
48 | return |
---|
49 | |
---|
50 | def getStudent(self): |
---|
51 | return self.__parent__ |
---|
52 | |
---|
53 | StudentAccommodation = attrs_to_fields(StudentAccommodation) |
---|
54 | |
---|
55 | class BedTicket(grok.Model): |
---|
56 | """This is a bed ticket which shows that the student has booked a bed |
---|
57 | and paid the maintenance fee. |
---|
58 | """ |
---|
59 | grok.implements(IBedTicket, IStudentNavigation) |
---|
60 | grok.provides(IBedTicket) |
---|
61 | |
---|
62 | def __init__(self): |
---|
63 | super(BedTicket, self).__init__() |
---|
64 | self.booking_date = datetime.utcnow() |
---|
65 | self.bed = None |
---|
66 | return |
---|
67 | |
---|
68 | def getStudent(self): |
---|
69 | return self.__parent__.__parent__ |
---|
70 | |
---|
71 | def getSessionString(self): |
---|
72 | return academic_sessions_vocab.getTerm( |
---|
73 | self.booking_session).title |
---|
74 | |
---|
75 | BedTicket = attrs_to_fields(BedTicket) |
---|
76 | |
---|
77 | # Bed tickets must be importable. So we might need a factory. |
---|
78 | class BedTicketFactory(grok.GlobalUtility): |
---|
79 | """A factory for bed tickets. |
---|
80 | """ |
---|
81 | grok.implements(IFactory) |
---|
82 | grok.name(u'waeup.BedTicket') |
---|
83 | title = u"Create a new bed ticket.", |
---|
84 | description = u"This factory instantiates new bed ticket instances." |
---|
85 | |
---|
86 | def __call__(self, *args, **kw): |
---|
87 | return BedTicket() |
---|
88 | |
---|
89 | def getInterfaces(self): |
---|
90 | return implementedBy(BedTicket) |
---|