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 | p_home = Globals.package_home(globals()) |
---|
16 | i_home = Globals.INSTANCE_HOME |
---|
17 | |
---|
18 | class AccoFolder(CPSDocument): ###( |
---|
19 | """ |
---|
20 | WAeUP AccoFolder containing Accommodation halls |
---|
21 | """ |
---|
22 | meta_type = 'AccoFolder' |
---|
23 | portal_type = meta_type |
---|
24 | security = ClassSecurityInfo() |
---|
25 | |
---|
26 | security.declareProtected(View,"Title") |
---|
27 | def Title(self): |
---|
28 | """compose title""" |
---|
29 | return "Accommodation Section" |
---|
30 | |
---|
31 | security.declareProtected(ModifyPortalContent,"generateFreeBedsList") ###( |
---|
32 | def generateFreeBedsList(self): |
---|
33 | """ |
---|
34 | generate the free Bedslist. |
---|
35 | """ |
---|
36 | freelist = self.portal_accommodation |
---|
37 | l = self.portal_catalog({'meta_type': "AccoHall"}) |
---|
38 | halls = [] |
---|
39 | generated = [] |
---|
40 | generated.append('"Bed","BedType","Student"' % vars()) |
---|
41 | beds_generated = [] |
---|
42 | for h in l: |
---|
43 | halls.append(h.getObject()) |
---|
44 | for hall in halls: |
---|
45 | #import pdb;pdb.set_trace() |
---|
46 | h = hall.getContent() |
---|
47 | hall_gen = {} |
---|
48 | hall_gen['name'] = hall.Title |
---|
49 | count = 0 |
---|
50 | reserved = [int(r) for r in h.reserved_rooms.split()] |
---|
51 | sex = 'male' |
---|
52 | if h.which_sex: |
---|
53 | sex = 'female' |
---|
54 | for block in range(1,int(h.nr_of_blocks)+1): |
---|
55 | for floor in range(1,int(h.nr_of_floors)+1): |
---|
56 | for room in range(1,int(h.rooms_per_floor)+1): |
---|
57 | for bed in 'ABCDEFGH'[:int(h.beds_per_room)]: |
---|
58 | room_nr = floor*100 + room |
---|
59 | bt = 'xx' |
---|
60 | if room_nr in reserved: |
---|
61 | bt = "reserved" |
---|
62 | elif bed in h.beds_for_fresh: |
---|
63 | bt = 'fr' |
---|
64 | elif bed in h.beds_for_returning: |
---|
65 | bt = 're' |
---|
66 | elif bed in h.beds_for_final: |
---|
67 | bt = 'fi' |
---|
68 | bt = "%(sex)s_%(bt)s" % vars() |
---|
69 | uid = '%s_%d_%d_%s' % (hall.getId(),block,room_nr,bed) |
---|
70 | try: |
---|
71 | freelist.addRecord(bed = uid, bed_type = bt,hall = hall.getId()) |
---|
72 | count +=1 |
---|
73 | generated.append('"%(uid)s","%(bt)s"' % vars()) |
---|
74 | except ValueError: |
---|
75 | #freelist.modifyRecord(bed = uid, bed_type = bt,hall =hall.getId()) |
---|
76 | pass |
---|
77 | hall_gen['count']= count |
---|
78 | beds_generated.append(hall_gen) |
---|
79 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
80 | open("%s/import/bedlist_%s.csv" % (i_home,current),"w+").write('\n'.join(generated)) |
---|
81 | return self.accommodation.accommodation_view(beds_generated=beds_generated) |
---|
82 | |
---|
83 | ###) |
---|
84 | |
---|
85 | InitializeClass(AccoFolder) |
---|
86 | |
---|
87 | def addAccoFolder(container, id, REQUEST=None, **kw): |
---|
88 | """Add a AccoFolder.""" |
---|
89 | ob = AccoFolder(id, **kw) |
---|
90 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
91 | ###) |
---|
92 | |
---|
93 | class AccoHall(CPSDocument): ###( |
---|
94 | """ |
---|
95 | WAeUP AccoHall containing Departments |
---|
96 | """ |
---|
97 | meta_type = 'AccoHall' |
---|
98 | portal_type = meta_type |
---|
99 | security = ClassSecurityInfo() |
---|
100 | |
---|
101 | security.declareProtected(View,"Title") ###( |
---|
102 | def Title(self): |
---|
103 | """compose title""" |
---|
104 | content = self.getContent() |
---|
105 | heading = getattr(content,'heading',None) |
---|
106 | if heading is None: |
---|
107 | return self.title |
---|
108 | return heading |
---|
109 | |
---|
110 | ###) |
---|
111 | |
---|
112 | InitializeClass(AccoHall) |
---|
113 | |
---|
114 | def addAccoHall(container, id, REQUEST=None, **kw): |
---|
115 | """Add a AccoHall.""" |
---|
116 | ob = AccoHall(id, **kw) |
---|
117 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
118 | ###) |
---|