source: WAeUP_SRP/trunk/skins/waeup_utilities/fillApplicationCategory.py @ 5178

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

change from upper to lower case keys

fillApplicationCategory.py: improve logging

enable export and import of application_category field

remove vocabulary property from layouts

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1## Script (Python) "fillApplicationCategory"
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: fillApplicationCategory.py 3438 2008-04-16 07:04:19Z 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
24import logging
25import DateTime
26logger = logging.getLogger('Skins.fillApplicationCategory')
27from Products.AdvancedQuery import Eq, Between, Le,In
28#aq_students = context.students_catalog.evalAdvancedQuery
29aq_portal = context.portal_catalog_real.evalAdvancedQuery
30#students_folder = context.portal_url.getPortalObject().campus.students
31
32request = context.REQUEST
33session = request.SESSION
34response = request.RESPONSE
35setheader = request.RESPONSE.setHeader
36logger.info('start')
37count = 0
38not_count = 0
39found = 0
40commit_after = 1000
41#certificates = context.getCertificatesDict()
42certificates = context.portal_catalog.search({'meta_type': "Certificate"})
43logger.info("found %d certificates" % len(certificates))
44cat = {'cos': 'basic',
45       'cos_cest': 'cest',
46       'cos_sandwich': 'sandwich',
47       }
48to_change = {}
49for cert in certificates:
50    found = []
51    for v in ('cos','cos_cest','cos_sandwich'):
52        voc = getattr(context.portal_vocabularies,v)
53        if cert.id in voc.keys():
54            found += v,
55    if found:
56        d = {}
57        d['application_category'] = cat[found[0]]
58        d['cert_doc'] = cert.getObject().getContent()
59        to_change[cert.id] = d
60        logger.info("%s in %s" % (cert.id,','.join(found)))
61        count += 1
62    else:
63        not_count += 1
64        logger.info("%s not in vocabularies" % (cert.id,))
65for cert,d in to_change.items():
66    d['cert_doc'].edit(mapping = d)
67    logger.info("set application_category of %s to %s" %
68               (cert,d['application_category']))
69logger.info("%d cert codes found, %d not found in vocabularies" % (count,not_count))
Note: See TracBrowser for help on using the repository browser.