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