source: WAeUP_SRP/branches/joachim-event-branch/skins/waeup_utilities/ti_151_resolve.py @ 17388

Last change on this file since 17388 was 1669, checked in by joachim, 18 years ago

merged up to 1664

  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1## Script (Python) "ti_151_resolve"
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_151_resolve.py 1669 2007-04-04 06:31:52Z joachim $
11"""
12resolve ticket #151
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19import logging
20#>>>>>>>>>>>>>>>><
21logger = logging.getLogger('Skins.ti_151_resolve')
22logger.info('already done on 26.3.07 by joachim')
23return
24#<<<<<<<<<<<<<<<<<
25request = context.REQUEST
26session = request.SESSION
27response = request.RESPONSE
28setheader = request.RESPONSE.setHeader
29students = context.portal_url.getPortalObject().campus.students
30#from string import Template
31def rwrite(s):
32    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
33    response.write(s)
34def getObject(outer,object):
35    if outer.hasObject(object):
36        return getattr(outer,object)
37    return None
38
39try:
40    from Products.AdvancedQuery import Eq, Between, Le,In
41    aq_students = context.students_catalog.evalAdvancedQuery
42except:
43    evalAdvancedQuery = None
44
45students_cat = context.students_catalog
46query = Eq('faculty','PSC') & Eq('department','PHY') & In('level',('300','400'))
47brains = aq_students(query)
48#brains = students_cat(faculty = 'PSC',department='PHY', level='400')
49total = 0
50count_ok = 0
51count_nosc = 0
52count_nolevel = 0
53count_level = 0
54count_renamed = 0
55#set_trace()
56#template = Template('"$count","$id","$course"')
57to_rename = []
58for student in brains:
59    student_dict = {}
60    for field in students_cat.schema():
61        student_dict[field] = getattr(student,field)
62    #s = template.substitute(student_dict,count=count,)
63    student_dict['total'] = total
64    while True:
65        if student.course == "BSCINP":
66            student_dict['message'] = "OK"
67            count_ok += 1
68            student_dict['sp_count'] = count_ok
69            s = '"%(total)d","%(sp_count)s","%(id)s","%(course)s","%(message)s",' % student_dict
70            break
71        student_dict['message'] = ""
72        student_obj = getObject(students,student.id)
73        if student_obj is None:
74            student_dict['message'] = "No student object"
75            break
76        study_course_obj = getObject(student_obj,'study_course')
77        if study_course_obj is None:
78            student_dict['message'] = "No study_course object"
79            count_nosc += 1
80            student_dict['sp_count'] = count_nosc
81            break
82        level_obj = getObject(student_obj,student.level)
83        if level_obj:
84            count_level += 1
85            study_course.manage_delObjects((student.level,))
86            student_dict['message'] = "Level deleted"
87            student_dict['sp_count'] = count_level
88        count_renamed += 1
89        to_rename.append(student.id)
90        student_dict['sp_count'] = count_renamed
91        student_dict['message'] = student_dict['message'] + "renamed to BSCINP"
92        study_course_doc = study_course_obj.getContent()
93        study_course_obj.edit(mapping = {'study_course': "BSCINP"})
94        total += 1
95        s = '"%(total)d","%(sp_count)s","%(id)s","%(course)s","%(message)s",' % student_dict
96        rwrite("%s<br />\r\n" %s)
97        break
98    total += 1
99    s = '"%(total)d","%(sp_count)s","%(id)s","%(course)s","%(message)s",' % student_dict
100    rwrite("%s<br />\r\n" %s)
101for sid in to_rename:
102    students_cat.modifyRecord(id = sid,course="BSCINP")
103sum = count_ok + count_nosc + count_nolevel + count_level   
104rwrite("total=%d,sum of below=%d,<br>\r\n correct study_course=%d<br>\r\n no study_course=%d<br>\r\n no level=%d<br>\r\n with level =%d,<br />\n Done" %
105        (total,
106         sum,
107         count_ok,
108         count_nosc,
109         count_nolevel,
110         count_level)
111         )
112
113logger.info("total=%d,sum=%d,ok=%d,no study_course=%d,no level=%d,with level =%d,\n Done" %
114             (total,sum,count_ok,count_nosc,count_nolevel,count_level))
Note: See TracBrowser for help on using the repository browser.