Changeset 1776 in products
- Timestamp:
- Feb 18, 2010 1:39:07 PM (14 years ago)
- Location:
- quintagroup.seoptimizer/branches/refactoring2.3.0
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/__init__.py
r1624 r1776 1 1 from AccessControl import allow_module 2 from zope.component import queryMultiAdapter3 2 from zope.i18nmessageid import MessageFactory 4 5 from Acquisition import aq_inner6 from DateTime import DateTime7 8 from Products.CMFCore.utils import getToolByName9 10 from quintagroup.seoptimizer.interfaces import IMetaKeywords, IMappingMetaTags11 from quintagroup.seoptimizer.util import SortedDict12 3 13 4 SeoptimizerMessageFactory = MessageFactory('quintagroup.seoptimizer') 14 5 15 6 allow_module('quintagroup.seoptimizer.util') 16 qSEO_globals = globals()17 18 19 try:20 from Products.CMFPlone.PloneTool import PloneTool, METADATA_DCNAME, \21 FLOOR_DATE, CEILING_DATE22 _present = hasattr(PloneTool, "listMetaTags")23 except ImportError:24 _present = False25 26 27 if _present:28 old_lmt = PloneTool.listMetaTags29 30 def listMetaTags(self, context):31 """Lists meta tags helper.32 33 Creates a mapping of meta tags.34 """35 36 from quintagroup.seoptimizer.browser.interfaces import IPloneSEOLayer37 if not IPloneSEOLayer.providedBy(self.REQUEST):38 return old_lmt(getToolByName(self, 'plone_utils'), context)39 40 result = SortedDict()41 site_props = getToolByName(self, 'portal_properties').site_properties42 use_all = site_props.getProperty('exposeDCMetaTags', None)43 44 seo_context = queryMultiAdapter((context, self.REQUEST), name='seo_context')45 adapter = IMappingMetaTags(context, None)46 mapping_metadata = adapter and adapter.getMappingMetaTags() or SortedDict()47 48 if not use_all:49 metadata_names = mapping_metadata.has_key('DC.description') and {'DC.description': mapping_metadata['DC.description']} or SortedDict()50 if mapping_metadata.has_key('description'):51 metadata_names['description'] = mapping_metadata['description']52 else:53 metadata_names = mapping_metadata54 55 for key, accessor in metadata_names.items():56 if accessor == 'meta_keywords':57 # Render all the existing keywords for the current content type58 adapter = IMetaKeywords(context, None)59 if adapter is not None:60 keywords = adapter.getMetaKeywords()61 if keywords:62 result['keywords'] = keywords63 continue64 65 method = getattr(seo_context, accessor, None)66 if method is None:67 method = getattr(aq_inner(context).aq_explicit, accessor, None)68 69 if not callable(method):70 continue71 72 # Catch AttributeErrors raised by some AT applications73 try:74 value = method()75 except AttributeError:76 value = None77 78 if not value:79 # No data80 continue81 if accessor == 'Publisher' and value == 'No publisher':82 # No publisher is hardcoded (TODO: still?)83 continue84 if isinstance(value, (list, tuple)):85 # convert a list to a string86 value = ', '.join(value)87 88 # Special cases89 if accessor == 'Description' and not metadata_names.has_key('description'):90 result['description'] = value91 elif accessor == 'Subject' and not metadata_names.has_key('keywords'):92 result['keywords'] = value93 94 if accessor not in ('Description', 'Subject'):95 result[key] = value96 97 if use_all:98 created = context.CreationDate()99 100 try:101 effective = context.EffectiveDate()102 if effective == 'None':103 effective = None104 if effective:105 effective = DateTime(effective)106 except AttributeError:107 effective = None108 109 try:110 expires = context.ExpirationDate()111 if expires == 'None':112 expires = None113 if expires:114 expires = DateTime(expires)115 except AttributeError:116 expires = None117 118 # Filter out DWIMish artifacts on effective / expiration dates119 if effective is not None and \120 effective > FLOOR_DATE and \121 effective != created:122 eff_str = effective.Date()123 else:124 eff_str = ''125 126 if expires is not None and expires < CEILING_DATE:127 exp_str = expires.Date()128 else:129 exp_str = ''130 131 if exp_str or exp_str:132 result['DC.date.valid_range'] = '%s - %s' % (eff_str, exp_str)133 134 # add custom meta tags (added from qseo tab by user) for given context and default from configlet135 custom_meta_tags = seo_context and seo_context.seo_customMetaTags() or []136 for tag in custom_meta_tags:137 if tag['meta_content']:138 result[tag['meta_name']] = tag['meta_content']139 140 return result141 142 PloneTool.listMetaTags = listMetaTags -
quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/configure.zcml
r1723 r1776 9 9 i18n_domain="quintagroup.seoptimizer"> 10 10 11 <include file="patches.zcml" /> 11 12 <!-- include dependent packages --> 12 13 <include package="quintagroup.canonicalpath" /> -
quintagroup.seoptimizer/branches/refactoring2.3.0/setup.py
r1716 r1776 36 36 'setuptools', 37 37 'quintagroup.canonicalpath>=0.4', 38 'collective.monkeypatcher', 38 39 # -*- Extra requirements: -*- 39 40 ],
Note: See TracChangeset
for help on using the changeset viewer.