source: WAeUP_SRP/trunk/skins/waeup_accommodation/allocate_reserved_bed.py @ 17328

Last change on this file since 17328 was 5653, checked in by Henrik Bettermann, 14 years ago

Enable allocation of reserved bed spaces in SSE hostels (with special handling).

  • Property svn:keywords set to Id
File size: 5.4 KB
Line 
1##parameters=REQUEST
2# $Id: allocate_reserved_bed.py 5653 2011-01-21 12:16:53Z henrik $
3"""
4process the the accommodation reservation
5"""
6import DateTime
7current = DateTime.DateTime()
8pr = context.portal_registration
9wftool = context.portal_workflow
10lt = context.portal_layouts
11mtool = context.portal_membership
12member = mtool.getAuthenticatedMember()
13portal_acco_cat = context.portal_accommodation
14import logging
15logger = logging.getLogger('Skins.allocate_reserved_bed')
16
17release = REQUEST.has_key("release")
18allocate = REQUEST.has_key("allocate")
19validate = release or (allocate and REQUEST.get("allocate").startswith('Allocate'))
20mode = 'create'
21d = {}
22rendered,psm,ds = lt.renderLayout(layout_id= 'acco_bed_booking',
23                      schema_id= 'acco_bed_booking',
24                      context=context,
25                      mapping=validate and REQUEST,
26                      ob=d,
27                      layout_mode='edit',
28                      commit = False
29                      )
30if psm == 'invalid':
31    psm = "Please correct your input."
32    return context.allocate_reserved_bed_form(rendered = rendered,
33                                 psm = psm,
34                                 #psm = "%s, %s" % (psm,ds),
35                                 mode = mode,
36                                 formaction = "allocate_reserved_bed",
37                                 button = "Allocate Bed",
38                                 ds = ds,
39                                 )
40elif psm == '':
41    return context.allocate_reserved_bed_form(rendered = rendered,
42                                 psm = psm,
43                                 mode = mode,
44                                 formaction = "allocate_reserved_bed",
45                                 button = "Allocate Bed",
46                                 ds = ds,
47                                 )
48elif psm == 'valid':
49    pass
50#from Products.zdb import set_trace;set_trace()
51hall_id = context.getId()
52doc = context.getContent()
53student = ds.get('student')
54sid = ds.get('student_id')
55br = ds.get('block_room')
56block = br[0]
57bl = ds.get('bed_letter')
58bid = "%s_%s_%s" % (hall_id,br,bl)
59res = portal_acco_cat(bed = bid)
60already = portal_acco_cat(student=sid)
61psm = ''
62
63while True:
64    if not res:
65        psm = "No bed with id %s" % bid
66        break
67    bed_brain = res[0]
68    if allocate:
69        if already:
70            psm = "Student %s has already booked bed %s. This booking must be cancelled first." % (sid, already[0].bed)
71            break
72        if not "reserved" in bed_brain.bed_type:
73            psm = "%s is not a reserved bed" % bid
74            break
75        if bed_brain.student and bed_brain.student != portal_acco_cat.not_occupied:
76            psm = "Bed %s already reserved for %s" % (bid,bed_brain.student)
77            break
78        if student.sex and not block in doc.blocks_for_female:
79            psm = "Sex does not match %s" % bid
80            break
81    if release:
82        if not already:
83            psm = "Student %s has no bed" % (sid)
84            break
85        already_brain = already[0]
86        if already_brain.bed != bid:
87            psm = "Student %s has booked bed %s. Bed can only be released by cancelling the booking record." % (sid, already_brain.bed)
88            break       
89        if not bed_brain.student:
90            psm = "Bed %s not allocated" % (bid)
91            break
92        accommodation_records = context.accommodation_catalog(student_id = sid, session = context.getSessionId()[0],reservation_status = 'maintenance_fee_paid')
93        if accommodation_records:
94            psm = "Student %s has already paid for bed %s" % (sid, bid)
95            break
96        if not "reserved" in bed_brain.bed_type:
97            psm = "%s is not a reserved bed" % bid
98            break
99    break
100
101if psm != '':
102    return context.allocate_reserved_bed_form(rendered = rendered,
103                                 psm = psm,
104                                 mode = mode,
105                                 ds = ds,
106                                 formaction = "allocate_reserved_bed",
107                                 button = "Allocate Bed",
108                                 )
109if allocate:
110    portal_acco_cat.modifyRecord(bed = bid, student = sid)
111    accommodation_records = context.accommodation_catalog(student_id = sid, session = context.getSessionId()[0])
112    if accommodation_records:
113        d = {}
114        d['bed'] = bid
115        d['catkey'] = sid + '|' + context.getSessionId()[0]
116        context.accommodation_catalog.modifyRecord(**d)       
117    logger.info('%s booked reserved bed %s for %s' % (member,bid,sid))
118    psm = "Bed %s reserved for %s %s" % (bid,sid,student.name)
119elif release:
120    accommodation_records = context.accommodation_catalog(student_id = sid, session = context.getSessionId()[0])
121    if accommodation_records and accommodation_records[0].bed == bid:
122        psm = "Removing of %s from bed %s failed. The booking record must be cancelled first." % (student.name,bid)
123    else:
124        portal_acco_cat.modifyRecord(bed=bid,student='')
125        logger.info('%s released bed %s booked by %s' % (member,bid,sid))
126        psm = "%s removed from %s" % (student.name,bid)
127
128mode = 'view'
129return context.allocate_reserved_bed_form(rendered = "",
130                                 psm = psm,
131                                 mode = mode,
132                                 formaction = "allocate_reserved_bed",
133                                 button = "Next Reservation",
134                                 ds = ds,
135                                 )
136
Note: See TracBrowser for help on using the repository browser.