[103] | 1 | #-*- mode: python; mode: fold -*- |
---|
| 2 | from Globals import InitializeClass |
---|
| 3 | from AccessControl import ClassSecurityInfo |
---|
| 4 | |
---|
| 5 | from Products.CMFCore.utils import UniqueObject, getToolByName |
---|
| 6 | from Products.CMFCore.permissions import View |
---|
| 7 | from Products.CMFCore.permissions import ModifyPortalContent |
---|
[575] | 8 | from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder |
---|
| 9 | #from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument |
---|
| 10 | from Products.CPSDocument.CPSDocument import CPSDocument |
---|
| 11 | from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder |
---|
[404] | 12 | from Products.WAeUP_SRP.WAeUPTables import AccommodationTable |
---|
[623] | 13 | import Globals |
---|
| 14 | import DateTime |
---|
| 15 | p_home = Globals.package_home(globals()) |
---|
| 16 | i_home = Globals.INSTANCE_HOME |
---|
[103] | 17 | |
---|
| 18 | class 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] | 85 | InitializeClass(AccoFolder) |
---|
| 86 | |
---|
| 87 | def 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] | 93 | class 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] | 112 | InitializeClass(AccoHall) |
---|
[103] | 113 | |
---|
[622] | 114 | def 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 | ###) |
---|