Changeset 1313 in products for quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/__init__.py
- Timestamp:
- Sep 18, 2009 5:29:41 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/__init__.py
r1312 r1313 1 1 from AccessControl import allow_module 2 from util import SortedDict 2 from zope.component import queryMultiAdapter 3 3 4 from Acquisition import aq_inner 4 5 from DateTime import DateTime 5 6 6 7 from Products.CMFCore.utils import getToolByName 8 9 from quintagroup.seoptimizer.interfaces import IKeywords, IMappingMetaTags 10 from quintagroup.seoptimizer.util import SortedDict 7 11 8 12 allow_module('quintagroup.seoptimizer.util') … … 18 22 19 23 20 21 24 if _present: 22 25 old_lmt = PloneTool.listMetaTags … … 25 28 """Lists meta tags helper. 26 29 27 Creates a mapping of meta tags -> values for the listMetaTags script.30 Creates a mapping of meta tags. 28 31 """ 29 result = {} 32 33 from quintagroup.seoptimizer.browser.interfaces import IPloneSEOLayer 34 if not IPloneSEOLayer.providedBy(self.REQUEST): 35 return old_lmt(getToolByName(self, 'plone_utils'), context) 36 37 result = SortedDict() 30 38 site_props = getToolByName(self, 'portal_properties').site_properties 31 39 use_all = site_props.getProperty('exposeDCMetaTags', None) 32 40 41 seo_context = queryMultiAdapter((context, self.REQUEST), name='seo_context') 42 adapter = IMappingMetaTags(context, None) 43 mapping_metadata = adapter and adapter.getMappingMetaTags() or SortedDict() 44 33 45 if not use_all: 34 metadata_names = {'Description': METADATA_DCNAME['Description']} 46 metadata_names = mapping_metadata.has_key('DC.description') and {'DC.description': mapping_metadata['DC.description']} or SortedDict() 47 if mapping_metadata.has_key('description'): 48 metadata_names['description'] = mapping_metadata['description'] 35 49 else: 36 metadata_names = METADATA_DCNAME50 metadata_names = mapping_metadata 37 51 38 for accessor, key in metadata_names.items(): 39 method = getattr(aq_inner(context).aq_explicit, accessor, None) 52 for key, accessor in metadata_names.items(): 53 if accessor == 'seo_keywords': 54 # Set the additional matching keywords, if any 55 adapter = IKeywords(context, None) 56 if adapter is not None: 57 keywords = adapter.listKeywords() 58 if keywords: 59 result['keywords'] = keywords 60 continue 61 62 method = getattr(seo_context, accessor, None) 63 if method is None: 64 method = getattr(aq_inner(context).aq_explicit, accessor, None) 65 40 66 if not callable(method): 41 67 continue … … 57 83 value = ', '.join(value) 58 84 59 # Exclusion meta tag description and keywords 60 # # Special cases 61 # if accessor == 'Description': 62 # result['description'] = value 63 # elif accessor == 'Subject': 64 # result['keywords'] = value 85 # Special cases 86 if accessor == 'Description' and not (result.has_key('description') or metadata_names.has_key('description')): 87 result['description'] = value 88 elif accessor == 'Subject' and not (result.has_key('keywords') or metadata_names.has_key('keywords')): 89 result['keywords'] = value 65 90 66 if use_all:91 if accessor not in ('Description', 'Subject'): 67 92 result[key] = value 68 93 … … 104 129 result['DC.date.valid_range'] = '%s - %s' % (eff_str, exp_str) 105 130 131 # add custom meta tags (added from qseo tab by user) for given context and default from configlet 132 custom_meta_tags = seo_context and seo_context.seo_customMetaTags() or [] 133 for tag in custom_meta_tags: 134 if tag['meta_content']: 135 result[tag['meta_name']] = tag['meta_content'] 136 106 137 return result 107 138
Note: See TracChangeset
for help on using the changeset viewer.