source: products/qSEOptimizer/tags/0.5.3/skins/qSEOptimizer/2.1.1/listMetaTags.py @ 1

Last change on this file since 1 was 1, checked in by myroslav, 18 years ago

Building directory structure

File size: 1.7 KB
Line 
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##
10from Products.CMFCore.utils import getToolByName
11plone_utils = getToolByName(context, 'plone_utils', None)
12site_props = getToolByName(context, 'portal_properties').site_properties
13exposeDCMetaTags = site_props.exposeDCMetaTags
14
15if 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]
Note: See TracBrowser for help on using the repository browser.