[3464] | 1 | ## Script (Python) "ti_531_resolve" |
---|
[3444] | 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_531_resolve.py 3464 2008-04-22 05:29:38Z 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_531_resolve') |
---|
| 28 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 29 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
| 30 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
| 31 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
| 32 | |
---|
| 33 | request = context.REQUEST |
---|
| 34 | session = request.SESSION |
---|
| 35 | response = request.RESPONSE |
---|
| 36 | setheader = request.RESPONSE.setHeader |
---|
| 37 | count = 0 |
---|
| 38 | found = 0 |
---|
| 39 | not_deleted = 0 |
---|
[3449] | 40 | commit_after = 200 |
---|
[3444] | 41 | logger.info('start') |
---|
| 42 | students = context.students_catalog() |
---|
| 43 | pumes = aq_portal(Eq('portal_type','StudentPume')) |
---|
| 44 | total = len(pumes) |
---|
| 45 | logger.info('found %d Pume objects' % total) |
---|
| 46 | for pume in pumes: |
---|
| 47 | student_id = pume.getPath().split('/')[-2] |
---|
| 48 | student_object = getattr(students_folder,student_id) |
---|
[3449] | 49 | if count and not count % commit_after: |
---|
| 50 | context.waeup_tool.doCommit() |
---|
| 51 | logger.info("commiting %d transaction of %d" % (commit_after,count)) |
---|
[3444] | 52 | try: |
---|
| 53 | getattr(student_object,manage_delObjects,'') |
---|
| 54 | except: |
---|
| 55 | student_object.manage_permission("Delete objects",roles=['Manager',]) |
---|
| 56 | try: |
---|
| 57 | student_object.manage_delObjects('pume',) |
---|
| 58 | count += 1 |
---|
| 59 | logger.info('deleted Pume object of %s %d/%d' % (student_id,count,total)) |
---|
| 60 | except: |
---|
| 61 | student_object.manage_permission("Delete objects",roles=['Manager',]) |
---|
| 62 | not_deleted += 1 |
---|
| 63 | logger.info('could not delete Pume object of %s %d' % (student_id,not_deleted)) |
---|
| 64 | logger.info('finished deleting %d not deleted %d' % (count,not_deleted)) |
---|
[3464] | 65 | |
---|
| 66 | |
---|