source: WAeUP_SRP/base/skins/waeup_utilities/ti_391_resolve.py @ 3013

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

logging messages improved

  • Property svn:keywords set to Id
File size: 2.8 KB
RevLine 
[2605]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
[2609]30students_folder = context.portal_url.getPortalObject().campus.students
[2605]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
[2609]42#query = Eq('portal_type','StudentPersonal')
43#brains = aq_portal(query)
44brains = context.students_catalog()
[2605]45total = len(brains)
46#rwrite("found %d " % total)
47no_email = 0
48edited = 0
49count = 0
[2609]50commit_after = 50
[2618]51logger.info('started to fix %d personal emails' % total)
[2605]52for brain in brains:
53    count += 1
[2609]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:
[2605]58        no_email += 1
59        try:
[2609]60            app_doc = getattr(getattr(students_folder,brain.id),'application').getContent()
61            #rwrite ("%s email = %s" % (brain.getId,doc.email))
[2605]62        except:
[2618]63            logger.info("%s, failed to get application object" % (brain.id,))
[2609]64            continue
65        if not app_doc.app_email or app_doc.app_email.find('@') < 0:
[2618]66            logger.info("%s, both emails (%s, %s) are invalid" % (brain.id,
[2609]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:
[2618]74            logger.info("%s, failed to get personal object" % (brain.id,))
[2609]75            continue
[2618]76        logger.info("%s, setting email from %s to %s" % (brain.id,
[2609]77                                                            per_doc.email,
78                                                            app_doc.app_email))
79        per_doc.edit(mapping={'email': app_doc.app_email})
80        edited += 1
[2605]81    else:
82        #rwrite ("%s email = %s" % (brain.getPath(),doc.email))
83        pass
84    # if count > 2000:
85    #     break
[2618]86logger.info('finished, %d checked, %d edited' % (count,
[2605]87                                               edited,))
88
Note: See TracBrowser for help on using the repository browser.