source: main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py @ 6971

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

We don't need special handling codes with and without categorization like in SRP. A new beds_for_all field is sufficient to configure these hostels.

  • Property svn:keywords set to Id
File size: 4.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"""
17These are the hostels.
18"""
19import grok
20from datetime import datetime
21from grok import index
22from waeup.sirp.utils.helpers import attrs_to_fields
23from waeup.sirp.hostels.interfaces import IHostel, IBed
24
25NOT_OCCUPIED = u'not occupied'
26
27class Hostel(grok.Container):
28    """This is a hostel.
29    """
30    grok.implements(IHostel)
31    grok.provides(IHostel)
32
33    def loggerInfo(self, ob_class, comment=None):
34        target = self.__name__
35        return grok.getSite()['hostels'].logger_info(ob_class,target,comment)
36
37    def addBed(self, bed):
38        """Add a bed.
39        """
40        if not IBed.providedBy(bed):
41            raise TypeError(
42                'Hostels contain only IBed instances')
43        self[bed.bed_id] = bed
44        return
45
46    # not yet tested nor used
47    def updateBeds(self):
48        """Fill hostel with beds or update beds.
49        """
50        added_counter = 0
51        modified_counter = 0
52        blocks_for_female = getattr(self,'blocks_for_female',[])
53        blocks_for_male = getattr(self,'blocks_for_male',[])
54        beds_for_fresh = getattr(self,'beds_for_fresh',[])
55        beds_for_pre = getattr(self,'beds_for_pre',[])
56        beds_for_returning = getattr(self,'beds_for_returning',[])
57        beds_for_final = getattr(self,'beds_for_final',[])
58        beds_for_all = getattr(self,'beds_for_all',[])
59        beds_reserved = [] #temporarily empty
60        all_blocks = blocks_for_female + blocks_for_male
61        all_beds = (beds_for_pre + beds_for_fresh +
62            beds_for_returning + beds_for_final + beds_for_all)
63        #import pdb;pdb.set_trace()
64        for block in all_blocks:
65            sex = 'male'
66            if block in blocks_for_female:
67                sex = 'female'
68            for floor in range(1,int(self.floors_per_block)+1):
69                for room in range(1,int(self.rooms_per_floor)+1):
70                    for bed in all_beds:
71                        room_nr = floor*100 + room
72                        bt = 'all'
73                        if (block,room_nr) in beds_reserved:
74                            bt = "reserved"
75                        elif bed in beds_for_fresh:
76                            bt = 'fr'
77                        elif bed in beds_for_pre:
78                            bt = 'pr'
79                        elif bed in beds_for_final:
80                            bt = 'fi'
81                        elif bed in beds_for_returning:
82                            bt = 're'
83                        # Hostels with special handling
84                        if self.special_handling != 'none':
85                            bt += "_" + self.special_handling
86                        bt = u'%(sex)s_%(bt)s' % vars()
87                        uid = u'%s_%s_%d_%s' % (self.hostel_id,block,room_nr,bed)
88                        if self.has_key(uid):
89                            bed = self[uid]
90                            if bed.bed_type != bt:
91                                bed.bed_type = bt
92                                #modified.append('"%(uid)s","%(bt)s","%(bed.owner)s"' % vars())
93                                modified_counter += 1
94                        else:
95                            bed = Bed()
96                            bed.bed_id = uid
97                            bed.bed_type = bt
98                            bed.bed_number = len(self) + 1
99                            bed.owner = NOT_OCCUPIED
100                            self.addBed(bed)
101                            #generated.append('"%(uid)s","%(bt)s"' % vars())
102                            added_counter +=1
103        return added_counter, modified_counter
104
105Hostel = attrs_to_fields(Hostel)
106
107class Bed(grok.Container):
108    """This is a bed.
109    """
110    grok.implements(IBed)
111    grok.provides(IBed)
112
113    def getBedCoordinates(self):
114        """Determine the coordinates from bed_id.
115        """
116        pass
117
118    def loggerInfo(self, ob_class, comment=None):
119        target = self.__name__
120        return grok.getSite()['hostels'].logger_info(ob_class,target,comment)
121
122Bed = attrs_to_fields(Bed)
Note: See TracBrowser for help on using the repository browser.