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

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

First version of bed creator (work in progress).

  • Property svn:keywords set to Id
File size: 5.1 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_reserved = [] #temporarily empty
59        all_blocks = blocks_for_female + blocks_for_male
60        all_beds = (beds_for_pre + beds_for_fresh +
61            beds_for_returning + beds_for_final)
62        #import pdb;pdb.set_trace()
63        for block in all_blocks:
64            sex = 'male'
65            if block in blocks_for_female:
66                sex = 'female'
67            for floor in range(1,int(self.floors_per_block)+1):
68                for room in range(1,int(self.rooms_per_floor)+1):
69                    for bed in all_beds:
70                        room_nr = floor*100 + room
71                        bt = 'all'
72                        if (block,room_nr) in beds_reserved:
73                            bt = "reserved"
74                        # Hostels with special handling and
75                        # without bed categorisation
76                        elif (self.special_handling != 'none' and not
77                              self.special_handling.endswith("_withcat")):
78                            bt = self.special_handling[3:]
79                        elif bed in beds_for_fresh:
80                            bt = 'fr'
81                        elif bed in beds_for_pre:
82                            bt = 'pr'
83                        elif bed in beds_for_final:
84                            bt = 'fi'
85                        elif bed in beds_for_returning:
86                            bt = 're'
87                        # Hostels with special handling and
88                        # with bed categorisation
89                        if (self.special_handling != 'none' and
90                            self.special_handling.endswith("_withcat")):
91                            bt += "_" + self.special_handling
92                        bt = u'%(sex)s_%(bt)s' % vars()
93                        uid = u'%s_%s_%d_%s' % (self.hostel_id,block,room_nr,bed)
94                        if self.has_key(uid):
95                            bed = self[uid]
96                            if bed.bed_type != bt:
97                                bed.bed_type = bt
98                                bed.sort_id = getattr(self,'sort_id',0)
99                                #modified.append('"%(uid)s","%(bt)s","%(bed.owner)s"' % vars())
100                                modified_counter += 1
101                        else:
102                            bed = Bed()
103                            bed.bed_id = uid
104                            bed.bed_type = bt
105                            bed.sort_id = getattr(self,'sort_id',0)
106                            bed.owner = NOT_OCCUPIED
107                            self.addBed(bed)
108                            #generated.append('"%(uid)s","%(bt)s"' % vars())
109                            added_counter +=1
110        return added_counter, modified_counter
111
112Hostel = attrs_to_fields(Hostel)
113
114class Bed(grok.Container):
115    """This is a bed.
116    """
117    grok.implements(IBed)
118    grok.provides(IBed)
119
120    def getBedCoordinates(self):
121        """Determine the coordinates from bed_id.
122        """
123        pass
124
125    def loggerInfo(self, ob_class, comment=None):
126        target = self.__name__
127        return grok.getSite()['hostels'].logger_info(ob_class,target,comment)
128
129Bed = attrs_to_fields(Bed)
Note: See TracBrowser for help on using the repository browser.