[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 | """ |
---|
| 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','joachim'): |
---|
| 22 | return |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | import logging |
---|
| 26 | import DateTime |
---|
| 27 | logger = logging.getLogger('Skins.ti_391_resolve') |
---|
| 28 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 29 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
[2609] | 30 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
[2605] | 31 | |
---|
| 32 | request = context.REQUEST |
---|
| 33 | session = request.SESSION |
---|
| 34 | response = request.RESPONSE |
---|
| 35 | setheader = request.RESPONSE.setHeader |
---|
| 36 | def 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) |
---|
| 44 | brains = context.students_catalog() |
---|
[2605] | 45 | total = len(brains) |
---|
| 46 | #rwrite("found %d " % total) |
---|
| 47 | no_email = 0 |
---|
| 48 | edited = 0 |
---|
| 49 | count = 0 |
---|
[2609] | 50 | commit_after = 50 |
---|
[2618] | 51 | logger.info('started to fix %d personal emails' % total) |
---|
[2605] | 52 | for 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] | 86 | logger.info('finished, %d checked, %d edited' % (count, |
---|
[2605] | 87 | edited,)) |
---|
| 88 | |
---|