Changeset 1815 in products for quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup
- Timestamp:
- Feb 24, 2010 12:04:10 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/browser/views.py
r1789 r1815 3 3 from Acquisition import aq_inner 4 4 from zope.component import queryAdapter 5 from plone.memoize import view 5 6 from plone.app.controlpanel.form import ControlPanelView 6 7 … … 23 24 """ 24 25 26 def __init__(self, *args, **kwargs): 27 super(SEOContext, self).__init__(*args, **kwargs) 28 self._seotags = self._getSEOTags() 29 30 def __getitem__(self, key): 31 return self._seotags.get(key, '') 32 33 @view.memoize 34 def _getSEOTags(self): 35 seotags = { 36 "seo_title": self.getSEOProperty( 'qSEO_title', accessor='Title' ), 37 "seo_robots": self.getSEOProperty( 'qSEO_robots', default='ALL'), 38 "seo_description": self.getSEOProperty( 'qSEO_description', accessor='Description' ), 39 "seo_distribution": self.getSEOProperty( 'qSEO_distribution', default="Global"), 40 "seo_customMetaTags": self.seo_customMetaTags(), 41 "seo_globalWithoutLocalCustomMetaTags": self.seo_globalWithoutLocalCustomMetaTags(), 42 "seo_localCustomMetaTags": self.seo_localCustomMetaTags(), 43 "seo_globalCustomMetaTags": self.seo_globalCustomMetaTags(), 44 "seo_html_comment": self.getSEOProperty( 'qSEO_html_comment', default='' ), 45 "meta_keywords": self.meta_keywords(), 46 "seo_keywords": self.seo_keywords(), 47 "seo_canonical": self.seo_canonical(), 48 # Add test properties 49 "has_seo_title": self.context.hasProperty('qSEO_title'), 50 "has_seo_robots": self.context.hasProperty('qSEO_robots'), 51 "has_seo_description": self.context.hasProperty( 'qSEO_description'), 52 "has_seo_distribution": self.context.hasProperty( 'qSEO_distribution'), 53 "has_html_comment": self.context.hasProperty('qSEO_html_comment'), 54 "has_seo_keywords": self.context.hasProperty('qSEO_keywords'), 55 "has_seo_canonical": self.context.hasProperty('qSEO_canonical'), 56 } 57 seotags["seo_nonEmptylocalMetaTags"] = bool(seotags["seo_localCustomMetaTags"]) 58 return seotags 59 60 61 def getSEOProperty( self, property_name, accessor='', default=None ): 62 """ Get value from seo property by property name. 63 """ 64 context = aq_inner(self.context) 65 66 if context.hasProperty(property_name): 67 return context.getProperty(property_name, default) 68 69 if accessor: 70 method = getattr(context, accessor, default) 71 if not callable(method): 72 return default 73 74 # Catch AttributeErrors raised by some AT applications 75 try: 76 value = method() 77 except AttributeError: 78 value = default 79 80 return value 81 82 25 83 def isSEOTabVisibile(self): 26 84 context = aq_inner(self.context) … … 30 88 return bool(self.context.portal_type in content_types_with_seoproperties) 31 89 32 def getSEOProperty( self, property_name, accessor='' ):33 """ Get value from seo property by property name.34 """35 context = aq_inner(self.context)36 37 if context.hasProperty(property_name):38 return context.getProperty(property_name)39 40 if accessor:41 method = getattr(context, accessor, None)42 if not callable(method):43 return None44 45 # Catch AttributeErrors raised by some AT applications46 try:47 value = method()48 except AttributeError:49 value = None50 51 return value52 53 def seo_title( self ):54 """ Generate SEO Title from SEO properties.55 """56 return self.getSEOProperty( 'qSEO_title', accessor='Title' )57 58 def seo_robots( self ):59 """ Generate SEO Robots from SEO properties.60 """61 robots = self.getSEOProperty( 'qSEO_robots' )62 return robots and robots or 'ALL'63 64 def seo_description( self ):65 """ Generate Description from SEO properties.66 """67 68 return self.getSEOProperty( 'qSEO_description', accessor = 'Description')69 70 def seo_distribution( self ):71 """ Generate Distribution from SEO properties.72 """73 dist = self.getSEOProperty( 'qSEO_distribution' )74 75 return dist and dist or 'Global'76 90 77 91 def seo_customMetaTags( self ): … … 132 146 'meta_content' : len(name_value) == 2 and name_value[1] or ''}) 133 147 return result 134 135 def seo_nonEmptylocalMetaTags( self ):136 """137 """138 return bool(self.seo_localCustomMetaTags())139 148 140 149 def seo_html_comment( self ):
Note: See TracChangeset
for help on using the changeset viewer.