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 | print h.which_sex |
---|
36 | sex = 'male' |
---|
37 | if h.which_sex: |
---|
38 | sex = 'female' |
---|
39 | for block in range(1,int(h.nr_of_blocks)): |
---|
40 | for floor in range(1,int(h.nr_of_floors)): |
---|
41 | for room in range(1,int(h.rooms_per_floor)): |
---|
42 | for bed in 'ABCDEFGH'[:int(h.beds_per_room)]: |
---|
43 | room_nr = floor*100 + room |
---|
44 | if room_nr in reserved: |
---|
45 | print room_nr |
---|
46 | continue |
---|
47 | bt = 'xx' |
---|
48 | if bed in h.beds_for_fresh: |
---|
49 | bt = 'fr' |
---|
50 | elif bed in h.beds_for_returning: |
---|
51 | bt = 're' |
---|
52 | elif bed in h.beds_for_final: |
---|
53 | bt = 'fi' |
---|
54 | bt = "%(sex)s_%(bt)s" % vars() |
---|
55 | uid = '%s_%d_%s' % (hall.getId(),room_nr,bed) |
---|
56 | print bt,uid |
---|
57 | freelist.addRecord(bed = uid) |
---|
58 | try: |
---|
59 | freelist.modifyRecord(uid, bed = bed, bed_type = bt) |
---|
60 | except ValueError,e: |
---|
61 | freelist.deleteRecord(uid) |
---|
62 | |
---|
63 | return self.accommodation.academics_contents() |
---|
64 | |
---|
65 | ###) |
---|
66 | |
---|
67 | InitializeClass(AccoFolder) |
---|
68 | |
---|
69 | def addAccoFolder(container, id, REQUEST=None, **kw): |
---|
70 | """Add a AccoFolder.""" |
---|
71 | ob = AccoFolder(id, **kw) |
---|
72 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
73 | ###) |
---|
74 | |
---|
75 | class Accommodation(CPSDocument): ###( |
---|
76 | """ |
---|
77 | WAeUP Accommodation containing Departments |
---|
78 | """ |
---|
79 | meta_type = 'Accommodation' |
---|
80 | portal_type = meta_type |
---|
81 | security = ClassSecurityInfo() |
---|
82 | |
---|
83 | security.declareProtected(View,"Title") ###( |
---|
84 | def Title(self): |
---|
85 | """compose title""" |
---|
86 | content = self.getContent() |
---|
87 | heading = getattr(content,'heading',None) |
---|
88 | if heading is None: |
---|
89 | return self.title |
---|
90 | return heading |
---|
91 | |
---|
92 | ###) |
---|
93 | |
---|
94 | InitializeClass(Accommodation) |
---|
95 | |
---|
96 | def addAccommodation(container, id, REQUEST=None, **kw): |
---|
97 | """Add a Accommodation.""" |
---|
98 | ob = Accommodation(id, **kw) |
---|
99 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
100 | ###) |
---|