| 1 | ## Script (Python) "getAccommodationRecords"
|
|---|
| 2 | ##bind container=container
|
|---|
| 3 | ##bind context=context
|
|---|
| 4 | ##bind namespace=
|
|---|
| 5 | ##bind script=script
|
|---|
| 6 | ##bind subpath=traverse_subpath
|
|---|
| 7 | ##parameters=student_id=None
|
|---|
| 8 | ##title=
|
|---|
| 9 | ##
|
|---|
| 10 | # $Id: getAccommodationRecords.py 5795 2011-03-05 12:34:09Z henrik $
|
|---|
| 11 | """
|
|---|
| 12 | """
|
|---|
| 13 | import logging
|
|---|
| 14 | logger = logging.getLogger('Skins.getAccommodationRecords')
|
|---|
| 15 | import DateTime
|
|---|
| 16 |
|
|---|
| 17 | pprops = context.portal_properties
|
|---|
| 18 | booking_disabled = not pprops.enable_acco_booking
|
|---|
| 19 |
|
|---|
| 20 | request = context.REQUEST
|
|---|
| 21 | mtool = context.portal_membership
|
|---|
| 22 | wf = context.portal_workflow
|
|---|
| 23 | member = mtool.getAuthenticatedMember()
|
|---|
| 24 | member_id = str(member)
|
|---|
| 25 | path_info = request.get('PATH_INFO').split('/')
|
|---|
| 26 | portal_session = context.getSessionId()[0]
|
|---|
| 27 |
|
|---|
| 28 | if mtool.isAnonymousUser():
|
|---|
| 29 | return None
|
|---|
| 30 | info = {}
|
|---|
| 31 | if student_id is None:
|
|---|
| 32 | requested_id = context.getStudentId()
|
|---|
| 33 | if requested_id and not context.isStaff() and member_id != requested_id:
|
|---|
| 34 | logger.info('%s tried to access %s' % (member_id,requested_id))
|
|---|
| 35 | return None
|
|---|
| 36 | elif context.isStaff():
|
|---|
| 37 | student_id = requested_id
|
|---|
| 38 | else:
|
|---|
| 39 | student_id = member_id
|
|---|
| 40 | student_record = context.students_catalog.getRecordByKey(student_id)
|
|---|
| 41 | if student_record is None:
|
|---|
| 42 | logger.info('%s not found in students_catalog' % student_id)
|
|---|
| 43 | return None
|
|---|
| 44 |
|
|---|
| 45 | info['is_so'] = context.isSectionOfficer()
|
|---|
| 46 | info['is_student'] = context.isStudent()
|
|---|
| 47 | info['student_name'] = student_record.name
|
|---|
| 48 | student_path = "%s/campus/students/%s" % (context.portal_url(),student_id)
|
|---|
| 49 | accommodation_records = context.accommodation_catalog(student_id = student_id)
|
|---|
| 50 | accommodations = []
|
|---|
| 51 | for ar in accommodation_records:
|
|---|
| 52 | row = {}
|
|---|
| 53 | row['sort_param'] = ar.session[-2:] # in 2006 we used the session attribute was 2006 and not 06
|
|---|
| 54 | row['session'] = ar.session
|
|---|
| 55 | row['bed'] = ar.bed
|
|---|
| 56 | row['reservation_status'] = ar.reservation_status
|
|---|
| 57 | row['paid'] = ar.reservation_status == 'maintenance_fee_paid'
|
|---|
| 58 | row['current_unpaid'] = not row['paid'] and ar.session == portal_session and \
|
|---|
| 59 | student_record.review_state in ('cleared_and_validated',
|
|---|
| 60 | 'school_fee_paid',
|
|---|
| 61 | 'courses_registered',
|
|---|
| 62 | 'courses_validated',)
|
|---|
| 63 | row['url'] = student_path
|
|---|
| 64 | row['cancellation_allowed'] = info['is_so'] and ar.session == portal_session
|
|---|
| 65 | row['relocation_allowed'] = info['is_so'] and ar.session == portal_session
|
|---|
| 66 | accommodations.append(row)
|
|---|
| 67 |
|
|---|
| 68 | accommodations.sort(cmp=lambda x,y: cmp(x['sort_param'],y['sort_param']))
|
|---|
| 69 |
|
|---|
| 70 | info['accommodations'] = accommodations
|
|---|
| 71 |
|
|---|
| 72 | as = context.getAccommodationStatus()
|
|---|
| 73 | info['booking_allowed'] = as['booking_allowed']
|
|---|
| 74 | info['booking_disabled'] = as['booking_disabled']
|
|---|
| 75 |
|
|---|
| 76 | return info
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | |
|---|