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 | |
---|
14 | class AccoFolder(CPSDocument): ###( |
---|
15 | """ |
---|
16 | WAeUP AccoFolder containing Accommodation halls |
---|
17 | """ |
---|
18 | meta_type = 'AccoFolder' |
---|
19 | portal_type = meta_type |
---|
20 | security = ClassSecurityInfo() |
---|
21 | |
---|
22 | security.declareProtected(ModifyPortalContent,"generateFreeBedsList") ###( |
---|
23 | def generateFreeBedsList(self): |
---|
24 | """ |
---|
25 | generate the free Bedslist. |
---|
26 | """ |
---|
27 | freelist = AccommodationTable() |
---|
28 | l = self.portal_catalog({'meta_type': "Accommodation"}) |
---|
29 | halls = [] |
---|
30 | for h in l: |
---|
31 | halls.append(h.getObject()) |
---|
32 | for hall in halls: |
---|
33 | h = hall.getContent() |
---|
34 | reserved = [int(r) for r in h.reserved_rooms.split()] |
---|
35 | for block in range(1,int(h.nr_of_blocks)): |
---|
36 | for floor in range(1,int(h.nr_of_floors)): |
---|
37 | for room in range(1,int(h.rooms_per_floor)): |
---|
38 | for bed in 'ABCDEFGH'[:int(h.beds_per_room)]: |
---|
39 | room_nr = floor*100 + room |
---|
40 | if room_nr in reserved: |
---|
41 | print room_nr |
---|
42 | continue |
---|
43 | bt = 'xx' |
---|
44 | if bed in h.beds_for_fresh: |
---|
45 | bt = 'fr' |
---|
46 | elif bed in h.beds_for_returning: |
---|
47 | bt = 're' |
---|
48 | elif bed in h.beds_for_final: |
---|
49 | bt = 'fi' |
---|
50 | print bt |
---|
51 | freelist.addRecord(bed = '%s_%d_%s' % (h.getId(),room_nr,bed), |
---|
52 | bed_type = bt) |
---|
53 | return self.accommodation.academics_contents() |
---|
54 | |
---|
55 | ###) |
---|
56 | |
---|
57 | InitializeClass(AccoFolder) |
---|
58 | |
---|
59 | def addAccoFolder(container, id, REQUEST=None, **kw): |
---|
60 | """Add a AccoFolder.""" |
---|
61 | ob = AccoFolder(id, **kw) |
---|
62 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
63 | ###) |
---|
64 | |
---|
65 | class Accommodation(CPSDocument): ###( |
---|
66 | """ |
---|
67 | WAeUP Accommodation containing Departments |
---|
68 | """ |
---|
69 | meta_type = 'Accommodation' |
---|
70 | portal_type = meta_type |
---|
71 | security = ClassSecurityInfo() |
---|
72 | |
---|
73 | security.declareProtected(View,"Title") ###( |
---|
74 | def Title(self): |
---|
75 | """compose title""" |
---|
76 | content = self.getContent() |
---|
77 | heading = getattr(content,'heading',None) |
---|
78 | if heading is None: |
---|
79 | return self.title |
---|
80 | return heading |
---|
81 | |
---|
82 | ###) |
---|
83 | |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | InitializeClass(Accommodation) |
---|
88 | |
---|
89 | def addAccommodation(container, id, REQUEST=None, **kw): |
---|
90 | """Add a Accommodation.""" |
---|
91 | ob = Accommodation(id, **kw) |
---|
92 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
93 | ###) |
---|