source: WAeUP_SRP/trunk/skins/waeup_utilities/ti_391_resolve.py @ 5066

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

logging messages improved

  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1## Script (Python) "ti_391_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_391_resolve.py 2618 2007-11-09 22:38:22Z 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','joachim'):
22    return
23
24
25import logging
26import DateTime
27logger = logging.getLogger('Skins.ti_391_resolve')
28from Products.AdvancedQuery import Eq, Between, Le,In
29aq_portal = context.portal_catalog_real.evalAdvancedQuery
30students_folder = context.portal_url.getPortalObject().campus.students
31
32request = context.REQUEST
33session = request.SESSION
34response = request.RESPONSE
35setheader = request.RESPONSE.setHeader
36def rwrite(s):
37    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
38    response.write("%s<br>\n\r" % s)
39
40#logger.info('')
41
42#query = Eq('portal_type','StudentPersonal')
43#brains = aq_portal(query)
44brains = context.students_catalog()
45total = len(brains)
46#rwrite("found %d " % total)
47no_email = 0
48edited = 0
49count = 0
50commit_after = 50
51logger.info('started to fix %d personal emails' % total)
52for brain in brains:
53    count += 1
54    if no_email and not no_email % commit_after:
55        context.waeup_tool.doCommit()
56        logger.info("Committing %s transactions, total %s" % (commit_after,count))
57    if not brain.email or brain.email.find('@') < 0:
58        no_email += 1
59        try:
60            app_doc = getattr(getattr(students_folder,brain.id),'application').getContent()
61            #rwrite ("%s email = %s" % (brain.getId,doc.email))
62        except:
63            logger.info("%s, failed to get application object" % (brain.id,))
64            continue
65        if not app_doc.app_email or app_doc.app_email.find('@') < 0:
66            logger.info("%s, both emails (%s, %s) are invalid" % (brain.id,
67                                                              app_doc.app_email,
68                                                              brain.email))
69            continue
70        try:
71            per_doc = getattr(getattr(students_folder,brain.id),'personal').getContent()
72            #rwrite ("%s email = %s" % (brain.getId,doc.email))
73        except:
74            logger.info("%s, failed to get personal object" % (brain.id,))
75            continue
76        logger.info("%s, setting email from %s to %s" % (brain.id,
77                                                            per_doc.email,
78                                                            app_doc.app_email))
79        per_doc.edit(mapping={'email': app_doc.app_email})
80        edited += 1
81    else:
82        #rwrite ("%s email = %s" % (brain.getPath(),doc.email))
83        pass
84    # if count > 2000:
85    #     break
86logger.info('finished, %d checked, %d edited' % (count,
87                                               edited,))
88
Note: See TracBrowser for help on using the repository browser.