source: WAeUP_SRP/trunk/Accommodation.py @ 639

Last change on this file since 639 was 638, checked in by joachim, 18 years ago

removed returning bed, reserved beds can now be separated by ,. or blank

  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1#-*- mode: python; mode: fold -*-
2from Globals import InitializeClass
3from AccessControl import ClassSecurityInfo
4
5from Products.CMFCore.utils import UniqueObject, getToolByName
6from Products.CMFCore.permissions import View
7from Products.CMFCore.permissions import ModifyPortalContent
8from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder
9#from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument
10from Products.CPSDocument.CPSDocument import CPSDocument
11from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder
12from Products.WAeUP_SRP.WAeUPTables import AccommodationTable
13import Globals
14import DateTime
15import re
16p_home = Globals.package_home(globals())
17i_home = Globals.INSTANCE_HOME
18
19class AccoFolder(CPSDocument): ###(
20    """
21    WAeUP AccoFolder containing Accommodation halls
22    """
23    meta_type = 'AccoFolder'
24    portal_type = meta_type
25    security = ClassSecurityInfo()
26
27    security.declareProtected(View,"Title")
28    def Title(self):
29        """compose title"""
30        return "Accommodation Section"
31
32    security.declareProtected(ModifyPortalContent,"generateFreeBedsList") ###(
33    def generateFreeBedsList(self):
34        """
35        generate the free Bedslist.
36        """
37        freelist = self.portal_accommodation
38        l = self.portal_catalog({'meta_type': "AccoHall"})
39        halls = []
40        generated = []
41        generated.append('"Bed","BedType","Student"' % vars())
42        beds_generated = []
43        for h in l:
44            halls.append(h.getObject())
45        for hall in halls:
46            #import pdb;pdb.set_trace()
47            h = hall.getContent()
48            hall_gen = {}
49            hall_gen['name'] = hall.Title
50            count = 0
51            #reserved = [int(r) for r in h.reserved_rooms.split(',')]
52            reserved = [int(r) for r in re.split(',|\.| ',h.reserved_rooms)
53                                     if not re.search(r'\D',r)]
54            sex = 'male'
55            if h.which_sex:
56                sex = 'female'
57            for block in range(1,int(h.nr_of_blocks)+1):
58                for floor in range(1,int(h.nr_of_floors)+1):
59                    for room in range(1,int(h.rooms_per_floor)+1):
60                        for bed in 'ABCDEFGH'[:int(h.beds_per_room)]:
61                            room_nr = floor*100 + room
62                            bt = 're'
63                            if room_nr in reserved:
64                                bt = "reserved"
65                            elif bed in h.beds_for_fresh:
66                                bt = 'fr'
67                            #elif bed in h.beds_for_returning:
68                            #    bt = 're'
69                            elif bed in h.beds_for_final:
70                                bt = 'fi'
71                            bt = "%(sex)s_%(bt)s" % vars()
72                            uid = '%s_%d_%d_%s' % (hall.getId(),block,room_nr,bed)
73                            try:
74                                freelist.addRecord(bed = uid, bed_type = bt,hall = hall.getId())
75                                count +=1
76                                generated.append('"%(uid)s","%(bt)s"' % vars())
77                            except ValueError:
78                                #freelist.modifyRecord(bed = uid, bed_type = bt,hall =hall.getId())
79                                pass
80            hall_gen['count']= count
81            beds_generated.append(hall_gen)
82        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
83        open("%s/import/bedlist_%s.csv" % (i_home,current),"w+").write('\n'.join(generated))
84        return self.accommodation.accommodation_view(beds_generated=beds_generated)
85
86###)
87
88InitializeClass(AccoFolder)
89
90def addAccoFolder(container, id, REQUEST=None, **kw):
91    """Add a AccoFolder."""
92    ob = AccoFolder(id, **kw)
93    return CPSBase_adder(container, ob, REQUEST=REQUEST)
94###)
95
96class AccoHall(CPSDocument): ###(
97    """
98    WAeUP AccoHall containing Departments
99    """
100    meta_type = 'AccoHall'
101    portal_type = meta_type
102    security = ClassSecurityInfo()
103
104    security.declareProtected(View,"Title") ###(
105    def Title(self):
106        """compose title"""
107        content = self.getContent()
108        heading = getattr(content,'heading',None)
109        if heading is None:
110            return self.title
111        return heading
112
113###)
114
115InitializeClass(AccoHall)
116
117def addAccoHall(container, id, REQUEST=None, **kw):
118    """Add a AccoHall."""
119    ob = AccoHall(id, **kw)
120    return CPSBase_adder(container, ob, REQUEST=REQUEST)
121###)
Note: See TracBrowser for help on using the repository browser.