source: products/qSEOptimizer/tags/0.3.2rc1/skins/qSEOptimizer/2.0-final/listMetaTags.py @ 1

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