source: WAeUP_SRP/trunk/Accommodation.py @ 596

Last change on this file since 596 was 575, checked in by Henrik Bettermann, 18 years ago

email field added to personal schema and layout
title method for AccoFolder? added

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