Changeset 1958 in products


Ignore:
Timestamp:
Mar 19, 2010 2:59:57 PM (11 years ago)
Author:
liebster
Message:

Clean-up code http://codereview.corp.quintagroup.com/40241/show

Location:
quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer
Files:
20 edited

Legend:

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

    r1932 r1958  
    1 import re, commands 
     1import re 
    22 
    3 from zope.component import adapts 
    43from zope.interface import implements 
    54from zope.component import queryAdapter 
    65from zope.component import queryMultiAdapter 
    7  
    8 from Acquisition import aq_inner 
    9 from OFS.interfaces import IPropertyManager 
    10 from Products.CMFCore.utils import getToolByName 
    116 
    127from quintagroup.seoptimizer.util import SortedDict 
     
    6762                    metadata_name[mt] = METADATA_MAPS[mt] 
    6863        return metadata_name 
    69  
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/browser/keywords.py

    r1918 r1958  
    1 import urllib, re, os, commands 
    2 from xml.dom import minidom, Node 
     1import re, commands 
     2from xml.dom import Node 
    33 
    44from zope.interface import implements 
     
    5151                               mapping={'result':'\n'.join(result)}), 
    5252                             context=self.context) 
    53  
    54     def walkTextNodes(self, parent, page_words=[]): 
    55         for node in parent.childNodes: 
    56             if node.nodeType == Node.ELEMENT_NODE: 
    57                 self.walkTextNodes(node, page_words) 
    58             elif node.nodeType == Node.TEXT_NODE: 
    59                 value = node.nodeValue 
    60                 if value is not None: 
    61                     page_words.extend(map(lambda x: x.lower(), value.split())) 
    62  
    63     def strip_tags(self, in_text): 
    64         s_list = list(in_text) 
    65         i,j = 0,0 
    66  
    67         while i < len(s_list): 
    68             if s_list[i] == '<': 
    69                 while s_list[i] != '>': 
    70                     # pop everything from the the left-angle bracket until the right-angle bracket 
    71                     s_list.pop(i) 
    72  
    73                 # pops the right-angle bracket, too 
    74                 s_list.pop(i) 
    75             else: 
    76                 i=i+1 
    77  
    78         # convert the list back into text 
    79         join_char='' 
    80         return join_char.join(s_list) 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/browser/seo_configlet.py

    r1904 r1958  
    33from zope.interface import implements 
    44from zope.component import adapts 
    5 from zope.schema.vocabulary import SimpleTerm 
    6 from zope.schema.vocabulary import SimpleVocabulary 
    7 from zope.schema import Bool, Text, Choice, Tuple, List 
     5from zope.schema import Bool, Choice, Tuple, List 
    86from zope.schema import SourceText 
    9 from zope.app.form.browser import RadioWidget 
    107 
    11 from zope.formlib.form import FormFields 
    128from zope.app.component.hooks import getSite 
    139from zope.app.form.browser import TextAreaWidget 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/browser/viewlets.py

    r1931 r1958  
    99 
    1010from Products.CMFPlone.utils import safe_unicode, getSiteEncoding 
    11 from Products.CMFCore.utils import getToolByName 
    1211 
    1312from quintagroup.seoptimizer.util import SortedDict 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/browser/views.py

    r1935 r1958  
    1 from sets import Set 
    21from time import time 
    3 from DateTime import DateTime  
     2from DateTime import DateTime 
    43from Acquisition import aq_inner 
    54from zope.component import queryAdapter 
     
    87 
    98from plone.memoize import view, ram 
    10 from plone.app.controlpanel.form import ControlPanelView 
    119 
    1210from Products.Five.browser import BrowserView 
     11from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile 
    1312from Products.CMFPlone.utils import getSiteEncoding 
    14 from Products.CMFCore.utils import getToolByName 
    15 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile 
    16 from Products.CMFPlone import PloneMessageFactory as pmf 
    1713 
    1814from quintagroup.canonicalpath.interfaces import ICanonicalLink 
    1915from quintagroup.canonicalpath.adapters import PROPERTY_LINK as CANONICAL_PROPERTY 
    2016 
    21 from quintagroup.seoptimizer import interfaces 
    2217from quintagroup.seoptimizer.browser.seo_configlet import ISEOConfigletSchema 
    2318from quintagroup.seoptimizer import SeoptimizerMessageFactory as _ 
     
    9792    def seo_customMetaTags( self ): 
    9893        """Returned seo custom metatags from default_custom_metatags property in seo_properties 
    99         (global seo custom metatags) with update from seo custom metatags properties in context (local seo custom metatags). 
     94           (global seo custom metatags) with update from seo custom metatags properties 
     95           in context (local seo custom metatags). 
    10096        """ 
    10197        glob, loc = self.seo_globalCustomMetaTags(), self.seo_localCustomMetaTags() 
     
    108104    def seo_globalWithoutLocalCustomMetaTags( self ): 
    109105        """Returned seo custom metatags from default_custom_metatags property in seo_properties 
    110         (global seo custom metatags) without seo custom metatags from properties in context (local seo custom metatags). 
     106           (global seo custom metatags) without seo custom metatags from properties 
     107           in context (local seo custom metatags). 
    111108        """ 
    112109        glob, loc = self.seo_globalCustomMetaTags(), self.seo_localCustomMetaTags() 
     
    156153        """ 
    157154        """ 
    158         return condition and first or second  
     155        return condition and first or second 
    159156 
    160157    def validateSEOProperty(self, property, value): 
     
    166163        """ Add a new property. 
    167164 
    168         Sets a new property with the given id, value and type or changes it. 
    169         """ 
    170         context = aq_inner(self.context)  
     165            Sets a new property with the given id, value and type or changes it. 
     166        """ 
     167        context = aq_inner(self.context) 
    171168        state = self.validateSEOProperty(property, value) 
    172169        if not state: 
     
    254251        """ Update seo custom metatags properties, if enabled checkbox override or delete properties. 
    255252 
    256         Change object properties by passing either a mapping object 
    257         of name:value pairs {'foo':6} or passing name=value parameters. 
     253            Change object properties by passing either a mapping object 
     254            of name:value pairs {'foo':6} or passing name=value parameters. 
    258255        """ 
    259256        context = aq_inner(self.context) 
     
    282279 
    283280    def __call__( self ): 
    284         """ Perform the update seo properties and redirect if necessary, or render the page Call method. 
     281        """ Perform the update seo properties and redirect if necessary, 
     282            or render the page Call method. 
    285283        """ 
    286284        context = aq_inner(self.context) 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/config.py

    r1924 r1958  
    11PROJECT_NAME = 'quintagroup.seoptimizer' 
    2  
    3 GLOBALS = globals() 
    4  
    5 PROPERTY_SHEET = 'seo_properties' 
    6 SHEET_TITLE = 'SEO Properties' 
    7  
    8 STOP_WORDS = ['a', 'an', 'amp', 'and', 'are', 'arial', 'as', 'at', 'be', 'but', 
    9     'by', 'can', 'com', 'do', 'font', 'for', 'from', 'gif', 'had', 'has', 
    10     'have', 'he', 'helvetica', 'her', 'his', 'how', 'href', 'i', 'if', 'in', 
    11     'is', 'it', 'javascript', 'jpg', 'made', 'net', 'of', 'on', 'or', 'org', 
    12     'our', 'sans', 'see', 'serif', 'she', 'that', 'the', 'this', 'to', 'us', 
    13     'we', 'with', 'you', 'your'] 
    14  
    15 DEFAULT_CUSTOM_METATAGS = [] 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/interfaces.py

    r1932 r1958  
    11from zope.interface import Interface 
    2 from quintagroup.canonicalpath.interfaces import ICanonicalPath 
    32 
    43class IMetaKeywords(Interface): 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/listMetaTags.py

    r1780 r1958  
    99    if not IPloneSEOLayer.providedBy(self.REQUEST): 
    1010        return originalListMetaTags(self, context) 
    11      
    1211    return {} 
    1312 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/setuphandlers.py

    r1925 r1958  
    2020            logger.log(logging.INFO, "Deleted \"SEO Properties\" action for %s type." % ptype.id) 
    2121 
    22 def removeConfiglet(site, conf_id): 
     22def removeConfiglet(site): 
    2323    """ Remove configlet. 
    2424    """ 
     25    conf_id = 'quintagroup.seoptimizer' 
    2526    controlpanel_tool = getToolByName(site, 'portal_controlpanel') 
    2627    if controlpanel_tool: 
     
    2930 
    3031def removeBrowserLayer(site): 
    31     """ Remove configlet. 
     32    """ Remove browser layer. 
    3233    """ 
    3334    name="qSEOptimizer" 
     
    4647    site = context.getSite() 
    4748    removeActions(site) 
    48     removeConfiglet(site, 'quintagroup.seoptimizer') 
     49    removeConfiglet(site) 
    4950    removeBrowserLayer(site) 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/base.py

    r1938 r1958  
    1919    from zope.app.cache.interfaces.ram import IRAMCache 
    2020 
    21 from AccessControl.SecurityManagement import newSecurityManager 
    22  
    2321from Products.Five import zcml 
    2422from Products.Five import fiveconfigure 
     
    2826from Products.CMFCore.utils import getToolByName 
    2927 
    30 from Products.PloneTestCase.layer import onsetup, PloneSite 
     28from Products.PloneTestCase.layer import PloneSite 
    3129from Products.PloneTestCase import PloneTestCase as ptc 
    3230from Products.PloneTestCase import setup as ptc_setup 
    3331 
    3432from Products.PloneTestCase.PloneTestCase import portal_owner 
    35 from Products.PloneTestCase.PloneTestCase import default_user 
    3633from Products.PloneTestCase.PloneTestCase import default_password 
    3734 
    38 from quintagroup.seoptimizer.config import * 
     35from quintagroup.seoptimizer.config import PROJECT_NAME 
    3936 
    4037ptc.setupPloneSite() 
     
    4946        import quintagroup.seoptimizer 
    5047        zcml.load_config('configure.zcml', quintagroup.seoptimizer) 
    51         #zcml.load_config('overrides.zcml', quintagroup.seoptimizer) 
    5248        fiveconfigure.debug_mode = False 
    5349        ztc.installPackage(PROJECT_NAME) 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testBugs.py

    r1894 r1958  
    1 import urllib, re 
     1import urllib 
    22from cStringIO import StringIO 
    33from base import * 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testCanonicalURL.py

    r1936 r1958  
    1 import re 
    2 from zope.interface import alsoProvides 
    3 from zope.component import queryAdapter 
    4 from zope.component import provideAdapter 
    5 from zope.component import queryMultiAdapter 
    6 from plone.indexer.decorator import indexer 
    7  
    8 from Products.CMFCore.interfaces import IContentish 
    9 from Products.Archetypes.interfaces import IBaseContent 
    10  
    111from quintagroup.canonicalpath.interfaces import ICanonicalLink 
    12 from quintagroup.canonicalpath.adapters import PROPERTY_LINK as CANONICAL_PROPERTY 
    13 from quintagroup.seoptimizer.browser.interfaces import IPloneSEOLayer 
    14 # from quintagroup.seoptimizer.interfaces import ISEOCanonicalPath 
    152from base import * 
    163 
     
    2613        self.curl = re.compile('<link\srel\s*=\s*"canonical"\s+' \ 
    2714            '[^>]*href\s*=\s*\"([^\"]*)\"[^>]*>', re.S|re.M) 
    28  
    2915 
    3016    def test_CanonicalURL(self): 
     
    9076        self.assertTrue("wrong canonical url" in html, 
    9177                        "Canonical url not validated") 
    92          
     78 
    9379    def test_delCanonical(self): 
    9480        newcanonical = '/new_canonical' 
     
    10490        mydoc_canonical = ICanonicalLink(self.mydoc).canonical_link 
    10591        self.assertTrue(mydoc_canonical == self.mydoc.absolute_url(), 
    106             "Steel customized canonical url after remove customization")  
    107          
     92            "Steel customized canonical url after remove customization") 
     93 
    10894 
    10995def test_suite(): 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testConfiglet.py

    r1907 r1958  
    1 import re 
    21from base import * 
    32 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testContextForm.py

    r1908 r1958  
    1 import urllib, re 
     1import urllib 
    22from cStringIO import StringIO 
    33from base import * 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testExposeDCMetaTags.py

    r1877 r1958  
    1 import re, string 
     1import string 
    22from DateTime import DateTime 
    33from base import * 
     
    3535        m = re.match(METATAG % "description", self.html, re.S|re.M) 
    3636        self.assert_(m, 'No "description" meta tag when expose DC meta tags is Off') 
    37          
     37 
    3838    def test_descriptionInPropertyOn(self): 
    3939        self.sp.manage_changeProperties(exposeDCMetaTags = True) 
     
    4242        m = re.match(METATAG % "description", self.html, re.S|re.M) 
    4343        self.assert_(m, 'No "description" meta tag when expose DC meta tags is On') 
    44          
     44 
    4545    def test_dateValidRange(self): 
    4646        self.sp.manage_changeProperties(exposeDCMetaTags = True) 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testInstallation.py

    r1930 r1958  
    55from zope.interface import alsoProvides 
    66from zope.component import queryMultiAdapter 
    7 from zope.publisher.browser import TestRequest 
    87from zope.viewlet.interfaces import IViewletManager 
    98 
     
    1110from quintagroup.seoptimizer.browser.interfaces import IPloneSEOLayer 
    1211from base import * 
     12 
     13PROPERTY_SHEET = 'seo_properties' 
     14STOP_WORDS = ['a', 'an', 'amp', 'and', 'are', 'arial', 'as', 'at', 'be', 'but', 
     15    'by', 'can', 'com', 'do', 'font', 'for', 'from', 'gif', 'had', 'has', 
     16    'have', 'he', 'helvetica', 'her', 'his', 'how', 'href', 'i', 'if', 'in', 
     17    'is', 'it', 'javascript', 'jpg', 'made', 'net', 'of', 'on', 'or', 'org', 
     18    'our', 'sans', 'see', 'serif', 'she', 'that', 'the', 'this', 'to', 'us', 
     19    'we', 'with', 'you', 'your'] 
    1320 
    1421PROPS = {'stop_words': STOP_WORDS, 
     
    3138 
    3239    def afterSetUp(self): 
    33         #self.qi = self.portal.portal_quickinstaller 
    34         #self.qi.uninstallProducts([PROJECT_NAME]) 
    3540        self.basic_auth = 'mgr:mgrpw' 
    3641        self.portal_path = '/%s' % self.portal.absolute_url(1) 
     
    7782        for p in VIEWLETS: 
    7883            self.assert_(manager.get(p) is not None, "Not registered '%s' viewlet" % p) 
    79          
     84 
    8085    def test_browser_layer(self): 
    8186        from plone.browserlayer import utils 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testMetaTagsDuplication.py

    r1897 r1958  
    1 import re 
    21from base import * 
    32 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testUsageKeywords.py

    r1901 r1958  
    1 import urllib, re 
    2 from Acquisition import aq_inner 
    31from base import * 
    42 
     
    1614        self.my_doc = self.portal['my_doc'] 
    1715 
    18  
    1916    def test_noDefaultKeywords(self): 
    2017        """No keywords added for the content by default""" 
    2118        metatags = self.pu.listMetaTags(self.my_doc) 
    2219        self.assert_('keywords' not in metatags) 
    23          
    2420 
    2521    def testrender_SEOKeywords(self): 
     
    3531            self.assert_(re.match(KWSTMPL % expect, html, re.S|re.M), 
    3632                         "No '%s' keyword found" % str(seokws)) 
    37  
    3833 
    3934    def testbehave_NoSEOKeywordsOnlySubject(self): 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/test_doctest.py

    r1895 r1958  
    11import unittest 
    22import doctest 
    3  
    4 from zope.testing import doctestunit 
    5 from zope.component import testing, eventtesting 
    63 
    74from base import * 
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/upgrades.py

    r1930 r1958  
    11import logging 
    22from zope.component import queryMultiAdapter 
    3 from Products.CMFCore.utils import getToolByName 
    43 
    54from quintagroup.canonicalpath.interfaces  import ICanonicalLink 
     
    1413def changeDomain(plone_tools): 
    1514    """ Fix i18n_domain bug for some portal_types, 
    16     which present in earlier versions of the package. 
     15        which present in earlier versions of the package. 
    1716    """ 
    1817    types_tool = plone_tools.types() 
     
    4443def migrationActions(plone_tools): 
    4544    """ Migration actions from portal_types action to seoproperties tool 
    46     (for seoaction in portal_actions). 
     45        (for seoaction in portal_actions). 
    4746    """ 
    4847    types_tool = plone_tools.types() 
     
    7675 
    7776def removeSkin(plone_tools): 
    78     """ Remove layers. 
     77    """ Remove skin layers. 
    7978    """ 
    8079    layer = 'quintagroup.seoptimizer' 
Note: See TracChangeset for help on using the changeset viewer.