Changeset 3054 for WAeUP_SRP/base/skins


Ignore:
Timestamp:
28 Jan 2008, 13:13:11 (17 years ago)
Author:
joachim
Message:

improve and sanitize code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/skins/waeup_accommodation/getAccoHallInfo.py

    r2845 r3054  
    2626
    2727request = context.REQUEST
    28 
    29 wf = context.portal_workflow
    30 path_info = request.get('PATH_INFO').split('/')
    31 mtool = context.portal_membership
    3228portal_accommodation = context.portal_accommodation
    3329aq_accommodation = portal_accommodation.evalAdvancedQuery
     30aq_students = context.students_catalog.evalAdvancedQuery
    3431info = {}
    35 #dep_id = request.get('PATH_TRANSLATED').split('/')[-2]
    36 dep_id = context.aq_parent.getId()
    3732info['action'] = "%s" % context.absolute_url()
    3833info['choosen_ids'] = request.get('ids',[])
    3934info['doc'] = context.getContent()
    40 bed_types = portal_accommodation.uniqueValuesFor('bed_type')
    4135bt_list = []
    4236bt_names =  context.getBedTypeNames()
    43 res = portal_accommodation.uniqueValuesFor('student')
    44 all_booked = [st for st in res if st and st != 'not_occupied']
     37query = Eq('hall',context.getId())
     38beds = aq_accommodation(query)
     39bed_types = []
     40for bed in beds:
     41    if bed.bed_type not in bed_types:
     42        bed_types += bed.bed_type,
     43bed_type_info = []
    4544booked_list = []
     45booked_mapping = {}
    4646for bt in bed_types:
    47     total = len(portal_accommodation(bed_type=bt,hall=context.getId()))
    48     if total <= 1:
    49         continue
    50     booked = portal_accommodation.searchResults({'bed_type': bt,
    51                                  'student':all_booked,
    52                                  'hall': context.getId()})
    53     bt_list.append({'name': bt_names[bt],
    54                     'total': total,
    55                     'reserved': len(booked),
    56                     })
    57     booked_list.extend(booked)
    58 # query = ~Eq('student','not_occupied')
    59 # beds = aq_accommodation(query,sortSpecs=('bed_type',))
    60 # bt_list = []
    61 # bt_names =  context.getBedTypeNames()
    62 # bt = 'xxx'
    63 # for bed in beds:
    64 #     if bt != bed.bed_type:
    65 #         bt = bed.bed_type
    66 #         total = len(aq_accommodation(Eq('bed_type',bt)))
    67 #         bt_list.append({'name': bt_names[bt],
    68 #                         'total': total,
    69 #                         'reserved': len(booked),
    70 #                        })
    71      
    72 info['bed_types'] = bt_list
    73 res_list = []
     47    total_beds = [b for b in beds if b.bed_type == bt]
     48    booked_beds = 0
     49    for b in total_beds:
     50        if b.student and b.student != context.portal_accommodation.not_occupied:
     51            booked_beds += 1
     52            booked_mapping[b.student] = b
     53    bed_type_info.append({'name': bt_names[bt],
     54                    'total': len(total_beds),
     55                    'reserved': booked_beds,
     56                   })
     57info['bed_types'] = bed_type_info
     58reserved_info = []
    7459students_url = "%s/campus/students" % (context.portal_url())
    75 for sbrain in booked_list:
     60student_records = aq_students(In('id',booked_mapping.keys()))
     61for student_record in student_records:
    7662    d = {}
    77     st = sbrain.student
    78     if not st:
    79         continue
    80     d['student'] = st
    81     d['student_url'] ='%s/%s' % (students_url,st)
    82     bed = context.getFormattedBed(sbrain.bed).split('/')
     63    student_id = student_record.id
     64    d['student'] = student_id
     65    d['student_url'] ='%s/%s' % (students_url,student_id)
     66    bed = context.getFormattedBed(booked_mapping[student_id].bed).split('/')
    8367    d['bed'] = " / ".join(bed[1:])
    84     erg = context.students_catalog(id = st)
    85     if erg:
    86         sd = context.getFormattedStudentEntry(erg[0])
    87         d.update(sd)
    88     else:
    89         #d['student'] = None
    90         d['student_url'] = None
    91         #d['bed'] = None
    92         d['name'] = 'Student record removed'
    93     res_list.append(d)
    94 res_list.sort(cmp_bed)
    95 info['reserved'] = res_list
     68    d.update(context.getFormattedStudentEntry(student_record))
     69    reserved_info.append(d)
     70reserved_info.sort(cmp_bed)
     71info['reserved'] = reserved_info
    9672
    9773return info
Note: See TracChangeset for help on using the changeset viewer.