Changeset 1931 in products


Ignore:
Timestamp:
Mar 17, 2010 6:46:02 PM (15 years ago)
Author:
mylan
Message:

#180: Update seoptimizer to use default ICanonicalLink adapter

Location:
quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/browser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/browser/viewlets.py

    r1909 r1931  
    206206    """ Simple viewlet for canonical url link rendering. 
    207207    """ 
    208  
    209208    def render( self ): 
    210         seo_context = getMultiAdapter((self.context, self.request), name='seo_context') 
    211         return """<link rel="canonical" href="%s" />""" % seo_context['seo_canonical'] 
     209        seoc = getMultiAdapter((self.context, self.request), name=u'seo_context') 
     210        return """<link rel="canonical" href="%s" />""" % seoc['seo_canonical'] 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/browser/views.py

    r1918 r1931  
    1313from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile 
    1414from Products.CMFPlone import PloneMessageFactory as pmf 
     15 
     16from quintagroup.canonicalpath.interfaces import ICanonicalLink 
     17from quintagroup.canonicalpath.adapters import PROPERTY_LINK as CANONICAL_PROPERTY 
    1518 
    1619from quintagroup.seoptimizer import interfaces 
     
    5558            "meta_keywords": self.getSEOProperty('qSEO_keywords', 'Subject', ()), 
    5659            "seo_keywords": self.getSEOProperty('qSEO_keywords', default=()), 
    57             "seo_canonical": self.seo_canonical(), 
     60            "seo_canonical": ICanonicalLink(self.context).canonical_link, 
    5861            # Add test properties 
    5962            "has_seo_title": self.context.hasProperty('qSEO_title'), 
     
    6366            "has_html_comment": self.context.hasProperty('qSEO_html_comment'), 
    6467            "has_seo_keywords": self.context.hasProperty('qSEO_keywords'), 
    65             "has_seo_canonical": self.context.hasProperty('qSEO_canonical'), 
     68            "has_seo_canonical": self.context.hasProperty(CANONICAL_PROPERTY), 
    6669            } 
    6770        #seotags["seo_nonEmptylocalMetaTags"] = bool(seotags["seo_localCustomMetaTags"]) 
     
    135138        return result 
    136139 
    137     def seo_canonical( self ): 
    138         """ Generate canonical URL from SEO properties. 
    139         """ 
    140         canpath = queryAdapter(self.context, interfaces.ISEOCanonicalPath) 
    141         return self.pps.portal_url() + canpath.canonical_path() 
    142  
    143140 
    144141class SEOContextPropertiesView( BrowserView ): 
     
    159156        return condition and first or second  
    160157 
    161     def getMainDomain(self, url): 
    162         """ Get a main domain. 
    163         """ 
    164         url = url.split('//')[-1] 
    165         dompath = url.split(':')[0] 
    166         dom = dompath.split('/')[0] 
    167         return '.'.join(dom.split('.')[-2:]) 
    168  
    169158    def validateSEOProperty(self, property, value): 
    170159        """ Validate a seo property. 
    171160        """ 
    172         purl = getToolByName(self.context, 'portal_url')() 
    173         state = '' 
    174         if property == PROP_PREFIX+'canonical': 
    175             # validate seo canonical url property 
    176             pdomain = self.getMainDomain(purl) 
    177             if not pdomain == self.getMainDomain(value): 
    178                 state = _('canonical_msg', default=u'Canonical URL mast be in ${pdomain} domain.', mapping={'pdomain': pdomain}) 
    179         return state 
     161        return '' 
    180162 
    181163    def setProperty(self, property, value, type='string'): 
     
    208190            if seo_key == 'custommetatags': 
    209191                self.manageSEOCustomMetaTagsProperties(**kw) 
     192            elif seo_key == 'canonical': 
     193                canonical = seo_items[seo_key] 
     194                try: 
     195                    ICanonicalLink(self.context).canonical_link = canonical 
     196                except InvalidValue, e: 
     197                    return str(e) 
    210198            else: 
    211199                if seo_key in seo_overrides_keys and seo_items.get(seo_key+SUFFIX): 
Note: See TracChangeset for help on using the changeset viewer.