Ignore:
Timestamp:
Feb 18, 2010 9:15:16 PM (14 years ago)
Author:
liebster
Message:

#143: Refactoring 'SEO' tab view for different types

File:
1 edited

Legend:

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

    r1752 r1782  
    2222    """ This class contains methods that allows to edit html header meta tags. 
    2323    """ 
     24 
     25    def isSEOTabVisibile(self): 
     26        context = aq_inner(self.context) 
     27        portal_properties = getToolByName(context, 'portal_properties') 
     28        seo_properties = getToolByName(portal_properties, 'seo_properties') 
     29        content_types_with_seoproperties = seo_properties.getProperty('content_types_with_seoproperties', '') 
     30        return bool(self.context.portal_type in content_types_with_seoproperties) 
     31 
    2432    def getSEOProperty( self, property_name, accessor='' ): 
    2533        """ Get value from seo property by property name. 
     
    232240        return getToolByName(context, 'portal_types') 
    233241 
    234     def hasSEOAction( self, type_info ): 
    235         """ 
    236         """ 
    237         return filter(lambda x:x.id == 'seo_properties', type_info.listActions()) 
     242    #def hasSEOAction( self, type_info ): 
     243        #""" 
     244        #""" 
     245        #return filter(lambda x:x.id == 'seo_properties', type_info.listActions()) 
    238246 
    239247    def test( self, condition, first, second ): 
     
    276284            return [slist] 
    277285 
     286    def isSEOTabVisibile(self, type): 
     287        context = aq_inner(self.context) 
     288        portal_properties = getToolByName(context, 'portal_properties') 
     289        seo_properties = getToolByName(portal_properties, 'seo_properties') 
     290        content_types_with_seoproperties = seo_properties.getProperty('content_types_with_seoproperties', '') 
     291        return bool(type in content_types_with_seoproperties) 
     292       
    278293    def __call__( self ): 
    279294        """ Perform the update and redirect if necessary, or render the page. 
     
    282297        request = self.request 
    283298 
    284         content_types_seoprops_enabled = request.get( 'contentTypes', [] ) 
    285299        exposeDCMetaTags = request.get( 'exposeDCMetaTags', None ) 
    286300        additionalKeywords = request.get('additionalKeywords', []) 
     
    289303        settingsUseKeywordsSG = int(request.get('settingsUseKeywordsSG', 1)) 
    290304        settingsUseKeywordsLG = int(request.get('settingsUseKeywordsLG', 1)) 
     305        content_types_with_seoproperties = request.get('contentTypes', []) 
    291306 
    292307        site_props = getToolByName(self.portal_properties, 'site_properties') 
     
    295310        form = self.request.form 
    296311        submitted = form.get('form.submitted', False) 
    297  
    298312        if submitted: 
    299313            site_props.manage_changeProperties(exposeDCMetaTags=exposeDCMetaTags) 
     
    301315            seo_props.manage_changeProperties(default_custom_metatags=default_custom_metatags) 
    302316            seo_props.manage_changeProperties(metatags_order=metatags_order) 
    303             seo_props.manage_changeProperties(content_types_seoprops_enabled=content_types_seoprops_enabled) 
    304317            seo_props.manage_changeProperties(settings_use_keywords_sg=settingsUseKeywordsSG) 
    305318            seo_props.manage_changeProperties(settings_use_keywords_lg=settingsUseKeywordsLG) 
    306  
    307             for ptype in self.portal_types.objectValues(): 
    308                 acts = filter(lambda x: x.id == 'seo_properties', ptype.listActions()) 
    309                 action = acts and acts[0] or None 
    310                 if ptype.getId() in content_types_seoprops_enabled: 
    311                     if action is None: 
    312                         ptype.addAction('seo_properties', 
    313                                         'SEO Properties', 
    314                                         'string:${object_url}/@@seo-context-properties', 
    315                                         "python:exists('portal/@@seo-context-properties')", 
    316                                         'Modify portal content', 
    317                                         'object', 
    318                                         visible=1) 
    319                 else: 
    320                     if action !=None: 
    321                         actions = list(ptype.listActions()) 
    322                         ptype.deleteActions([actions.index(a) for a in actions if a.getId()=='seo_properties']) 
     319            seo_props.manage_changeProperties(content_types_with_seoproperties=content_types_with_seoproperties) 
     320 
    323321            context.plone_utils.addPortalMessage(pmf(u'Changes saved.')) 
    324322            return request.response.redirect('%s/%s'%(self.context.absolute_url(), 'plone_control_panel')) 
    325323        else: 
    326             return self.template(contentTypes=content_types_seoprops_enabled, exposeDCMetaTags=exposeDCMetaTags) 
     324            return self.template(contentTypes=content_types_with_seoproperties, exposeDCMetaTags=exposeDCMetaTags) 
    327325 
    328326    def typeInfo( self, type_name ): 
Note: See TracChangeset for help on using the changeset viewer.