[7190] | 1 | ## $Id: accommodation.py 7190 2011-11-25 07:10:06Z henrik $ |
---|
| 2 | ## |
---|
[6635] | 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 | Container which contains the (student) accommodation objects. |
---|
| 20 | """ |
---|
[6992] | 21 | from datetime import datetime |
---|
[6635] | 22 | import grok |
---|
| 23 | from grok import index |
---|
| 24 | from zope.component.interfaces import IFactory |
---|
[6994] | 25 | from waeup.sirp.interfaces import academic_sessions_vocab |
---|
[6642] | 26 | from waeup.sirp.students.interfaces import ( |
---|
[6989] | 27 | IStudentAccommodation, IStudentNavigation, IBedTicket) |
---|
[6635] | 28 | from waeup.sirp.utils.helpers import attrs_to_fields |
---|
| 29 | |
---|
| 30 | class StudentAccommodation(grok.Container): |
---|
| 31 | """This is a container for accommodation objects. |
---|
| 32 | """ |
---|
[6642] | 33 | grok.implements(IStudentAccommodation, IStudentNavigation) |
---|
[6635] | 34 | grok.provides(IStudentAccommodation) |
---|
| 35 | |
---|
| 36 | def __init__(self): |
---|
| 37 | super(StudentAccommodation, self).__init__() |
---|
| 38 | return |
---|
| 39 | |
---|
[6989] | 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 | |
---|
[6642] | 49 | def getStudent(self): |
---|
| 50 | return self.__parent__ |
---|
| 51 | |
---|
[6989] | 52 | StudentAccommodation = attrs_to_fields(StudentAccommodation) |
---|
| 53 | |
---|
| 54 | class 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__() |
---|
[6992] | 63 | self.booking_date = datetime.now() |
---|
[6996] | 64 | self.bed = None |
---|
[6989] | 65 | return |
---|
| 66 | |
---|
| 67 | def getStudent(self): |
---|
| 68 | return self.__parent__.__parent__ |
---|
| 69 | |
---|
[6994] | 70 | def getSessionString(self): |
---|
| 71 | return academic_sessions_vocab.getTerm( |
---|
| 72 | self.booking_session).title |
---|
| 73 | |
---|
[6992] | 74 | BedTicket = attrs_to_fields(BedTicket) |
---|
| 75 | |
---|
| 76 | # Bed tickets must be importable. So we might need a factory. |
---|
| 77 | class 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) |
---|