source: WAeUP_SRP/base/skins/waeup_utilities/removeImagesFromZODB.py @ 3427

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

remove all passport pictures from ZODB

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1## Script (Python) "writeStudentImages"
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: removeImagesFromZODB.py 2419 2007-10-22 19:37:42Z 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.removeImagesFromZODB')
28
29request = context.REQUEST
30session = request.SESSION
31response = request.RESPONSE
32setheader = request.RESPONSE.setHeader
33def rwrite(s):
34    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
35    response.write("%s<br>\n\r" % s)
36
37#logger.info('')
38students = context.students_catalog()
39starttime = DateTime.DateTime()
40logger.info("Start removing %d student images" % len(students))
41count = 0
42chunk = 50
43stool = context.portal_schemas
44schemas = ['student_application',
45           #'student_clearance',
46          ]
47students_folder = context.portal_url.getPortalObject().campus.students
48image_keys = {}
49for schema_id in schemas:
50    schema = getattr(stool,schema_id)
51    image_keys[schema_id] = [key for key in schema.keys()
52                             if schema[key].meta_type == "CPS Image Field"]
53for student in students:
54    count += 1
55    if count and not count % chunk:
56        logger.info("removed %d of %d student images " % (count,len(students)))
57        context.waeup_tool.doCommit()
58    for schema_id in schemas:
59        try:
60            doc_id = getattr(getattr(students_folder,student.id),
61                          schema_id[len('student_'):]).getContent().getId()
62        except:
63            continue
64        doc = context.portal_repository[doc_id]
65        ids = [key for key in image_keys[schema_id]
66               if key in doc.objectIds()]
67        if not ids:
68            continue
69        try:
70            doc.manage_delObjects(ids)
71            logger.info("removed %s images " % (student.id))
72        except:
73            set_trace()
74            logger.info("!!!!!!!could not remove  %s images " % (student.id))
75logger.info("Finished removing %d student images" % len(students))
Note: See TracBrowser for help on using the repository browser.