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
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
[623]13import Globals
14import DateTime
15p_home = Globals.package_home(globals())
16i_home = Globals.INSTANCE_HOME
[103]17
18class AccoFolder(CPSDocument): ###(
19    """
[575]20    WAeUP AccoFolder containing Accommodation halls
[103]21    """
22    meta_type = 'AccoFolder'
23    portal_type = meta_type
24    security = ClassSecurityInfo()
[630]25
[575]26    security.declareProtected(View,"Title")
27    def Title(self):
28        """compose title"""
[630]29        return "Accommodation Section"
[575]30
[404]31    security.declareProtected(ModifyPortalContent,"generateFreeBedsList") ###(
32    def generateFreeBedsList(self):
33        """
34        generate the free Bedslist.
35        """
[623]36        freelist = self.portal_accommodation
37        l = self.portal_catalog({'meta_type': "AccoHall"})
[404]38        halls = []
[623]39        generated = []
40        generated.append('"Bed","BedType","Student"' % vars())
[626]41        beds_generated = []
[404]42        for h in l:
43            halls.append(h.getObject())
44        for hall in halls:
[623]45            #import pdb;pdb.set_trace()
[404]46            h = hall.getContent()
[626]47            hall_gen = {}
[630]48            hall_gen['name'] = hall.Title
[626]49            count = 0
[407]50            reserved = [int(r) for r in h.reserved_rooms.split()]
[411]51            sex = 'male'
52            if h.which_sex:
53                sex = 'female'
[627]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):
[404]57                        for bed in 'ABCDEFGH'[:int(h.beds_per_room)]:
58                            room_nr = floor*100 + room
[623]59                            bt = 'xx'
[407]60                            if room_nr in reserved:
[623]61                                bt = "reserved"
62                            elif bed in h.beds_for_fresh:
[407]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'
[575]68                            bt = "%(sex)s_%(bt)s" % vars()
[623]69                            uid = '%s_%d_%d_%s' % (hall.getId(),block,room_nr,bed)
[626]70                            try:
[627]71                                freelist.addRecord(bed = uid, bed_type = bt,hall = hall.getId())
[626]72                                count +=1
73                                generated.append('"%(uid)s","%(bt)s"' % vars())
74                            except ValueError:
[627]75                                #freelist.modifyRecord(bed = uid, bed_type = bt,hall =hall.getId())
[626]76                                pass
77            hall_gen['count']= count
78            beds_generated.append(hall_gen)
[623]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))
[626]81        return self.accommodation.accommodation_view(beds_generated=beds_generated)
[152]82
[404]83###)
84
[103]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
[622]93class AccoHall(CPSDocument): ###(
[103]94    """
[622]95    WAeUP AccoHall containing Departments
[103]96    """
[622]97    meta_type = 'AccoHall'
[103]98    portal_type = meta_type
99    security = ClassSecurityInfo()
[575]100
[404]101    security.declareProtected(View,"Title") ###(
[152]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
[404]109
110###)
[575]111
[622]112InitializeClass(AccoHall)
[103]113
[622]114def addAccoHall(container, id, REQUEST=None, **kw):
115    """Add a AccoHall."""
116    ob = AccoHall(id, **kw)
[103]117    return CPSBase_adder(container, ob, REQUEST=REQUEST)
118###)
Note: See TracBrowser for help on using the repository browser.