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 | """
|
---|
13 | try:
|
---|
14 | from Products.zdb import set_trace
|
---|
15 | except:
|
---|
16 | def set_trace():
|
---|
17 | pass
|
---|
18 |
|
---|
19 | mtool = context.portal_membership
|
---|
20 | member = mtool.getAuthenticatedMember()
|
---|
21 | if str(member) not in ('admin'):
|
---|
22 | return
|
---|
23 |
|
---|
24 | import logging
|
---|
25 | import DateTime
|
---|
26 | logger = logging.getLogger('Skins.initializeAccommodationCatalog')
|
---|
27 | from Products.AdvancedQuery import Eq, Between, Le,In
|
---|
28 | aq_portal = context.portal_catalog_real.evalAdvancedQuery
|
---|
29 | wf = context.portal_workflow
|
---|
30 |
|
---|
31 | logger.info('start')
|
---|
32 | count = 0
|
---|
33 | not_count = 0
|
---|
34 | found = 0
|
---|
35 | commit_after = 1000
|
---|
36 | accommodation_brains = context.portal_catalog.search({'meta_type': "StudentAccommodation"})
|
---|
37 | num_objects = len(accommodation_brains)
|
---|
38 | logger.info("found %d StudentAccommodation objects" % num_objects)
|
---|
39 | fields = ('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')
|
---|
40 | students_folder = context.portal_url.getPortalObject().campus.students
|
---|
41 |
|
---|
42 | for 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 |
|
---|
62 | logger.info("finished")
|
---|