1 | #-*- mode: python; mode: fold -*- |
---|
2 | from Globals import InitializeClass |
---|
3 | from AccessControl import ClassSecurityInfo |
---|
4 | |
---|
5 | from Products.CMFCore.utils import UniqueObject, getToolByName |
---|
6 | from Products.CMFCore.permissions import View |
---|
7 | from Products.CMFCore.permissions import ModifyPortalContent |
---|
8 | from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder |
---|
9 | #from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument |
---|
10 | from Products.CPSDocument.CPSDocument import CPSDocument |
---|
11 | from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder |
---|
12 | from Products.WAeUP_SRP.WAeUPTables import AccommodationTable |
---|
13 | import Globals |
---|
14 | import DateTime |
---|
15 | import re |
---|
16 | p_home = Globals.package_home(globals()) |
---|
17 | i_home = Globals.INSTANCE_HOME |
---|
18 | |
---|
19 | class 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.split('/')[0]),int(r.split('/')[1])) for r in re.split(',|\.| ',h.reserved_rooms) |
---|
52 | if r] |
---|
53 | sex = 'male' |
---|
54 | if h.which_sex: |
---|
55 | sex = 'female' |
---|
56 | for block in range(1,int(h.nr_of_blocks)+1): |
---|
57 | for floor in range(1,int(h.nr_of_floors)+1): |
---|
58 | for room in range(1,int(h.rooms_per_floor)+1): |
---|
59 | for bed in 'ABCDEFGH'[:int(h.beds_per_room)]: |
---|
60 | room_nr = floor*100 + room |
---|
61 | bt = 're' |
---|
62 | if (block,room_nr) in reserved: |
---|
63 | bt = "reserved" |
---|
64 | elif bed in h.beds_for_fresh: |
---|
65 | bt = 'fr' |
---|
66 | #elif bed in h.beds_for_returning: |
---|
67 | # bt = 're' |
---|
68 | elif bed in h.beds_for_final: |
---|
69 | bt = 'fi' |
---|
70 | bt = "%(sex)s_%(bt)s" % vars() |
---|
71 | uid = '%s_%d_%d_%s' % (hall.getId(),block,room_nr,bed) |
---|
72 | try: |
---|
73 | freelist.addRecord(bed = uid, bed_type = bt,hall = hall.getId()) |
---|
74 | count +=1 |
---|
75 | generated.append('"%(uid)s","%(bt)s"' % vars()) |
---|
76 | except ValueError: |
---|
77 | #freelist.modifyRecord(bed = uid, bed_type = bt,hall =hall.getId()) |
---|
78 | pass |
---|
79 | hall_gen['count']= count |
---|
80 | beds_generated.append(hall_gen) |
---|
81 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
82 | open("%s/import/bedlist_%s.csv" % (i_home,current),"w+").write('\n'.join(generated)) |
---|
83 | return self.accommodation.acco_folder_view(beds_generated=beds_generated) |
---|
84 | |
---|
85 | ###) |
---|
86 | |
---|
87 | InitializeClass(AccoFolder) |
---|
88 | |
---|
89 | def addAccoFolder(container, id, REQUEST=None, **kw): |
---|
90 | """Add a AccoFolder.""" |
---|
91 | ob = AccoFolder(id, **kw) |
---|
92 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
93 | ###) |
---|
94 | |
---|
95 | class AccoHall(CPSDocument): ###( |
---|
96 | """ |
---|
97 | WAeUP AccoHall containing Departments |
---|
98 | """ |
---|
99 | meta_type = 'AccoHall' |
---|
100 | portal_type = meta_type |
---|
101 | security = ClassSecurityInfo() |
---|
102 | |
---|
103 | security.declareProtected(View,"Title") ###( |
---|
104 | def Title(self): |
---|
105 | """compose title""" |
---|
106 | content = self.getContent() |
---|
107 | heading = getattr(content,'heading',None) |
---|
108 | if heading is None: |
---|
109 | return self.title |
---|
110 | return heading |
---|
111 | |
---|
112 | ###) |
---|
113 | |
---|
114 | InitializeClass(AccoHall) |
---|
115 | |
---|
116 | def addAccoHall(container, id, REQUEST=None, **kw): |
---|
117 | """Add a AccoHall.""" |
---|
118 | ob = AccoHall(id, **kw) |
---|
119 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
120 | ###) |
---|