source: WAeUP_SRP/trunk/Accommodation.py @ 408

Last change on this file since 408 was 407, checked in by joachim, 18 years ago

undoing change committed in 404

  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1#-*- mode: python; mode: fold -*-
2from Globals import InitializeClass
3from AccessControl import ClassSecurityInfo
4
5from Products.CMFCore.utils import UniqueObject, getToolByName
6from Products.CMFCore.permissions import View
7from Products.CMFCore.permissions import ModifyPortalContent
8from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder
9#from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument
10from Products.CPSDocument.CPSDocument import CPSDocument
11from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder
12from Products.WAeUP_SRP.WAeUPTables import AccommodationTable
13
14class 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
57InitializeClass(AccoFolder)
58
59def 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
65class 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               
87InitializeClass(Accommodation)
88
89def addAccommodation(container, id, REQUEST=None, **kw):
90    """Add a Accommodation."""
91    ob = Accommodation(id, **kw)
92    return CPSBase_adder(container, ob, REQUEST=REQUEST)
93###)
Note: See TracBrowser for help on using the repository browser.