source: WAeUP_SRP/trunk/Accommodation.py @ 466

Last change on this file since 466 was 411, checked in by joachim, 18 years ago

added AccomodationTable? again

  • Property svn:keywords set to Id
File size: 3.6 KB
RevLine 
[103]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
[404]12from Products.WAeUP_SRP.WAeUPTables import AccommodationTable
[103]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   
[404]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()
[407]34            reserved = [int(r) for r in h.reserved_rooms.split()]
[411]35            print h.which_sex
36            sex = 'male'
37            if h.which_sex:
38                sex = 'female'
[404]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
[407]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'
[411]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                   
[407]63        return self.accommodation.academics_contents()
[152]64
[404]65###)
66
[103]67InitializeClass(AccoFolder)
68
69def 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
75class Accommodation(CPSDocument): ###(
76    """
77    WAeUP Accommodation containing Departments
78    """
79    meta_type = 'Accommodation'
80    portal_type = meta_type
81    security = ClassSecurityInfo()
82   
[404]83    security.declareProtected(View,"Title") ###(
[152]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
[404]91
92###)
93
94       
95                           
96               
[103]97InitializeClass(Accommodation)
98
99def addAccommodation(container, id, REQUEST=None, **kw):
100    """Add a Accommodation."""
101    ob = Accommodation(id, **kw)
102    return CPSBase_adder(container, ob, REQUEST=REQUEST)
103###)
Note: See TracBrowser for help on using the repository browser.