source: WAeUP_SRP/trunk/skins/waeup_utilities/initialize_accommodation_catalog.py @ 5653

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

Implement first part of new accommodation allocation module. This part contains the new student accommodation catalog which replaces the accommodation objects.

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1## Script (Python) "initialize_accommodation_catalog"
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: initialize_accommodation_catalog.py 5614 2010-12-27 07:25:11Z henrik $
11"""
12"""
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18
19mtool = context.portal_membership
20member = mtool.getAuthenticatedMember()
21if str(member) not in ('admin'):
22    return
23
24import logging
25import DateTime
26logger = logging.getLogger('Skins.initializeAccommodationCatalog')
27from Products.AdvancedQuery import Eq, Between, Le,In
28aq_portal = context.portal_catalog_real.evalAdvancedQuery
29wf = context.portal_workflow
30
31logger.info('start')
32count = 0
33not_count = 0
34found = 0
35commit_after = 1000
36accommodation_brains = context.portal_catalog.search({'meta_type': "StudentAccommodation"})
37num_objects = len(accommodation_brains)
38logger.info("found %d StudentAccommodation objects" % num_objects)
39fields = ('acco_maint_date','acco_maint_code','acco_maint_fee','acco_maint_sc_pin','acco_maint_pay_id','acco_res_date','acco_res_sc_pin','bed','session','student_status')
40students_folder = context.portal_url.getPortalObject().campus.students
41
42for i in xrange(num_objects):
43    #set_trace()
44    data = {}
45    a_brain = accommodation_brains[i]
46    a_object = a_brain.getObject()   
47    doc = a_object.getContent()
48    pl = a_brain.getPath().split('/')
49    student_id = pl[-2]   
50    if not getattr(doc,'session',None):
51        student_folder = getattr(students_folder,student_id)
52        student_folder.manage_delObjects('accommodation_final')
53        continue
54    for field in fields:
55        data[field] = getattr(doc,field,None)
56    data['reservation_status'] = wf.getInfoFor(a_object,'review_state',None)
57    data['student_id'] = student_id
58    catkey = student_id + '|' + data['session']
59    data['catkey'] = catkey
60    context.accommodation_catalog.addRecord(**data)
61
62logger.info("finished")
Note: See TracBrowser for help on using the repository browser.