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 | for block in range(1,int(h.nr_of_blocks)): |
---|
35 | for floor in range(1,int(h.nr_of_floors)): |
---|
36 | for room in range(1,int(h.rooms_per_floor)): |
---|
37 | for bed in 'ABCDEFGH'[:int(h.beds_per_room)]: |
---|
38 | room_nr = floor*100 + room |
---|
39 | freelist.addRecord(bed = '%s_%d_%s' % (h.getId(),room_nr,bed), |
---|
40 | bed_type = "test") |
---|
41 | |
---|
42 | ###) |
---|
43 | |
---|
44 | InitializeClass(AccoFolder) |
---|
45 | |
---|
46 | def addAccoFolder(container, id, REQUEST=None, **kw): |
---|
47 | """Add a AccoFolder.""" |
---|
48 | ob = AccoFolder(id, **kw) |
---|
49 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
50 | ###) |
---|
51 | |
---|
52 | class Accommodation(CPSDocument): ###( |
---|
53 | """ |
---|
54 | WAeUP Accommodation containing Departments |
---|
55 | """ |
---|
56 | meta_type = 'Accommodation' |
---|
57 | portal_type = meta_type |
---|
58 | security = ClassSecurityInfo() |
---|
59 | |
---|
60 | security.declareProtected(View,"Title") ###( |
---|
61 | def Title(self): |
---|
62 | """compose title""" |
---|
63 | content = self.getContent() |
---|
64 | heading = getattr(content,'heading',None) |
---|
65 | if heading is None: |
---|
66 | return self.title |
---|
67 | return heading |
---|
68 | |
---|
69 | ###) |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | InitializeClass(Accommodation) |
---|
75 | |
---|
76 | def addAccommodation(container, id, REQUEST=None, **kw): |
---|
77 | """Add a Accommodation.""" |
---|
78 | ob = Accommodation(id, **kw) |
---|
79 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
80 | ###) |
---|