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