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 | """ |
---|
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 | import logging |
---|
25 | import DateTime |
---|
26 | logger = logging.getLogger('Skins.fillApplicationCategory') |
---|
27 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
28 | #aq_students = context.students_catalog.evalAdvancedQuery |
---|
29 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
30 | #students_folder = context.portal_url.getPortalObject().campus.students |
---|
31 | |
---|
32 | request = context.REQUEST |
---|
33 | session = request.SESSION |
---|
34 | response = request.RESPONSE |
---|
35 | setheader = request.RESPONSE.setHeader |
---|
36 | logger.info('start') |
---|
37 | count = 0 |
---|
38 | not_count = 0 |
---|
39 | found = 0 |
---|
40 | commit_after = 1000 |
---|
41 | #certificates = context.getCertificatesDict() |
---|
42 | certificates = context.portal_catalog.search({'meta_type': "Certificate"}) |
---|
43 | logger.info("found %d certificates" % len(certificates)) |
---|
44 | cat = {'cos': 'basic', |
---|
45 | 'cos_cest': 'cest', |
---|
46 | 'cos_sandwich': 'sandwich', |
---|
47 | } |
---|
48 | to_change = {} |
---|
49 | for 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,)) |
---|
65 | for 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'])) |
---|
69 | logger.info("%d cert codes found, %d not found in vocabularies" % (count,not_count)) |
---|