#-*- mode: python; mode: fold -*- from Globals import InitializeClass from AccessControl import ClassSecurityInfo from Products.CMFCore.utils import UniqueObject, getToolByName from Products.CMFCore.permissions import View from Products.CMFCore.permissions import ModifyPortalContent from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder #from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument from Products.CPSDocument.CPSDocument import CPSDocument from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder from Products.WAeUP_SRP.WAeUPTables import AccommodationTable import Globals import DateTime import re p_home = Globals.package_home(globals()) i_home = Globals.INSTANCE_HOME class AccoFolder(CPSDocument): ###( """ WAeUP AccoFolder containing Accommodation halls """ meta_type = 'AccoFolder' portal_type = meta_type security = ClassSecurityInfo() security.declareProtected(View,"Title") def Title(self): """compose title""" return "Accommodation Section" security.declareProtected(ModifyPortalContent,"generateFreeBedsList") ###( def generateFreeBedsList(self): """ generate the free Bedslist. """ freelist = self.portal_accommodation l = self.portal_catalog({'meta_type': "AccoHall"}) halls = [] generated = [] generated.append('"Bed","BedType","Student"' % vars()) beds_generated = [] for h in l: halls.append(h.getObject()) for hall in halls: #import pdb;pdb.set_trace() h = hall.getContent() hall_gen = {} hall_gen['name'] = hall.Title count = 0 #reserved = [int(r) for r in h.reserved_rooms.split(',')] reserved = [int(r) for r in re.split(',|\.| ',h.reserved_rooms) if not re.search(r'\D',r) and r] sex = 'male' if h.which_sex: sex = 'female' for block in range(1,int(h.nr_of_blocks)+1): for floor in range(1,int(h.nr_of_floors)+1): for room in range(1,int(h.rooms_per_floor)+1): for bed in 'ABCDEFGH'[:int(h.beds_per_room)]: room_nr = floor*100 + room bt = 're' if room_nr in reserved: bt = "reserved" elif bed in h.beds_for_fresh: bt = 'fr' #elif bed in h.beds_for_returning: # bt = 're' elif bed in h.beds_for_final: bt = 'fi' bt = "%(sex)s_%(bt)s" % vars() uid = '%s_%d_%d_%s' % (hall.getId(),block,room_nr,bed) try: freelist.addRecord(bed = uid, bed_type = bt,hall = hall.getId()) count +=1 generated.append('"%(uid)s","%(bt)s"' % vars()) except ValueError: #freelist.modifyRecord(bed = uid, bed_type = bt,hall =hall.getId()) pass hall_gen['count']= count beds_generated.append(hall_gen) current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") open("%s/import/bedlist_%s.csv" % (i_home,current),"w+").write('\n'.join(generated)) return self.accommodation.acco_folder_view(beds_generated=beds_generated) ###) InitializeClass(AccoFolder) def addAccoFolder(container, id, REQUEST=None, **kw): """Add a AccoFolder.""" ob = AccoFolder(id, **kw) return CPSBase_adder(container, ob, REQUEST=REQUEST) ###) class AccoHall(CPSDocument): ###( """ WAeUP AccoHall containing Departments """ meta_type = 'AccoHall' portal_type = meta_type security = ClassSecurityInfo() security.declareProtected(View,"Title") ###( def Title(self): """compose title""" content = self.getContent() heading = getattr(content,'heading',None) if heading is None: return self.title return heading ###) InitializeClass(AccoHall) def addAccoHall(container, id, REQUEST=None, **kw): """Add a AccoHall.""" ob = AccoHall(id, **kw) return CPSBase_adder(container, ob, REQUEST=REQUEST) ###)