[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() |
---|
| 25 | |
---|
[575] | 26 | security.declareProtected(View,"Title") |
---|
| 27 | def Title(self): |
---|
| 28 | """compose title""" |
---|
| 29 | return "Accommodation" |
---|
| 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()) |
---|
[404] | 41 | for h in l: |
---|
| 42 | halls.append(h.getObject()) |
---|
| 43 | for hall in halls: |
---|
[623] | 44 | #import pdb;pdb.set_trace() |
---|
[404] | 45 | h = hall.getContent() |
---|
[407] | 46 | reserved = [int(r) for r in h.reserved_rooms.split()] |
---|
[411] | 47 | print h.which_sex |
---|
| 48 | sex = 'male' |
---|
| 49 | if h.which_sex: |
---|
| 50 | sex = 'female' |
---|
[404] | 51 | for block in range(1,int(h.nr_of_blocks)): |
---|
| 52 | for floor in range(1,int(h.nr_of_floors)): |
---|
| 53 | for room in range(1,int(h.rooms_per_floor)): |
---|
| 54 | for bed in 'ABCDEFGH'[:int(h.beds_per_room)]: |
---|
| 55 | room_nr = floor*100 + room |
---|
[623] | 56 | bt = 'xx' |
---|
[407] | 57 | if room_nr in reserved: |
---|
[623] | 58 | bt = "reserved" |
---|
| 59 | elif bed in h.beds_for_fresh: |
---|
[407] | 60 | bt = 'fr' |
---|
| 61 | elif bed in h.beds_for_returning: |
---|
| 62 | bt = 're' |
---|
| 63 | elif bed in h.beds_for_final: |
---|
| 64 | bt = 'fi' |
---|
[575] | 65 | bt = "%(sex)s_%(bt)s" % vars() |
---|
[623] | 66 | uid = '%s_%d_%d_%s' % (hall.getId(),block,room_nr,bed) |
---|
[411] | 67 | print bt,uid |
---|
[623] | 68 | freelist.addRecord(bed = uid, bed_type = bt, student= '') |
---|
| 69 | generated.append('"%(uid)s","%(bt)s"' % vars()) |
---|
| 70 | current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") |
---|
| 71 | open("%s/import/bedlist_%s.csv" % (i_home,current),"w+").write('\n'.join(generated)) |
---|
[407] | 72 | return self.accommodation.academics_contents() |
---|
[152] | 73 | |
---|
[404] | 74 | ###) |
---|
| 75 | |
---|
[103] | 76 | InitializeClass(AccoFolder) |
---|
| 77 | |
---|
| 78 | def addAccoFolder(container, id, REQUEST=None, **kw): |
---|
| 79 | """Add a AccoFolder.""" |
---|
| 80 | ob = AccoFolder(id, **kw) |
---|
| 81 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 82 | ###) |
---|
| 83 | |
---|
[622] | 84 | class AccoHall(CPSDocument): ###( |
---|
[103] | 85 | """ |
---|
[622] | 86 | WAeUP AccoHall containing Departments |
---|
[103] | 87 | """ |
---|
[622] | 88 | meta_type = 'AccoHall' |
---|
[103] | 89 | portal_type = meta_type |
---|
| 90 | security = ClassSecurityInfo() |
---|
[575] | 91 | |
---|
[404] | 92 | security.declareProtected(View,"Title") ###( |
---|
[152] | 93 | def Title(self): |
---|
| 94 | """compose title""" |
---|
| 95 | content = self.getContent() |
---|
| 96 | heading = getattr(content,'heading',None) |
---|
| 97 | if heading is None: |
---|
| 98 | return self.title |
---|
| 99 | return heading |
---|
[404] | 100 | |
---|
| 101 | ###) |
---|
[575] | 102 | |
---|
[622] | 103 | InitializeClass(AccoHall) |
---|
[103] | 104 | |
---|
[622] | 105 | def addAccoHall(container, id, REQUEST=None, **kw): |
---|
| 106 | """Add a AccoHall.""" |
---|
| 107 | ob = AccoHall(id, **kw) |
---|
[103] | 108 | return CPSBase_adder(container, ob, REQUEST=REQUEST) |
---|
| 109 | ###) |
---|