| 1 | ## Script (Python) "release_bed" |
|---|
| 2 | ##bind container=container |
|---|
| 3 | ##bind context=context |
|---|
| 4 | ##bind namespace= |
|---|
| 5 | ##bind script=script |
|---|
| 6 | ##bind subpath=traverse_subpath |
|---|
| 7 | ##parameters= |
|---|
| 8 | ##title= |
|---|
| 9 | ## |
|---|
| 10 | # $Id: release_bed.py 3406 2008-04-02 07:16:08Z henrik $ |
|---|
| 11 | """ |
|---|
| 12 | release an allocated bed |
|---|
| 13 | """ |
|---|
| 14 | import logging |
|---|
| 15 | logger = logging.getLogger('Skins.release_bed') |
|---|
| 16 | |
|---|
| 17 | request = context.REQUEST |
|---|
| 18 | redirect = request.RESPONSE.redirect |
|---|
| 19 | mtool = context.portal_membership |
|---|
| 20 | wf = context.portal_workflow |
|---|
| 21 | member = mtool.getAuthenticatedMember() |
|---|
| 22 | member_id = str(member) |
|---|
| 23 | path_info = request.get('PATH_INFO').split('/') |
|---|
| 24 | |
|---|
| 25 | if mtool.isAnonymousUser(): |
|---|
| 26 | return None |
|---|
| 27 | students = context.portal_url.getPortalObject().campus.students |
|---|
| 28 | acco_cat = context.portal_accommodation |
|---|
| 29 | #stud_cat = context.students_catalog |
|---|
| 30 | student_id = context.getStudentId() |
|---|
| 31 | try: |
|---|
| 32 | from Products.zdb import set_trace |
|---|
| 33 | except: |
|---|
| 34 | def set_trace(): |
|---|
| 35 | return |
|---|
| 36 | #set_trace() |
|---|
| 37 | if student_id is not None: |
|---|
| 38 | logger.info('%s requests bed_release for %s' % (member_id,student_id)) |
|---|
| 39 | res = acco_cat(student=student_id) |
|---|
| 40 | if len(res) == 0: |
|---|
| 41 | logger.info('no bed of %s found' % (student_id)) |
|---|
| 42 | return redirect("%s/%s" % (students.absolute_url(),student_id)) |
|---|
| 43 | allocated_bed = res[0] |
|---|
| 44 | acco_cat.modifyRecord(bed=allocated_bed.bed,student=acco_cat.not_occupied) |
|---|
| 45 | acco_doc = context.getContent() |
|---|
| 46 | acco_doc.edit(mapping={'bed':"-- cancelled by section officer --",'acco_maint_fee':""}) |
|---|
| 47 | logger.info('%s released bed of %s' % (member_id,student_id)) |
|---|
| 48 | return redirect("%s" % (context.absolute_url())) |
|---|
| 49 | |
|---|