source: WAeUP_SRP/trunk/Accommodation.py @ 632

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

table layout modified

  • Property svn:keywords set to Id
File size: 4.3 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
13import Globals
14import DateTime
15p_home = Globals.package_home(globals())
16i_home = Globals.INSTANCE_HOME
17
18class AccoFolder(CPSDocument): ###(
19    """
20    WAeUP AccoFolder containing Accommodation halls
21    """
22    meta_type = 'AccoFolder'
23    portal_type = meta_type
24    security = ClassSecurityInfo()
25
26    security.declareProtected(View,"Title")
27    def Title(self):
28        """compose title"""
29        return "Accommodation Section"
30
31    security.declareProtected(ModifyPortalContent,"generateFreeBedsList") ###(
32    def generateFreeBedsList(self):
33        """
34        generate the free Bedslist.
35        """
36        freelist = self.portal_accommodation
37        l = self.portal_catalog({'meta_type': "AccoHall"})
38        halls = []
39        generated = []
40        generated.append('"Bed","BedType","Student"' % vars())
41        beds_generated = []
42        for h in l:
43            halls.append(h.getObject())
44        for hall in halls:
45            #import pdb;pdb.set_trace()
46            h = hall.getContent()
47            hall_gen = {}
48            hall_gen['name'] = hall.Title
49            count = 0
50            reserved = [int(r) for r in h.reserved_rooms.split()]
51            sex = 'male'
52            if h.which_sex:
53                sex = 'female'
54            for block in range(1,int(h.nr_of_blocks)+1):
55                for floor in range(1,int(h.nr_of_floors)+1):
56                    for room in range(1,int(h.rooms_per_floor)+1):
57                        for bed in 'ABCDEFGH'[:int(h.beds_per_room)]:
58                            room_nr = floor*100 + room
59                            bt = 'xx'
60                            if room_nr in reserved:
61                                bt = "reserved"
62                            elif bed in h.beds_for_fresh:
63                                bt = 'fr'
64                            elif bed in h.beds_for_returning:
65                                bt = 're'
66                            elif bed in h.beds_for_final:
67                                bt = 'fi'
68                            bt = "%(sex)s_%(bt)s" % vars()
69                            uid = '%s_%d_%d_%s' % (hall.getId(),block,room_nr,bed)
70                            try:
71                                freelist.addRecord(bed = uid, bed_type = bt,hall = hall.getId())
72                                count +=1
73                                generated.append('"%(uid)s","%(bt)s"' % vars())
74                            except ValueError:
75                                #freelist.modifyRecord(bed = uid, bed_type = bt,hall =hall.getId())
76                                pass
77            hall_gen['count']= count
78            beds_generated.append(hall_gen)
79        current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S")
80        open("%s/import/bedlist_%s.csv" % (i_home,current),"w+").write('\n'.join(generated))
81        return self.accommodation.accommodation_view(beds_generated=beds_generated)
82
83###)
84
85InitializeClass(AccoFolder)
86
87def addAccoFolder(container, id, REQUEST=None, **kw):
88    """Add a AccoFolder."""
89    ob = AccoFolder(id, **kw)
90    return CPSBase_adder(container, ob, REQUEST=REQUEST)
91###)
92
93class AccoHall(CPSDocument): ###(
94    """
95    WAeUP AccoHall containing Departments
96    """
97    meta_type = 'AccoHall'
98    portal_type = meta_type
99    security = ClassSecurityInfo()
100
101    security.declareProtected(View,"Title") ###(
102    def Title(self):
103        """compose title"""
104        content = self.getContent()
105        heading = getattr(content,'heading',None)
106        if heading is None:
107            return self.title
108        return heading
109
110###)
111
112InitializeClass(AccoHall)
113
114def addAccoHall(container, id, REQUEST=None, **kw):
115    """Add a AccoHall."""
116    ob = AccoHall(id, **kw)
117    return CPSBase_adder(container, ob, REQUEST=REQUEST)
118###)
Note: See TracBrowser for help on using the repository browser.