1 | # Script (Python) "listMetaTags" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters= |
---|
8 | ##title=List Dublin Core for '<meta>' tags |
---|
9 | ## |
---|
10 | from Products.CMFCore.utils import getToolByName |
---|
11 | plone_utils = getToolByName(context, 'plone_utils', None) |
---|
12 | site_props = getToolByName(context, 'portal_properties').site_properties |
---|
13 | exposeDCMetaTags = site_props.exposeDCMetaTags |
---|
14 | |
---|
15 | if plone_utils: |
---|
16 | metaTags = plone_utils.listMetaTags(context) |
---|
17 | metadataList = [ |
---|
18 | ('qSEO_Description', 'description'), |
---|
19 | ('qSEO_Keywords', 'keywords'), |
---|
20 | ('qSEO_Robots', 'robots'), |
---|
21 | ('qSEO_Distribution','distribution'), |
---|
22 | ] |
---|
23 | |
---|
24 | if exposeDCMetaTags: |
---|
25 | metadataList.append(('qSEO_Distribution', 'DC.distribution')) |
---|
26 | |
---|
27 | for accessor, key in metadataList: |
---|
28 | method = getattr(context, accessor, None) |
---|
29 | if not callable(method): |
---|
30 | # ups |
---|
31 | continue |
---|
32 | # Catch AttributeErrors raised by some AT applications |
---|
33 | try: |
---|
34 | value = method() |
---|
35 | except AttributeError: |
---|
36 | value = None |
---|
37 | |
---|
38 | if not value: |
---|
39 | # no data |
---|
40 | continue |
---|
41 | if same_type(value, ()) or same_type(value, []): |
---|
42 | # convert a list to a string |
---|
43 | value = ', '.join(value) |
---|
44 | metaTags[key] = value |
---|
45 | |
---|
46 | # Reordering metaTags.items() to have primary metatags first (in specified order) |
---|
47 | # and all other following them (in arbitrary order). |
---|
48 | primary_metatags = ['description', 'keywords'] |
---|
49 | return [(name,metaTags[name]) for name in primary_metatags if name in metaTags.keys()] + \ |
---|
50 | [(name,metaTags[name]) for name in metaTags.keys() if name not in primary_metatags] |
---|