source: products/qSEOptimizer/trunk/skins/qSEOptimizer/2.0-final/listMetaTags.py @ 1

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

Building directory structure

File size: 3.1 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##
10
11from DateTime import DateTime
12from Products.CMFCore.utils import getToolByName
13
14site_props = getToolByName(context, 'portal_properties').site_properties
15exposeDCMetaTags = site_props.getProperty('exposeDCMetaTags',True)
16
17metadataList = [
18    # dublic core accessor name, metadata name
19    ('qSEO_Description', 'description'),
20    ('qSEO_Keywords',    'keywords'),
21    ('qSEO_Robots',      'robots'),
22    ('qSEO_Distribution','distribution'),
23]
24
25returnList = []
26if exposeDCMetaTags: 
27        metadataList.append(('qSEO_Distribution', 'DC.distribution'))
28        metadataList.append(('Description',      'DC.description'))
29        metadataList.append(('Subject',          'DC.subject'))
30        metadataList.append(('Creator',          'DC.creator'))
31        metadataList.append(('Contributors',     'DC.contributors'))
32        metadataList.append(('Publisher',        'DC.publisher'))
33        metadataList.append(('CreationDate',     'DC.date.created'))
34        metadataList.append(('ModificationDate', 'DC.date.modified'))
35        metadataList.append(('Type',             'DC.type'))
36        metadataList.append(('Format',           'DC.format'))
37        metadataList.append(('Language',         'DC.language'))
38        metadataList.append(('Rights',           'DC.rights'))
39
40for accessor, key in metadataList:
41    method = getattr(context, accessor, None)
42    if not callable(method):
43        # ups
44        continue
45
46    # Catch AttributeErrors raised by some AT applications
47    try:
48        value = method()
49    except AttributeError:
50        value = None
51
52    if not value:
53        # no data
54        continue
55    if accessor == 'Publisher' and value == 'No publisher':
56        # No publisher is hardcoded (XXX: still?)
57        continue
58    if same_type(value, ()) or same_type(value, []):
59        # convert a list to a string
60        value = ', '.join(value)
61    returnList.append( (key, value) )
62
63# Portions of following code was copy/pasted from the listMetaTags script from
64# CMFDefault.  This script is licensed under the ZPL 2.0 as stated here:
65# http://www.zope.org/Resources/ZPL
66# Zope Public License (ZPL) Version 2.0
67# This software is Copyright (c) Zope Corporation (tm) and Contributors. All rights reserved.
68created = context.CreationDate()
69
70effective = context.EffectiveDate()
71if effective and effective != 'None':
72    effective = DateTime(effective)
73else:
74    effective = None
75
76expires = context.ExpirationDate()
77if expires and expires != 'None':
78    expires = DateTime(expires)
79else:
80    expires = None
81
82#   Filter out DWIMish artifacts on effective / expiration dates
83eff_str = ( effective and effective.year() > 1000
84                      and effective != created ) and effective.Date() or ''
85exp_str = ( expires and expires.year() < 9000 ) and expires.Date() or ''
86
87if exp_str or exp_str:
88    returnList.append( ( 'DC.date.valid_range'
89                    , '%s - %s' % ( eff_str, exp_str ) ) )
90
91return returnList
Note: See TracBrowser for help on using the repository browser.