source: WAeUP_SRP/trunk/skins/waeup_utilities/ti_294_resolve.py @ 5629

Last change on this file since 5629 was 1983, checked in by Henrik Bettermann, 17 years ago

see comment in ticket #294

  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1## Script (Python) "findStudentsWithCourses"
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: ti_294_resolve.py 1983 2007-07-04 07:32:36Z henrik $
11"""
12"""
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18import logging
19logger = logging.getLogger('Skins.ti_294_resolve')
20from Products.AdvancedQuery import Eq, Between, Le,In
21aq_students = context.students_catalog.evalAdvancedQuery
22
23request = context.REQUEST
24session = request.SESSION
25response = request.RESPONSE
26setheader = request.RESPONSE.setHeader
27students = context.portal_url.getPortalObject().campus.students
28#from string import Template
29def rwrite(s):
30    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
31    response.write("%s<br>\n\r" % s)
32
33#logger.info('')
34
35query = In('registered_courses',('',))
36brains = aq_students(query)
37total = len(brains)
38logger.info('found %d students with empty course_result id' % total)
39count = 0
40commit_after = 5000
41todelete = []
42for brain in brains:
43    level_object = None
44    #
45    #set_trace()
46    try:
47        level_object = getattr(getattr(getattr(students,brain.id),'study_course'),brain.level)
48    except:
49        continue
50    ids = level_object.objectIds()
51    logger.info('ids of %s: %s#%s' % (brain.id,list(ids),brain.registered_courses))
52    if '' in ids:
53        todelete.append((brain.id,level_object))
54        rwrite("appended %s" % (brain.id))
55    else:
56        registered_courses = brain.registered_courses
57        registered_courses.remove('')
58        logger.info('object not found, %s' % registered_courses)
59        # the following line is critical (modifying the catalog in a for brain in brains loop)
60        context.students_catalog.modifyRecord(id=brain.id,registered_courses=registered_courses)
61logger.info('todelete %d' % (len(todelete)))
62for brain_id,level_object in todelete:
63    count += 1
64    #set_trace()
65    try:
66        level_object.manage_delObjects(['',])
67        logger.info('deleted course with empty id of %s' % (brain_id))
68        rwrite("%d: deleted empty id in %s" % (count, level_object.absolute_url()))
69    except:
70        logger.info('could not delete course with empty in of %s' % (level_object.absolute_url()))
71        rwrite("%d: could not delete empty id in %s" % (count, level_object.absolute_url()))
72    if count and not count % commit_after:
73        context.waeup_tool.doCommit()
74        logger.info("committed %d transactions" % commit_after)
75logger.info('finished for %d of %d' % (count,total))
76return
77
Note: See TracBrowser for help on using the repository browser.