Changeset 3134 in products


Ignore:
Timestamp:
Apr 18, 2011 2:32:21 PM (13 years ago)
Author:
zidane
Message:

fixes pep8

Location:
quintagroup.seoptimizer/trunk
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/Extensions/Install.py

    r2139 r3134  
    1111UNINSTALL = 'profile-%s:uninstall' % PROJECT_NAME 
    1212 
     13 
    1314def install(portal, reinstall=False): 
    1415    """ (Re)Install this product. 
    1516 
    16         This external method is need, because portal_quickinstaller doens't know 
    17         what GenericProfile profile to apply when reinstalling a product. 
     17        This external method is need, because portal_quickinstaller doens't 
     18        know what GenericProfile profile to apply when reinstalling a product. 
    1819    """ 
    1920    setup_tool = getToolByName(portal, 'portal_setup') 
     
    2122        step = None 
    2223        profile_id = 'quintagroup.seoptimizer:default' 
    23         steps_to_run = [s['id'] for s in setup_tool.listUpgrades(profile_id, show_old=False)] 
     24        steps_to_run = [s['id'] for s in \ 
     25                        setup_tool.listUpgrades(profile_id, show_old=False)] 
    2426        for step_id in steps_to_run: 
    2527            step = _upgrade_registry.getUpgradeStep(profile_id, step_id) 
    2628            step.doStep(setup_tool) 
    27             msg = "Ran upgrade step %s for profile %s" % (step.title, profile_id) 
     29            msg = "Ran upgrade step %s for profile %s" \ 
     30                  % (step.title, profile_id) 
    2831            logger.log(logging.INFO, msg) 
    2932        # We update the profile version to the last one we have reached 
    3033        # with running an upgrade step. 
    3134        if step and step.dest is not None and step.checker is None: 
    32            setup_tool.setLastVersionForProfile(profile_id, step.dest) 
     35            setup_tool.setLastVersionForProfile(profile_id, step.dest) 
    3336        return "Ran all reinstall steps." 
    3437    else: 
     
    3639        return "Ran all install steps." 
    3740 
     41 
    3842def uninstall(portal, reinstall=False): 
    3943    """ Uninstall this product. 
    4044 
    41         This external method is need, because portal_quickinstaller doens't know 
    42         what GenericProfile profile to apply when uninstalling a product. 
     45        This external method is need, because portal_quickinstaller doens't 
     46        know what GenericProfile profile to apply when uninstalling a product. 
    4347    """ 
    4448    setup_tool = getToolByName(portal, 'portal_setup') 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/adapters.py

    r2139 r3134  
    2626    ("robots", "seo_robots"), 
    2727    ("distribution", "seo_distribution")]) 
     28 
    2829 
    2930class MetaKeywordsAdapter(object): 
     
    5960        if self.gseo: 
    6061            for mt in self.gseo.metatags_order: 
    61                 if METADATA_MAPS.has_key(mt): 
     62                if mt in METADATA_MAPS: 
    6263                    metadata_name[mt] = METADATA_MAPS[mt] 
    6364        return metadata_name 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/browser/interfaces.py

    r2139 r3134  
    11from zope.interface import Interface 
    22from plone.theme.interfaces import IDefaultPloneLayer 
     3 
    34 
    45class IPloneSEOLayer(IDefaultPloneLayer): 
     
    67       Selection in portal_skins. 
    78    """ 
     9 
    810 
    911class IValidateSEOKeywordsView(Interface): 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/browser/keywords.py

    r2933 r3134  
    1 import re, sys, urllib2 
     1import re 
     2import sys 
     3import urllib2 
    24from xml.dom import Node 
    35 
     
    1719from quintagroup.seoptimizer.browser.seo_configlet import ISEOConfigletSchema 
    1820 
     21 
    1922class ValidateSEOKeywordsView(BrowserView): 
    2023 
     
    2730        transforms = getUtility(IPortalTransformsTool) 
    2831        portal = getToolByName(self.context, 'portal_url').getPortalObject() 
    29         isExternal = queryAdapter(portal, ISEOConfigletSchema).external_keywords_test 
     32        query_adapter = queryAdapter(portal, ISEOConfigletSchema) 
     33        isExternal = query_adapter.external_keywords_test 
    3034        # extract keywords from text 
    3135        enc = getSiteEncoding(self.context) 
     
    4246            # Not pass timeout option because: 
    4347            # 1. its value get from the global default timeout settings. 
    44             # 2. timeout option added in python 2.6 (so acceptable only in plone4+) 
     48            # 2. timeout option added in python 2.6 
     49            #    (so acceptable only in plone4+) 
    4550            try: 
    4651                resp = urllib2.urlopen(self.context.absolute_url()) 
     
    5055                    resp.close() 
    5156            except (urllib2.URLError, urllib2.HTTPError), e: 
    52                 # In case of exceed timeout period or other URL connection errors. 
    53                 # Get nearest to context error_log object (stolen from Zope2/App/startup.py) 
     57                # In case of exceed timeout period or 
     58                # other URL connection errors. 
     59                # Get nearest to context error_log object 
     60                # (stolen from Zope2/App/startup.py) 
    5461                html = None 
    5562                info = sys.exc_info() 
     
    5966            html = unicode(self.context()).encode(enc) 
    6067 
    61         # If no html - information about problem with page retrieval should be returned 
     68        # If no html - information about problem with page retrieval 
     69        # should be returned 
    6270        result = [] 
    6371        if html is None: 
     
    6977            # check every keyword on appearing in body of html page 
    7078            for keyword in keywords: 
    71                 keyword_on_page = unicode(len(re.findall(u'\\b%s\\b' % keyword, page_text, re.I|re.U))) 
     79                keyword_on_page = unicode(len(re.findall(u'\\b%s\\b' % keyword, 
     80                                              page_text, re.I | re.U))) 
    7281                result.append(' - '.join((keyword, keyword_on_page))) 
    7382 
    7483        return ts.utranslate(domain='quintagroup.seoptimizer', 
    7584                             msgid=_(u'number_keywords', 
    76                                default=u'Number of keywords at page:\n${result}', 
    77                                mapping={'result':'\n'.join(result)}), 
     85                                     default=u'Number of keywords at page:\n' 
     86                                              '${result}', 
     87                                     mapping={'result': '\n'.join(result)}), 
    7888                             context=self.context) 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/browser/seo_configlet.py

    r2889 r3134  
    2727    exposeDCMetaTags = Bool( 
    2828        title=_("label_exposeDCMetaTags", 
    29                 default='Expose <abbr title="Dublin Core">DC</abbr> meta tags'), 
     29                default='Expose <abbr title="Dublin Core">DC</abbr> ' \ 
     30                'meta tags'), 
    3031        description=_("description_seo_dc_metatags", 
    31                 default='Controls if <abbr title="Dublin Core">DC</abbr> ' 
    32                     'metatags are exposed to page header. They include ' 
    33                     'DC.description, DC.type, DC.format, DC.creator and ' 
    34                     'others.'), 
     32                      default='Controls if <abbr title="Dublin Core">DC</abbr>' 
     33                      ' metatags are exposed to page header. They include ' 
     34                      'DC.description, DC.type, DC.format, DC.creator and ' 
     35                      'others.'), 
    3536        default=True, 
    3637        required=False) 
     
    4041                default='Meta tags order in the page.'), 
    4142        description=_("help_metatags_order", 
    42                 default='Fill in meta tags (one per line) in the order in which' 
    43                     ' they will appear on site source pages. Example: ' 
    44                     '"metaname accessor".'), 
     43                      default='Fill in meta tags (one per line) in the order ' 
     44                      'in which they will appear on site source pages. ' 
     45                      'Example: "metaname accessor".'), 
    4546        required=False) 
    4647 
     
    5657 
    5758    default_custom_metatags = List( 
    58         title=_("label_default_custom_metatags", default='Default custom metatags.'), 
     59        title=_("label_default_custom_metatags", 
     60                default='Default custom metatags.'), 
    5961        description=_("help_default_custom_metatags", 
    60                 default='Fill in custom metatag names (one per line) which will ' 
    61                     'appear on qseo_properties edit tab. Example: ' 
    62                     '"metaname|metacontent" or "metaname".'), 
    63         required=False) 
    64  
     62                      default='Fill in custom metatag names (one per line) ' \ 
     63                      'which will appear on qseo_properties edit tab. ' \ 
     64                      'Example: "metaname|metacontent" or "metaname".'), 
     65        required=False) 
    6566 
    6667 
     
    7576 
    7677    fields = List( 
    77         title=_("label_fields", default='Fields for keywords statistic calculation.'), 
    78         description=_("help_fields", 
    79                 default='Fill in filds (one per line) which statistics of keywords usage ' 
    80                     'should be calculated for.'), 
     78        title=_("label_fields", default='Fields for keywords statistic ' 
     79                'calculation.'), 
     80        description=_("help_fields", default='Fill in filds (one per line)' 
     81                      'which statistics of keywords usage should ' 
     82                      'be calculated for.'), 
    8183        required=False) 
    8284 
    8385    stop_words = List( 
    8486        title=_("label_stop_words", default='Stop words.'), 
    85         description=_("help_stop_words", 
    86                 default='Fill in stop words (one per line) which will ' 
    87                     'be excluded from kewords statistics calculation.'), 
     87        description=_("help_stop_words", default='Fill in stop words ' 
     88                      '(one per line) which will be excluded from kewords ' 
     89                      'statistics calculation.'), 
    8890        required=False) 
    8991 
     
    120122        self.encoding = pprop.site_properties.default_charset 
    121123 
    122  
    123124    def getExposeDC(self): 
    124125        return self.siteprops.getProperty('exposeDCMetaTags') 
     
    146147 
    147148    exposeDCMetaTags = property(getExposeDC, setExposeDC) 
    148     default_custom_metatags = ProxyFieldProperty(ISEOConfigletSchema['default_custom_metatags']) 
     149    seo_default_custom_metatag = ISEOConfigletSchema['default_custom_metatags'] 
     150    default_custom_metatags = ProxyFieldProperty(seo_default_custom_metatag) 
    149151    metatags_order = ProxyFieldProperty(ISEOConfigletSchema['metatags_order']) 
    150152    types_seo_enabled = property(getTypesSEOEnabled, setTypesSEOEnabled) 
     
    152154    fields = ProxyFieldProperty(ISEOConfigletSchema['fields']) 
    153155    stop_words = ProxyFieldProperty(ISEOConfigletSchema['stop_words']) 
    154     external_keywords_test = ProxyFieldProperty(ISEOConfigletSchema['external_keywords_test']) 
     156    seo_external_keywords_test = ISEOConfigletSchema['external_keywords_test'] 
     157    external_keywords_test = ProxyFieldProperty(seo_external_keywords_test) 
    155158 
    156159 
    157160class Text2ListWidget(TextAreaWidget): 
    158161    height = 5 
    159     splitter = re.compile(u'\\r?\\n', re.S|re.U) 
     162    splitter = re.compile(u'\\r?\\n', re.S | re.U) 
    160163 
    161164    def _toFieldValue(self, input): 
     
    166169 
    167170    def _toFormValue(self, value): 
    168         if value == self.context.missing_value or value == self.context._type(): 
     171        if value == self.context.missing_value or \ 
     172           value == self.context._type(): 
    169173            return self._missing 
    170174        else: 
     
    181185advancedset.label = _(u'label_seoadvanced', default=u'Advanced') 
    182186 
     187 
    183188class SEOConfiglet(ControlPanelForm): 
    184189 
    185190    form_fields = FormFieldsets(baseset, advancedset) 
     191    type_seo_enabled = MultiCheckBoxThreeColumnWidget 
    186192 
    187193    form_fields['default_custom_metatags'].custom_widget = Text2ListWidget 
    188194    form_fields['metatags_order'].custom_widget = Text2ListWidget 
    189     form_fields['types_seo_enabled'].custom_widget = MultiCheckBoxThreeColumnWidget 
    190     form_fields['types_seo_enabled'].custom_widget.cssClass='label' 
     195    form_fields['types_seo_enabled'].custom_widget = type_seo_enabled 
     196    form_fields['types_seo_enabled'].custom_widget.cssClass = 'label' 
    191197    form_fields['fields'].custom_widget = Text2ListWidget 
    192198    form_fields['stop_words'].custom_widget = Text2ListWidget 
     
    195201    description = _("seo_configlet_description", default="You can select what " 
    196202                    "content types are qSEOptimizer-enabled, and control if " 
    197                     "Dublin Core metatags are exposed in the header of content " 
    198                     "pages.") 
     203                    "Dublin Core metatags are exposed in the header of content" 
     204                    " pages.") 
    199205    form_name = _("") 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/browser/viewlets.py

    r2237 r3134  
    1717from Products.CMFPlone.PloneTool import * 
    1818 
    19 class SEOTagsViewlet( ViewletBase ): 
     19 
     20class SEOTagsViewlet(ViewletBase): 
    2021    """ Simple viewlet for custom title rendering. 
    2122    """ 
     
    2425        TEMPLATE = '<meta name="%s" content="%s"/>' 
    2526        enc = getSiteEncoding(self.context) 
    26         sfuncd = lambda x, enc=enc:safe_unicode(x, enc) 
    27         return u'\n'.join([TEMPLATE % tuple(map(sfuncd, (k,v))) \ 
    28                            for k,v in self.listMetaTags().items()]) 
     27        sfuncd = lambda x, enc=enc: safe_unicode(x, enc) 
     28        return u'\n'.join([TEMPLATE % tuple(map(sfuncd, (k, v))) \ 
     29                           for k, v in self.listMetaTags().items()]) 
    2930 
    3031    def listMetaTags(self): 
     
    3233 
    3334        result = SortedDict() 
    34         pps = queryMultiAdapter((self.context, self.request), name="plone_portal_state") 
     35        pps = queryMultiAdapter((self.context, self.request), 
     36                                name="plone_portal_state") 
    3537        seo_global = queryAdapter(pps.portal(), ISEOConfigletSchema) 
    36         seo_context = queryMultiAdapter((self.context, self.request), name='seo_context') 
     38        seo_context = queryMultiAdapter((self.context, self.request), 
     39                                        name='seo_context') 
    3740 
    3841        use_all = seo_global.exposeDCMetaTags 
    3942        adapter = IMappingMetaTags(self.context, None) 
    40         mapping_metadata = adapter and adapter.getMappingMetaTags() or SortedDict() 
     43        mapping_metadata = adapter and adapter.getMappingMetaTags() \ 
     44                           or SortedDict() 
    4145 
    4246        if not use_all: 
    43             metadata_names = mapping_metadata.has_key('DC.description') \ 
    44                              and {'DC.description': mapping_metadata['DC.description']} \ 
    45                              or SortedDict() 
    46             if mapping_metadata.has_key('description'): 
     47            metadata_names = 'DC.description' in mapping_metadata and \ 
     48                {'DC.description': mapping_metadata['DC.description']} \ 
     49                or SortedDict() 
     50            if 'description' in mapping_metadata: 
    4751                metadata_names['description'] = mapping_metadata['description'] 
    4852        else: 
     
    5963                continue 
    6064 
    61             if seo_context._seotags.has_key(accessor): 
     65            if accessor in seo_context._seotags: 
    6266                value = seo_context._seotags.get(accessor, None) 
    6367            else: 
    6468                method = getattr(seo_context, accessor, None) 
    6569                if method is None: 
    66                     method = getattr(aq_inner(self.context).aq_explicit, accessor, None) 
     70                    method = getattr(aq_inner(self.context).aq_explicit, 
     71                                     accessor, None) 
    6772 
    6873                if not callable(method): 
     
    8691 
    8792            # Special cases 
    88             if accessor == 'Description' and not metadata_names.has_key('description'): 
     93            if accessor == 'Description' and \ 
     94               not 'description' in metadata_names: 
    8995                result['description'] = value 
    90             elif accessor == 'Subject' and not metadata_names.has_key('keywords'): 
     96            elif accessor == 'Subject' and \ 
     97                 not 'keywords' in metadata_names: 
    9198                result['keywords'] = value 
    9299 
     
    133140        # add custom meta tags (added from qseo tab by user) 
    134141        # for given context and default from configlet 
    135         custom_meta_tags = seo_context and seo_context['seo_customMetaTags'] or [] 
     142        custom_meta_tags = seo_context and \ 
     143                           seo_context['seo_customMetaTags'] or [] 
    136144        for tag in custom_meta_tags: 
    137145            if tag['meta_content']: 
     
    139147 
    140148        return result 
    141  
    142149 
    143150 
     
    175182                qseo_comments = u"<!--%s-->" % safe_unicode( 
    176183                    self.seo_context["seo_html_comment"]) 
    177                 return u"%s\n%s"%(std_title, qseo_comments) 
     184                return u"%s\n%s" % (std_title, qseo_comments) 
    178185        else: 
    179186            qseo_title = u"<title>%s</title>" % safe_unicode( 
     
    184191                qseo_comments = u"<!--%s-->" % safe_unicode( 
    185192                    self.seo_context["seo_html_comment"]) 
    186                 return u"%s\n%s"%(qseo_title, qseo_comments) 
    187  
    188  
    189 class CustomScriptViewlet( ViewletBase ): 
     193                return u"%s\n%s" % (qseo_title, qseo_comments) 
     194 
     195 
     196class CustomScriptViewlet(ViewletBase): 
    190197    """ Simple viewlet for custom script rendering. 
    191198    """ 
    192     def getCustomScript( self ): 
     199    def getCustomScript(self): 
    193200        pps = queryMultiAdapter((self.context, self.request), 
    194201                                name="plone_portal_state") 
     
    198205        return '' 
    199206 
    200     def render( self ): 
    201         return safe_unicode("""%s"""% self.getCustomScript()) 
    202  
    203  
    204 class CanonicalUrlViewlet( ViewletBase ): 
     207    def render(self): 
     208        return safe_unicode("""%s""" % self.getCustomScript()) 
     209 
     210 
     211class CanonicalUrlViewlet(ViewletBase): 
    205212    """ Simple viewlet for canonical url link rendering. 
    206213    """ 
    207     def render( self ): 
    208         seoc = getMultiAdapter((self.context, self.request), name=u'seo_context') 
     214    def render(self): 
     215        seoc = getMultiAdapter((self.context, self.request), 
     216                               name=u'seo_context') 
    209217        if seoc['seo_canonical']: 
    210             return """<link rel="canonical" href="%s" />""" % seoc['seo_canonical'] 
     218            return """<link rel="canonical" href="%s" />""" \ 
     219                   % seoc['seo_canonical'] 
    211220        return "" 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/browser/views.py

    r3007 r3134  
    1313 
    1414from quintagroup.canonicalpath.interfaces import ICanonicalLink 
    15 from quintagroup.canonicalpath.adapters import PROPERTY_LINK as CANONICAL_PROPERTY 
     15from quintagroup.canonicalpath.adapters import PROPERTY_LINK \ 
     16                                               as CANONICAL_PROPERTY 
    1617 
    1718from quintagroup.seoptimizer.browser.seo_configlet import ISEOConfigletSchema 
     
    2425PROP_CUSTOM_PREFIX = 'qSEO_custom_' 
    2526 
     27 
    2628# Ram cache function, which depends on plone instance and time 
    2729def plone_instance_time(method, self, *args, **kwargs): 
    2830    return (self.pps.portal(), time() // (60 * 60)) 
    2931 
    30 class SEOContext( BrowserView ): 
     32 
     33class SEOContext(BrowserView): 
    3134    """ This class contains methods that allows to edit html header meta tags. 
    3235    """ 
     
    3437    def __init__(self, *args, **kwargs): 
    3538        super(SEOContext, self).__init__(*args, **kwargs) 
    36         self.pps = queryMultiAdapter((self.context, self.request), name="plone_portal_state") 
    37         self.pcs = queryMultiAdapter((self.context, self.request), name="plone_context_state") 
     39        self.pps = queryMultiAdapter((self.context, self.request), 
     40                                     name="plone_portal_state") 
     41        self.pcs = queryMultiAdapter((self.context, self.request), 
     42                                     name="plone_context_state") 
    3843        self.gseo = queryAdapter(self.pps.portal(), ISEOConfigletSchema) 
    3944        self._seotags = self._getSEOTags() 
     
    4550    def _getSEOTags(self): 
    4651        seotags = { 
    47             "seo_title": self.getSEOProperty( 'qSEO_title', default=self.pcs.object_title() ), 
    48             "seo_robots": self.getSEOProperty( 'qSEO_robots', default='ALL'), 
    49             "seo_description": self.getSEOProperty( 'qSEO_description', accessor='Description' ), 
    50             "seo_distribution": self.getSEOProperty( 'qSEO_distribution', default="Global"), 
     52            "seo_title": self.getSEOProperty('qSEO_title', 
     53                                             default=self.pcs.object_title()), 
     54            "seo_robots": self.getSEOProperty('qSEO_robots', default='ALL'), 
     55            "seo_description": self.getSEOProperty('qSEO_description', 
     56                                                   accessor='Description'), 
     57            "seo_distribution": self.getSEOProperty('qSEO_distribution', 
     58                                                    default="Global"), 
    5159            "seo_customMetaTags": self.seo_customMetaTags(), 
    5260            # "seo_localCustomMetaTags": self.seo_localCustomMetaTags(), 
    5361            # "seo_globalCustomMetaTags": self.seo_globalCustomMetaTags(), 
    54             "seo_html_comment": self.getSEOProperty( 'qSEO_html_comment', default='' ), 
    55             "meta_keywords": self.getSEOProperty('qSEO_keywords', 'Subject', ()), 
     62            "seo_html_comment": self.getSEOProperty('qSEO_html_comment', 
     63                                                    default=''), 
     64            "meta_keywords": self.getSEOProperty('qSEO_keywords', 
     65                                                 'Subject', ()), 
    5666            "seo_keywords": self.getSEOProperty('qSEO_keywords', default=()), 
    5767            "seo_canonical": self.getCanonical(), 
     
    5969            "has_seo_title": self.context.hasProperty('qSEO_title'), 
    6070            "has_seo_robots": self.context.hasProperty('qSEO_robots'), 
    61             "has_seo_description": self.context.hasProperty( 'qSEO_description'), 
    62             "has_seo_distribution": self.context.hasProperty( 'qSEO_distribution'), 
     71            "has_seo_description": \ 
     72                     self.context.hasProperty('qSEO_description'), 
     73            "has_seo_distribution": \ 
     74                     self.context.hasProperty('qSEO_distribution'), 
    6375            "has_html_comment": self.context.hasProperty('qSEO_html_comment'), 
    6476            "has_seo_keywords": self.context.hasProperty('qSEO_keywords'), 
    6577            "has_seo_canonical": self.context.hasProperty(CANONICAL_PROPERTY), 
    6678            } 
    67         #seotags["seo_nonEmptylocalMetaTags"] = bool(seotags["seo_localCustomMetaTags"]) 
     79        #seotags["seo_nonEmptylocalMetaTags"] = \ 
     80        #    bool(seotags["seo_localCustomMetaTags"]) 
    6881        return seotags 
    6982 
    70     def getSEOProperty( self, property_name, accessor='', default=None ): 
     83    def getSEOProperty(self, property_name, accessor='', default=None): 
    7184        """ Get value from seo property by property name. 
    7285        """ 
     
    90103        return default 
    91104 
    92     def seo_customMetaTags( self ): 
    93         """Returned seo custom metatags from default_custom_metatags property in seo_properties 
    94            (global seo custom metatags) with update from seo custom metatags properties 
    95            in context (local seo custom metatags). 
    96         """ 
    97         glob, loc = self.seo_globalCustomMetaTags(), self.seo_localCustomMetaTags() 
     105    def seo_customMetaTags(self): 
     106        """Returned seo custom metatags from default_custom_metatags property 
     107           in seo_properties (global seo custom metatags) with update from seo 
     108           custom metatags properties in context (local seo custom metatags). 
     109        """ 
     110        glob = self.seo_globalCustomMetaTags() 
     111        loc = self.seo_localCustomMetaTags() 
    98112        gnames = set(map(lambda x: x['meta_name'], glob)) 
    99113        lnames = set(map(lambda x: x['meta_name'], loc)) 
    100         # Get untouch global, override global in custom and new custom meta tags 
    101         untouchglob = [t for t in glob if t['meta_name'] in list(gnames - lnames)] 
     114        # Get untouch global, override global in custom 
     115        # and new custom meta tags 
     116        untouchglob = [t for t in glob \ 
     117                         if t['meta_name'] in list(gnames - lnames)] 
    102118        return untouchglob + loc 
    103119 
    104     def seo_globalWithoutLocalCustomMetaTags( self ): 
    105         """Returned seo custom metatags from default_custom_metatags property in seo_properties 
    106            (global seo custom metatags) without seo custom metatags from properties 
    107            in context (local seo custom metatags). 
    108         """ 
    109         glob, loc = self.seo_globalCustomMetaTags(), self.seo_localCustomMetaTags() 
     120    def seo_globalWithoutLocalCustomMetaTags(self): 
     121        """Returned seo custom metatags from default_custom_metatags property 
     122           in seo_properties (global seo custom metatags) without seo custom 
     123           metatags from properties in context (local seo custom metatags). 
     124        """ 
     125        glob = self.seo_globalCustomMetaTags() 
     126        loc = self.seo_localCustomMetaTags() 
    110127        gnames = set(map(lambda x: x['meta_name'], glob)) 
    111128        lnames = set(map(lambda x: x['meta_name'], loc)) 
    112129        return [t for t in glob if t['meta_name'] in list(gnames - lnames)] 
    113130 
    114     def seo_localCustomMetaTags( self ): 
    115         """ Returned seo custom metatags from properties in context (local seo custom metatags). 
     131    def seo_localCustomMetaTags(self): 
     132        """ Returned seo custom metatags from properties in 
     133            context (local seo custom metatags). 
    116134        """ 
    117135        result = [] 
     
    119137        context = aq_inner(self.context) 
    120138        for property, value in context.propertyItems(): 
    121             if property.startswith(property_prefix) and property[len(property_prefix):]: 
    122                 result.append({'meta_name'    : property[len(property_prefix):], 
    123                                'meta_content' : value}) 
     139            if property.startswith(property_prefix) and \ 
     140               property[len(property_prefix):]: 
     141                result.append({'meta_name': property[len(property_prefix):], 
     142                               'meta_content': value}) 
    124143        return result 
    125144 
    126145    @ram.cache(plone_instance_time) 
    127     def seo_globalCustomMetaTags( self ): 
    128         """ Returned seo custom metatags from default_custom_metatags property in seo_properties. 
     146    def seo_globalCustomMetaTags(self): 
     147        """ Returned seo custom metatags from default_custom_metatags property 
     148            in seo_properties. 
    129149        """ 
    130150        result = [] 
     
    133153                name_value = tag.split(SEPERATOR) 
    134154                if name_value[0]: 
    135                     result.append({'meta_name'    : name_value[0], 
    136                                    'meta_content' : len(name_value) == 2 and name_value[1] or ''}) 
     155                    result.append({'meta_name': name_value[0], 
     156                                   'meta_content': len(name_value) == 2 and \ 
     157                                                    name_value[1] or ''}) 
    137158        return result 
    138159 
     
    142163 
    143164 
    144 class SEOContextPropertiesView( BrowserView ): 
     165class SEOContextPropertiesView(BrowserView): 
    145166    """ This class contains methods that allows to manage seo properties. 
    146167    """ 
     
    153174        self.gseo = queryAdapter(self.pps.portal(), ISEOConfigletSchema) 
    154175 
    155  
    156     def test( self, condition, first, second ): 
     176    def test(self, condition, first, second): 
    157177        """ 
    158178        """ 
     
    167187        """ Add a new property. 
    168188 
    169             Sets a new property with the given id, value and type or changes it. 
     189            Sets a new property with the given id, value and type or 
     190            changes it. 
    170191        """ 
    171192        context = aq_inner(self.context) 
     
    184205        state = '' 
    185206        delete_list, seo_overrides_keys, seo_keys = [], [], [] 
    186         seo_items = dict([(k[len(SEO_PREFIX):],v) for k,v in kw.items() if k.startswith(SEO_PREFIX)]) 
     207        seo_items = dict([(k[len(SEO_PREFIX):], v) \ 
     208                         for k, v in kw.items() if k.startswith(SEO_PREFIX)]) 
    187209        for key in seo_items.keys(): 
    188210            if key.endswith(SUFFIX): 
     
    194216                self.manageSEOCustomMetaTagsProperties(**kw) 
    195217            else: 
    196                 if seo_key in seo_overrides_keys and seo_items.get(seo_key+SUFFIX): 
     218                if seo_key in seo_overrides_keys and \ 
     219                              seo_items.get(seo_key + SUFFIX): 
    197220                    seo_value = seo_items[seo_key] 
    198221                    if seo_key == 'canonical': 
    199222                        try: 
    200                             ICanonicalLink(self.context).canonical_link = seo_value 
     223                            i_canonical_link = ICanonicalLink(self.context) 
     224                            i_canonical_link.canonical_link = seo_value 
    201225                        except InvalidValue, e: 
    202226                            state = "'%s' - wrong canonical url" % str(e) 
    203227                    else: 
    204228                        t_value = 'string' 
    205                         if type(seo_value)==type([]) or type(seo_value)==type(()): t_value = 'lines' 
    206                         state = self.setProperty(PROP_PREFIX+seo_key, seo_value, type=t_value) 
     229                        if type(seo_value) == type([]) or \ 
     230                           type(seo_value) == type(()): 
     231                            t_value = 'lines' 
     232                        state = self.setProperty(PROP_PREFIX + seo_key, 
     233                                                 seo_value, type=t_value) 
    207234                    if state: 
    208235                        return state 
    209236                elif seo_key == 'canonical': 
    210237                    del ICanonicalLink(self.context).canonical_link 
    211                 elif context.hasProperty(PROP_PREFIX+seo_key): 
    212                     delete_list.append(PROP_PREFIX+seo_key) 
     238                elif context.hasProperty(PROP_PREFIX + seo_key): 
     239                    delete_list.append(PROP_PREFIX + seo_key) 
    213240        if delete_list: 
    214241            context.manage_delProperties(delete_list) 
     
    220247        context = aq_inner(self.context) 
    221248        for tag in custommetatags: 
    222             self.setProperty('%s%s' % (PROP_CUSTOM_PREFIX, tag['meta_name']), tag['meta_content']) 
     249            self.setProperty('%s%s' % (PROP_CUSTOM_PREFIX, tag['meta_name']), 
     250                             tag['meta_content']) 
    223251 
    224252    def delAllSEOCustomMetaTagsProperties(self): 
     
    228256        delete_list = [] 
    229257        for property, value in context.propertyItems(): 
    230             if property.startswith(PROP_CUSTOM_PREFIX)  and not property == PROP_CUSTOM_PREFIX: 
     258            if property.startswith(PROP_CUSTOM_PREFIX) and \ 
     259                                   not property == PROP_CUSTOM_PREFIX: 
    231260                delete_list.append(property) 
    232261        if delete_list: 
     
    243272                if name_value[0]: 
    244273                    globalCustomMetaTags.append( 
    245                         {'meta_name' : name_value[0], 
    246                          'meta_content' : len(name_value) > 1 and name_value[1] or ''}) 
     274                        {'meta_name': name_value[0], 
     275                         'meta_content': len(name_value) > 1 and \ 
     276                                         name_value[1] or ''}) 
    247277        for tag in custommetatags: 
    248278            meta_name, meta_content = tag['meta_name'], tag['meta_content'] 
    249279            if meta_name: 
    250280                if not [gmt for gmt in globalCustomMetaTags \ 
    251                         if (gmt['meta_name']==meta_name and gmt['meta_content']==meta_content)]: 
    252                     self.setProperty('%s%s' % (PROP_CUSTOM_PREFIX, meta_name), meta_content) 
     281                        if (gmt['meta_name'] == meta_name and \ 
     282                            gmt['meta_content'] == meta_content)]: 
     283                    self.setProperty('%s%s' % (PROP_CUSTOM_PREFIX, meta_name), 
     284                                     meta_content) 
    253285 
    254286    def manageSEOCustomMetaTagsProperties(self, **kw): 
    255         """ Update seo custom metatags properties, if enabled checkbox override or delete properties. 
     287        """ Update seo custom metatags properties, if enabled checkbox override 
     288            or delete properties. 
    256289 
    257290            Change object properties by passing either a mapping object 
     
    271304        # and may contains stop words in different languages. 
    272305        # So we must return encoded strings. 
    273         sw = map(lambda x:unicode.encode(x, enc), self.gseo.stop_words) 
     306        sw = map(lambda x: unicode.encode(x, enc), self.gseo.stop_words) 
    274307        return str(sw) 
    275308 
     
    282315        return str(fields_id) 
    283316 
    284     def __call__( self ): 
     317    def __call__(self): 
    285318        """ Perform the update seo properties and redirect if necessary, 
    286319            or render the page Call method. 
     
    290323        form = self.request.form 
    291324        submitted = form.get('form.submitted', False) 
    292         #import pdb;pdb.set_trace() 
    293325        if submitted: 
    294326            msgtype = "info" 
     
    299331                    msg = _('seoproperties_saved', 
    300332                            default=u'Content SEO properties have been saved.') 
    301                     kwargs = {'modification_date' : DateTime()}  
     333                    kwargs = {'modification_date': DateTime()} 
    302334                    context.plone_utils.contentEdit(context, **kwargs) 
    303335                else: 
     
    305337            else: 
    306338                # Cancel 
    307                 msg = _('seoproperties_canceled', 
    308                         default=u'No content SEO properties have been changed.') 
     339                msg = _('seoproperties_canceled', default=u'No content SEO ' \ 
     340                        'properties have been changed.') 
    309341 
    310342            context.plone_utils.addPortalMessage(msg, msgtype) 
     
    315347 
    316348 
    317 class VisibilityCheckerView( BrowserView ): 
     349class VisibilityCheckerView(BrowserView): 
    318350    """ This class contains methods that visibility checker. 
    319351    """ 
     
    323355        """ 
    324356        context = aq_inner(self.context) 
    325         plone = queryMultiAdapter((self, self.request),name="plone_portal_state").portal() 
     357        plone = queryMultiAdapter((self, self.request), 
     358                                  name="plone_portal_state").portal() 
    326359        adapter = ISEOConfigletSchema(plone) 
    327360        return bool(self.context.portal_type in adapter.types_seo_enabled) 
    328  
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/interfaces.py

    r2139 r3134  
    11from zope.interface import Interface 
     2 
    23 
    34class IMetaKeywords(Interface): 
     
    89        """ 
    910 
     11 
    1012class IMappingMetaTags(Interface): 
    1113    """ 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/listMetaTags.py

    r2139 r3134  
    22 
    33originalListMetaTags = PloneTool.listMetaTags 
     4 
    45 
    56def qsListMetaTags(self, context): 
     
    1112    return {} 
    1213 
     14 
    1315def qsListMetaTagsOriginal(self, context): 
    1416    """ Returned original method listMetaTags 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/setuphandlers.py

    r2139 r3134  
    44 
    55from config import SUPPORT_BLAYER 
    6      
     6 
    77from Products.CMFCore.utils import getToolByName 
    88 
    99logger = logging.getLogger('quintagroup.seoptimizer') 
     10 
    1011 
    1112def removeActions(site): 
     
    1819        if idxs: 
    1920            ptype.deleteActions(idxs) 
    20             logger.log(logging.INFO, "Deleted \"SEO Properties\" action for %s type." % ptype.id) 
     21            msg_delete = "Deleted \"SEO Properties\" action for %s type." 
     22            logger.log(logging.INFO, msg_delete % ptype.id) 
     23 
    2124 
    2225def removeConfiglet(site): 
     
    2932        logger.log(logging.INFO, "Unregistered \"%s\" configlet." % conf_id) 
    3033 
     34 
    3135def removeBrowserLayer(site): 
    3236    """ Remove browser layer. 
     
    3842    from plone.browserlayer.interfaces import ILocalBrowserLayerType 
    3943 
    40     name="qSEOptimizer" 
     44    name = "qSEOptimizer" 
    4145    site = getSiteManager(site) 
    4246    registeredLayers = [r.name for r in site.registeredUtilities() 
     
    4549        unregister_layer(name, site_manager=site) 
    4650        logger.log(logging.INFO, "Unregistered \"%s\" browser layer." % name) 
     51 
    4752 
    4853def uninstall(context): 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/base.py

    r3011 r3134  
    3838ptc.setupPloneSite() 
    3939 
     40 
    4041class NotInstalled(PloneSite): 
    4142    """ Only package register, without installation into portal 
     
    7172    def tearDown(cls): 
    7273        ptc_setup._placefulTearDown() 
    73          
     74 
    7475 
    7576class MixinTestCase: 
     
    8182            authenticator = self.portal.restrictedTraverse("@@authenticator") 
    8283        except: 
    83             handle  = "" 
     84            handle = "" 
    8485        else: 
    8586            html = authenticator.authenticator() 
     
    99100    layer = Installed 
    100101 
     102 
    101103class TestCaseNotInstalled(MixinTestCase, ptc.PloneTestCase): 
    102104    layer = NotInstalled 
     
    109111        self.installBrowserLayer() 
    110112 
     113 
    111114class FunctionalTestCaseNotInstalled(MixinTestCase, ptc.FunctionalTestCase): 
    112115    layer = NotInstalled 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testBugs.py

    r3125 r3134  
    2222 
    2323    def afterSetUp(self): 
    24         self.basic_auth = ':'.join((portal_owner,default_password)) 
     24        self.basic_auth = ':'.join((portal_owner, default_password)) 
    2525        self.loginAsPortalOwner() 
    2626        # prepare test document 
     
    3737 
    3838        md_before = self.my_doc.modification_date 
    39         self.publish(path=self.mydoc_path+'/@@seo-context-properties', 
     39        self.publish(path=self.mydoc_path + '/@@seo-context-properties', 
    4040                     basic=self.basic_auth, request_method='POST', 
    4141                     stdin=StringIO(urllib.urlencode(form_data))) 
     
    7373        """ 
    7474        curl = re.compile('<link\srel\s*=\s*"canonical"\s+' \ 
    75                          '[^>]*href\s*=\s*\"([^\"]*)\"[^>]*>', re.S|re.M) 
    76         # When adapter registered for the object - canoncal link present on the page 
    77         self.assertNotEqual( queryAdapter(self.my_doc, ICanonicalLink), None) 
     75                          '[^>]*href\s*=\s*\"([^\"]*)\"[^>]*>', re.S | re.M) 
     76        # When adapter registered for the object - canoncal link 
     77        # present on the page 
     78        self.assertNotEqual(queryAdapter(self.my_doc, ICanonicalLink), None) 
    7879 
    7980        res = self.publish(path=self.mydoc_path, basic=self.basic_auth) 
     
    8485        #     - canonical link will be absent on the page 
    8586        gsm = getGlobalSiteManager() 
    86         gsm.unregisterAdapter(DefaultCanonicalLinkAdapter, [ITraversable,], 
     87        gsm.unregisterAdapter(DefaultCanonicalLinkAdapter, [ITraversable, ], 
    8788                              ICanonicalLink) 
    88         self.assertEqual( queryAdapter(self.my_doc, ICanonicalLink), None) 
     89        self.assertEqual(queryAdapter(self.my_doc, ICanonicalLink), None) 
    8990 
    9091        res = self.publish(path=self.mydoc_path, basic=self.basic_auth) 
     
    9293 
    9394        # register adapter back in the global site manager 
    94         gsm.registerAdapter(DefaultCanonicalLinkAdapter, [ITraversable,], 
     95        gsm.registerAdapter(DefaultCanonicalLinkAdapter, [ITraversable, ], 
    9596                            ICanonicalLink) 
    9697 
     
    104105 
    105106    def test_escape_characters_title(self): 
    106         """Change escape characters in title of SEO properties  
    107            Bug url http://plone.org/products/plone-seo/issues/31  
    108         """        
     107        """Change escape characters in title of SEO properties 
     108           Bug url http://plone.org/products/plone-seo/issues/31 
     109        """ 
    109110        from cgi import escape 
    110111        title = 'New <i>Title</i>' 
     
    113114                     'form.button.Save': "Save", 
    114115                     'form.submitted:int': 1} 
    115              
    116         res = self.publish(path=self.mydoc_path+'/@@seo-context-properties', 
     116 
     117        res = self.publish(path=self.mydoc_path + '/@@seo-context-properties', 
    117118                     basic=self.basic_auth, request_method='POST', 
    118119                     stdin=StringIO(urllib.urlencode(form_data))) 
    119120        html = self.publish(self.mydoc_path, self.basic_auth).getBody() 
    120         m = re.match('.*<title>\\s*%s\\s*</title>' % escape(title), html, re.S|re.M) 
    121         self.assert_(m, 'Title is not escaped properly.')        
     121        m = re.match('.*<title>\\s*%s\\s*</title>' % escape(title), html, 
     122                     re.S | re.M) 
     123        self.assert_(m, 'Title is not escaped properly.') 
    122124 
    123125    def test_escape_characters_comment(self): 
    124         """Change escape characters in comment of SEO properties  
    125         """        
     126        """Change escape characters in comment of SEO properties 
     127        """ 
    126128        from cgi import escape 
    127129        comment = 'New <i>comment</i>' 
     
    132134                     'form.button.Save': "Save", 
    133135                     'form.submitted:int': 1} 
    134              
    135         res = self.publish(path=self.mydoc_path+'/@@seo-context-properties', 
    136                      basic=self.basic_auth, request_method='POST', 
    137                      stdin=StringIO(urllib.urlencode(form_data))) 
     136 
     137        res = self.publish(path=self.mydoc_path + '/@@seo-context-properties', 
     138                           basic=self.basic_auth, request_method='POST', 
     139                           stdin=StringIO(urllib.urlencode(form_data))) 
    138140        html = self.publish(self.mydoc_path, self.basic_auth).getBody() 
    139         m = re.match('.*<!--\\s*%s\\s*-->' % escape(comment), html, re.S|re.M) 
    140         self.assert_(m, 'Comment is not escaped properly.')        
     141        m = re.match('.*<!--\\s*%s\\s*-->' % escape(comment), html, 
     142                     re.S | re.M) 
     143        self.assert_(m, 'Comment is not escaped properly.') 
    141144 
    142145    def test_bug_custom_metatags_update(self): 
     
    145148        request = self.portal.REQUEST 
    146149        directlyProvides(request, IPloneSEOLayer) 
    147         seo_context_props = getMultiAdapter((page, request), name="seo-context-properties") 
     150        seo_context_props = getMultiAdapter((page, request), 
     151                                            name="seo-context-properties") 
    148152        # Set default custom meta tag without default value (tag name only) 
    149153        self.gseo = queryAdapter(self.portal, ISEOConfigletSchema) 
    150         self.gseo.default_custom_metatags = ["test_tag",] 
     154        self.gseo.default_custom_metatags = ["test_tag", ] 
    151155        try: 
    152             # Breakage on updating custom metatag with seo-context-properties view 
     156            # Breakage on updating custom metatag 
     157            # with seo-context-properties view 
    153158            seo_context_props.updateSEOCustomMetaTagsProperties([]) 
    154159        except IndexError: 
    155             self.fail("Error in calculating of default tag value, when only tag name set "\ 
    156                       "in default_custom_metatags property of the configlet.") 
     160            self.fail("Error in calculating of default tag value, when only "\ 
     161                      "tag name set in default_custom_metatags property of "\ 
     162                      "the configlet.") 
    157163 
    158164 
     
    168174                        ['Member'], []) 
    169175        uf.userFolderAddUser(editor_id, test_pswd, 
    170                         ['Member','Editor'], []) 
    171  
    172         self.member_auth = '%s:%s'%(member_id, test_pswd) 
    173         self.editor_auth = '%s:%s'%(editor_id, test_pswd) 
     176                        ['Member', 'Editor'], []) 
     177 
     178        self.member_auth = '%s:%s' % (member_id, test_pswd) 
     179        self.editor_auth = '%s:%s' % (editor_id, test_pswd) 
    174180        self.portal_url = '/'.join(self.portal.getPhysicalPath()) 
    175181 
     
    190196        rexp = re.compile('<a\s+[^>]*' \ 
    191197               'href="[a-zA-Z0-9\:\/_-]*/@@seo-context-properties"[^>]*>'\ 
    192                '\s*SEO Properties\s*</a>', re.I|re.S) 
     198               '\s*SEO Properties\s*</a>', re.I | re.S) 
    193199        # Anonymous: NO SEO Properties link 
    194200        res = self.publish(path=self.portal_url).getBody() 
    195201        self.assertEqual(rexp.search(res), None) 
    196202        # Member: NO 'SEO Properties' link 
    197         res = self.publish(path=self.portal_url, basic=self.member_auth).getBody() 
     203        res = self.publish(path=self.portal_url, 
     204                           basic=self.member_auth).getBody() 
    198205        self.assertEqual(rexp.search(res), None) 
    199206        # Editor: PRESENT 'SEO Properties' link 
    200         res = self.publish(path=self.portal_url, basic=self.editor_auth).getBody() 
     207        res = self.publish(path=self.portal_url, 
     208                           basic=self.editor_auth).getBody() 
    201209        self.assertNotEqual(rexp.search(res), None) 
    202210 
     
    206214        # Anonymous: can NOT ACCESS 
    207215        headers = self.publish(path=test_url).headers 
    208         self.assertEqual( headers.get('bobo-exception-type',""), 'Unauthorized', 
    209             "No 'Unauthorized' exception rised for Anonymous on '@@seo-context-properties' view") 
     216        self.assertEqual(headers.get('bobo-exception-type', ""), 
     217                         'Unauthorized', "No 'Unauthorized' exception rised " \ 
     218                         "for Anonymous on '@@seo-context-properties' view") 
    210219        # Member: can NOT ACCESS 
    211220        status = self.publish(path=test_url, basic=self.member_auth).headers 
    212         self.assertEqual( headers.get('bobo-exception-type',""), 'Unauthorized', 
    213             "No 'Unauthorized' exception rised for Member on '@@seo-context-properties' view") 
     221        self.assertEqual(headers.get('bobo-exception-type', ""), 
     222                         'Unauthorized', "No 'Unauthorized' exception rised " \ 
     223                         "for Member on '@@seo-context-properties' view") 
    214224        # Editor: CAN Access 
    215225        res = self.publish(path=test_url, basic=self.editor_auth) 
    216226        self.assertEqual(res.status, 200) 
    217  
    218227 
    219228    def test_tab_edit(self): 
     
    224233                     'form.submitted:int': 1} 
    225234        res = self.publish(path=test_url, basic=self.editor_auth, 
    226                   request_method='POST', stdin=StringIO(urllib.urlencode(form_data))) 
     235                           request_method='POST', 
     236                           stdin=StringIO(urllib.urlencode(form_data))) 
    227237        self.assertNotEqual(res.status, 200) 
    228238 
     
    234244    suite.addTest(makeSuite(TestBug24AtPloneOrg)) 
    235245    return suite 
    236  
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testCanonicalURL.py

    r3012 r3134  
    11from quintagroup.canonicalpath.interfaces import ICanonicalLink 
    22from base import * 
     3 
    34 
    45class TestCanonicalURL(FunctionalTestCase): 
    56 
    67    def afterSetUp(self): 
    7         self.basic_auth = ':'.join((portal_owner,default_password)) 
     8        self.basic_auth = ':'.join((portal_owner, default_password)) 
    89        self.loginAsPortalOwner() 
    910        # Preparation for functional testing 
     
    1213        self.mydoc_path = "/%s" % self.mydoc.absolute_url(1) 
    1314        self.curl = re.compile('<link\srel\s*=\s*"canonical"\s+' \ 
    14             '[^>]*href\s*=\s*\"([^\"]*)\"[^>]*>', re.S|re.M) 
     15                               '[^>]*href\s*=\s*\"([^\"]*)\"[^>]*>', 
     16                                re.S | re.M) 
    1517 
    1618    def test_CanonicalURL(self): 
     
    1921        mydoc_url = self.mydoc.absolute_url() 
    2022 
    21         self.assertTrue([1 for curl in foundcurls if curl==mydoc_url], 
     23        self.assertTrue([1 for curl in foundcurls if curl == mydoc_url], 
    2224           "Wrong CANONICAL URL for document: %s, all must be: %s" % ( 
    2325           foundcurls, mydoc_url)) 
     
    2729        # Update canonical url property 
    2830        self.publish(self.mydoc_path + '/@@seo-context-properties?' \ 
    29            'seo_canonical_override=checked&seo_canonical=%s&' \ 
    30            'form.submitted=1&form.button.Save=Save' % mydoc_url_new, self.basic_auth) 
     31                     'seo_canonical_override=checked&seo_canonical=%s&' \ 
     32                     'form.submitted=1&form.button.Save=Save' % mydoc_url_new, 
     33                     self.basic_auth) 
    3134        # Test updated canonical url 
    3235        html = self.publish(self.mydoc_path, self.basic_auth).getBody() 
     
    3538        qseo_url = ICanonicalLink(self.mydoc).canonical_link 
    3639        self.assertTrue(qseo_url == mydoc_url_new, 
    37            "Not set 'qSEO_canonical' property") 
    38         self.assertTrue([1 for curl in foundcurls if curl==mydoc_url_new], 
    39            "Wrong CANONICAL URL for document: %s, all must be: %s" % ( 
    40            foundcurls, mydoc_url_new)) 
     40                        "Not set 'qSEO_canonical' property") 
     41        self.assertTrue([1 for curl in foundcurls if curl == mydoc_url_new], 
     42                        "Wrong CANONICAL URL for document: %s, all must be: %s" 
     43                        % (foundcurls, mydoc_url_new)) 
    4144 
    4245    def test_defaultCanonical(self): 
     
    6669        mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_link 
    6770        self.assertTrue(newcpath == mydoc_catalog_canonical, 
    68             "canonical path get by adapter: '%s' not equals to cataloged one: '%s'" % ( 
    69              newcpath, mydoc_catalog_canonical)) 
     71                        "canonical path get by adapter: '%s' not equals to "\ 
     72                        "cataloged one: '%s'" % (newcpath, 
     73                                                 mydoc_catalog_canonical)) 
    7074 
    7175    def test_canonicalValidation(self): 
     
    7377        # Update canonical url property 
    7478        html = self.publish(self.mydoc_path + '/@@seo-context-properties?' \ 
    75                'seo_canonical_override=checked&seo_canonical=%s&' \ 
    76                'form.submitted=1&form.button.Save=Save' % wrong_canonical, self.basic_auth).getBody() 
     79                            'seo_canonical_override=checked&seo_canonical=%s&'\ 
     80                            'form.submitted=1&form.button.Save=Save' 
     81                            % wrong_canonical, self.basic_auth).getBody() 
    7782        self.assertTrue("wrong canonical url" in html, 
    7883                        "Canonical url not validated") 
     
    8691        # remove canonical url customization 
    8792        self.publish(self.mydoc_path + '/@@seo-context-properties?' \ 
    88            'seo_canonical=%s&seo_canonical_override=&form.submitted=1&form.button.Save=Save' % newcanonical, 
    89             self.basic_auth) 
     93                     'seo_canonical=%s&seo_canonical_override=&'\ 
     94                     'form.submitted=1&form.button.Save=Save' % newcanonical, 
     95                      self.basic_auth) 
    9096 
    9197        mydoc_canonical = ICanonicalLink(self.mydoc).canonical_link 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testConfiglet.py

    r2888 r3134  
    55from quintagroup.seoptimizer.browser.seo_configlet import ISEOConfigletSchema 
    66 
     7 
    78class TestConfiglet(FunctionalTestCase): 
    89 
     
    1011        self.sp = self.portal.portal_properties.site_properties 
    1112        self.seo = self.portal.portal_properties.seo_properties 
    12         self.basic_auth = ':'.join((portal_owner,default_password)) 
     13        self.basic_auth = ':'.join((portal_owner, default_password)) 
    1314        self.loginAsPortalOwner() 
    14         self.save_url = self.portal.id+'/@@seo-controlpanel?form.actions.save=1' \ 
    15             '&_authenticator=%s' % self._getauth() 
     15        self.save_url = self.portal.id + '/@@seo-controlpanel?' \ 
     16                        'form.actions.save=1&_authenticator=%s' \ 
     17                        % self._getauth() 
    1618 
    1719    def test_exposeDCMetaTags_On(self): 
     
    2830        expect = ('test', 'custom', 'metatags') 
    2931        formdata = "\n".join(expect) 
    30         self.publish(self.save_url + '&form.default_custom_metatags=%s'%formdata, 
    31              self.basic_auth) 
     32        self.publish(self.save_url + '&form.default_custom_metatags=%s' 
     33                     % formdata, self.basic_auth) 
    3234 
    3335        dcm = self.seo.getProperty("default_custom_metatags", ()) 
    3436        self.assertTrue(dcm == expect, '"default_custom_metatags" property ' \ 
    35             'contains: "%s", must: "%s"' % (dcm, expect)) 
     37                        'contains: "%s", must: "%s"' % (dcm, expect)) 
    3638 
    3739    def test_defaultCustomMetatags_Off(self): 
     
    3941        self.seo._updateProperty("default_custom_metatags", data) 
    4042        self.publish(self.save_url + '&form.default_custom_metatags=', 
    41              self.basic_auth) 
     43                     self.basic_auth) 
    4244 
    4345        dcm = self.seo.getProperty("default_custom_metatags", ()) 
    4446        self.assertTrue(dcm == (), '"default_custom_metatags" property ' \ 
    45             'contains: "%s", must be empty"' % str(dcm)) 
     47                        'contains: "%s", must be empty"' % str(dcm)) 
    4648 
    4749    def test_metatagsOrder_On(self): 
    4850        expect = ('test', 'metatags', 'order') 
    4951        formdata = "\n".join(expect) 
    50         self.publish(self.save_url + '&form.metatags_order=%s'%formdata, 
    51              self.basic_auth) 
     52        self.publish(self.save_url + '&form.metatags_order=%s' % formdata, 
     53                     self.basic_auth) 
    5254 
    5355        mo = self.seo.getProperty("metatags_order", ()) 
    5456        self.assertTrue(mo == expect, '"metatags_order" property ' \ 
    55             'contains: "%s", must: "%s"' % (mo, expect)) 
     57                        'contains: "%s", must: "%s"' % (mo, expect)) 
    5658 
    5759    def test_metatagsOrder_Off(self): 
     
    5961        self.seo._updateProperty("metatags_order", data) 
    6062        self.publish(self.save_url + '&form.metatags_order=', 
    61              self.basic_auth) 
     63                     self.basic_auth) 
    6264 
    6365        mo = self.seo.getProperty("metatags_order", ()) 
    6466        self.assertTrue(mo == (), '"metatags_order" property ' \ 
    65             'contains: "%s", must be empty"' % str(mo)) 
     67                        'contains: "%s", must be empty"' % str(mo)) 
    6668 
    6769    def test_typesSEOEnabled_On(self): 
    6870        expect = 'Event' 
    69         self.publish(self.save_url + "&form.types_seo_enabled=%s" % expect, self.basic_auth) 
     71        self.publish(self.save_url + "&form.types_seo_enabled=%s" % expect, 
     72                     self.basic_auth) 
    7073        tse = self.seo.getProperty("content_types_with_seoproperties", ()) 
    7174        self.assertTrue(tse == (expect,), 
    72             '"content_types_with_seoproperties" property contains: ' \ 
    73             '"%s", must: "%s"' % (tse, expect)) 
     75                        '"content_types_with_seoproperties" property ' \ 
     76                        'contains:" %s", must: "%s"' % (tse, expect)) 
    7477 
    7578    def test_typesSEOEnabled_Off(self): 
     
    7881 
    7982        tse = self.seo.getProperty("content_types_with_seoproperties", ()) 
    80         self.assertTrue(tse == (), '"content_types_with_seoproperties" property ' \ 
    81             'contains: "%s", must be empty"' % str(tse)) 
     83        self.assertTrue(tse == (), '"content_types_with_seoproperties" ' \ 
     84                        'property contains: "%s", must be empty"' % str(tse)) 
    8285 
    8386    def test_CustomScriptAdd(self): 
     
    102105        expect = ('field1', 'field2') 
    103106        formdata = "\n".join(expect) 
    104         self.publish(self.save_url + '&form.fields=%s'%formdata, 
    105              self.basic_auth) 
     107        self.publish(self.save_url + '&form.fields=%s' % formdata, 
     108                     self.basic_auth) 
    106109 
    107110        f = self.seo.getProperty("fields", ()) 
     
    113116        self.seo._updateProperty("fields", data) 
    114117        self.publish(self.save_url + '&form.fields=', 
    115              self.basic_auth) 
     118                     self.basic_auth) 
    116119 
    117120        f = self.seo.getProperty("fields", ()) 
    118121        self.assertTrue(f == (), '"fields" property ' \ 
    119             'contains: "%s", must be empty"' % str(f)) 
     122                        'contains: "%s", must be empty"' % str(f)) 
    120123 
    121124    def test_stopWordsAdd(self): 
    122125        expect = ('sw1', 'sw2', 'sw3') 
    123126        formdata = "\n".join(expect) 
    124         self.publish(self.save_url + '&form.stop_words=%s'%formdata, 
    125              self.basic_auth) 
     127        self.publish(self.save_url + '&form.stop_words=%s' % formdata, 
     128                     self.basic_auth) 
    126129 
    127130        f = self.seo.getProperty("stop_words", ()) 
    128131        self.assertTrue(f == expect, '"stop_words" property ' \ 
    129             'contains: "%s", must: "%s"' % (f, expect)) 
     132                        'contains: "%s", must: "%s"' % (f, expect)) 
    130133 
    131134    def test_stopWordsDel(self): 
     
    133136        self.seo._updateProperty("stop_words", data) 
    134137        self.publish(self.save_url + '&form.stop_words=', 
    135              self.basic_auth) 
     138                     self.basic_auth) 
    136139 
    137140        f = self.seo.getProperty("stop_words", ()) 
    138141        self.assertTrue(f == (), '"stop_words" property ' \ 
    139             'contains: "%s", must be empty"' % str(f)) 
     142                        'contains: "%s", must be empty"' % str(f)) 
    140143 
    141144    def test_externalKeywordTest(self): 
    142145        fields = FormFields(ISEOConfigletSchema) 
    143146        ffield = fields.get("external_keywords_test") 
    144         self.assertTrue(ffield is not None, 'Not found "external_keywords_test" '\ 
    145             'field in ISEOConfigletSchema interface') 
     147        self.assertTrue(ffield is not None, 
     148                        'Not found "external_keywords_test" field in ' \ 
     149                        'ISEOConfigletSchema interface') 
    146150        self.assertTrue(IBool.providedBy(ffield.field), 
    147             '"external_keywords_test" is not boolean type field') 
     151                        '"external_keywords_test" is not boolean type field') 
    148152        self.assertTrue(ffield.field.default == False, 
    149             '"external_keywords_test" field default value is not set to False') 
     153                        '"external_keywords_test" field default value ' \ 
     154                        'is not set to False') 
    150155 
    151156    def test_externalKeyword_On(self): 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testContextForm.py

    r3012 r3134  
    3535METATAG = '.*(<meta\s+(?:(?:name="%s"\s*)|(?:content="%s"\s*)){2}/>)' 
    3636 
     37 
    3738class TestContextForm(FunctionalTestCase): 
    3839 
     
    4243        self.wf = self.portal.portal_workflow 
    4344 
    44         self.basic_auth = ':'.join((portal_owner,default_password)) 
     45        self.basic_auth = ':'.join((portal_owner, default_password)) 
    4546        self.loginAsPortalOwner() 
    4647 
     
    5152        self.abs_path = "/%s" % my_doc.absolute_url(1) 
    5253        # prepare seo context form data 
    53         self.sp.manage_changeProperties( 
    54             default_custom_metatags = 'metatag1|global_metatag1value\n' \ 
    55                                       'metatag4|global_metatag4value') 
     54        self.sp.manage_changeProperties(default_custom_metatags='metatag1|' \ 
     55                                        'global_metatag1value\nmetatag4|' \ 
     56                                        'global_metatag4value') 
    5657        st = '' 
    5758        for d in CUSTOM_METATAGS: 
    5859            st += '&seo_custommetatags.meta_name:records=%s' % d['meta_name'] 
    59             st += '&seo_custommetatags.meta_content:records=%s' % d['meta_content'] 
     60            st += '&seo_custommetatags.meta_content:records=%s' \ 
     61                  % d['meta_content'] 
    6062        # update seo properties for the test document and publish it 
    61         self.publish(path=self.abs_path+'/@@seo-context-properties', 
     63        self.publish(path=self.abs_path + '/@@seo-context-properties', 
    6264                     basic=self.basic_auth, request_method='POST', 
    63                      stdin=StringIO(urllib.urlencode(FORM)+st)) 
     65                     stdin=StringIO(urllib.urlencode(FORM) + st)) 
    6466        self.wf.doActionFor(my_doc, 'publish') 
    6567        # get html view of test document 
    6668        self.html = self.publish(self.abs_path, self.basic_auth).getBody() 
    6769 
    68  
    6970    def testTitle(self): 
    70         m = re.match('.*<title>\\s*hello world\\s*</title>', self.html, re.S|re.M) 
     71        m = re.match('.*<title>\\s*hello world\\s*</title>', self.html, 
     72                     re.S | re.M) 
    7173        self.assert_(m, 'Title not set in') 
    7274 
    7375    def testTitleDuplication(self): 
    74         """If we are not overriding page title and current page title equals title of the plone site 
    75         then there should be no concatenation of both titles. Only one should be displayed. 
     76        """If we are not overriding page title and current page title equals 
     77           title of the plone site then there should be no concatenation of 
     78           both titles. Only one should be displayed. 
    7679        """ 
    7780        # setup page with title equal to plone site's title 
     
    8083        my_doc2 = self.portal['my_doc2'] 
    8184        self.wf.doActionFor(my_doc2, 'publish') 
    82         html2 = self.publish('/'+my_doc2.absolute_url(1), self.basic_auth).getBody() 
     85        html2 = self.publish('/' + my_doc2.absolute_url(1), 
     86                             self.basic_auth).getBody() 
    8387 
    84         m = re.match('.*<title>\\s*%s\\s*</title>' % self.portal.Title(), html2, re.S|re.M) 
    85         self.assert_(m, 'Title is not set correctly, perhaps it is duplicated with plone site title') 
     88        m = re.match('.*<title>\\s*%s\\s*</title>' % self.portal.Title(), 
     89                     html2, re.S | re.M) 
     90        self.assert_(m, 'Title is not set correctly, perhaps it is ' \ 
     91                     'duplicated with plone site title') 
    8692 
    8793    def testDescription(self): 
    88         m = re.match(METATAG % ("description", FORM['seo_description']), self.html, re.S|re.M) 
     94        m = re.match(METATAG % ("description", FORM['seo_description']), 
     95                     self.html, re.S | re.M) 
    8996        self.assert_(m, 'Description not set in') 
    9097 
    9198    def testRobots(self): 
    92         m = re.match(METATAG % ("robots", FORM['seo_robots']), self.html, re.S|re.M) 
     99        m = re.match(METATAG % ("robots", FORM['seo_robots']), self.html, 
     100                     re.S | re.M) 
    93101        self.assert_(m, 'Robots not set in') 
    94102 
    95103    def testDistribution(self): 
    96         m = re.match(METATAG % ("distribution", FORM['seo_distribution']), self.html, re.S|re.M) 
     104        m = re.match(METATAG % ("distribution", FORM['seo_distribution']), 
     105                     self.html, re.S | re.M) 
    97106        self.assert_(m, 'Distribution not set in') 
    98107 
    99108    def testHTMLComments(self): 
    100         m = re.match('.*<!--\\s*no comments\\s*-->', self.html, re.S|re.M) 
     109        m = re.match('.*<!--\\s*no comments\\s*-->', self.html, re.S | re.M) 
    101110        self.assert_(m, 'Comments not set in') 
    102111 
    103112    def testTagsOrder(self): 
    104113        def is_match(html, mtorder): 
    105             return re.search('.*'.join(['<meta.*name="%s".*/>' %t \ 
    106                                         for t in mtorder]), html, re.S|re.M) 
     114            return re.search('.*'.join(['<meta.*name="%s".*/>' % t \ 
     115                                        for t in mtorder]), html, re.S | re.M) 
    107116 
    108         metatags_order = [t for t in self.sp.getProperty('metatags_order') if t in VIEW_METATAGS] 
    109         self.assert_(is_match(self.html, metatags_order), "Meta tags order not supported.") 
     117        metatags_order = [t for t in self.sp.getProperty('metatags_order') \ 
     118                            if t in VIEW_METATAGS] 
     119        self.assert_(is_match(self.html, metatags_order), 
     120                     "Meta tags order not supported.") 
    110121 
    111122        metatags_order.reverse() 
    112         self.assertFalse(is_match(self.html, metatags_order), "Meta tags order not supported.") 
     123        self.assertFalse(is_match(self.html, metatags_order), 
     124                         "Meta tags order not supported.") 
    113125 
    114         self.sp.manage_changeProperties(metatags_order = metatags_order) 
    115         self.assertFalse(is_match(self.html, metatags_order), "Meta tags order not supported.") 
     126        self.sp.manage_changeProperties(metatags_order=metatags_order) 
     127        self.assertFalse(is_match(self.html, metatags_order), 
     128                         "Meta tags order not supported.") 
    116129 
    117130        html = self.publish(self.abs_path, self.basic_auth).getBody() 
    118         self.assert_(is_match(html, metatags_order), "Meta tags order not supported.") 
    119  
     131        self.assert_(is_match(html, metatags_order), 
     132                     "Meta tags order not supported.") 
    120133 
    121134    def testCustomMetaTags(self): 
    122135        for tag in CUSTOM_METATAGS: 
    123136            m = re.match(METATAG % (tag['meta_name'], tag['meta_content']), 
    124                          self.html, re.S|re.M) 
     137                         self.html, re.S | re.M) 
    125138            if tag['meta_content']: 
    126                 self.assert_(m, "Custom meta tag %s not applied." % tag['meta_name']) 
     139                self.assert_(m, "Custom meta tag %s not applied." \ 
     140                             % tag['meta_name']) 
    127141            else: 
    128                 self.assert_(not m, "Meta tag %s has no content, but is present:" \ 
    129                                  " in the page." % tag['meta_name']) 
     142                self.assert_(not m, "Meta tag %s has no content, but is " \ 
     143                             "present: in the page." % tag['meta_name']) 
    130144 
    131         m = re.match(METATAG % ("metatag4", "global_metatag4value"), self.html, re.S|re.M) 
     145        m = re.match(METATAG % ("metatag4", "global_metatag4value"), self.html, 
     146                     re.S | re.M) 
    132147        self.assert_(m, "Global custom meta tag %s not applied." % 'metatag4') 
    133148 
    134149    def testDeleteCustomMetaTags(self): 
    135         self.sp.manage_changeProperties( 
    136             default_custom_metatags = 'metatag1|global_metatag1value') 
     150        self.sp.manage_changeProperties(default_custom_metatags='metatag1|' \ 
     151                                        'global_metatag1value') 
    137152        form_data = {'seo_custommetatags': CUSTOM_METATAGS, 
    138153                     'seo_custommetatags_override:int': 0, 
     
    143158        getUtility(IRAMCache).invalidateAll() 
    144159 
    145         self.publish(path=self.abs_path+'/@@seo-context-properties', 
     160        self.publish(path=self.abs_path + '/@@seo-context-properties', 
    146161                     basic=self.basic_auth, request_method='POST', 
    147162                     stdin=StringIO(urllib.urlencode(form_data))) 
    148163        html = self.publish(self.abs_path, self.basic_auth).getBody() 
    149164 
    150         m = re.match(METATAG % ("metatag4", "global_metatag4value"), html, re.S|re.M) 
    151         self.assert_(not m, "Global custom meta tag %s is prosent in the page." % 'metatag4') 
     165        m = re.match(METATAG % ("metatag4", "global_metatag4value"), html, 
     166                     re.S | re.M) 
     167        self.assert_(not m, "Global custom meta tag %s is prosent in the " \ 
     168                     "page." % 'metatag4') 
    152169 
    153         m = re.match(METATAG % ("metatag1", "global_metatag1value"), html, re.S|re.M) 
     170        m = re.match(METATAG % ("metatag1", "global_metatag1value"), html, 
     171                     re.S | re.M) 
    154172        self.assert_(m, "Global custom meta tag %s not applied." % 'metatag1') 
     173 
    155174 
    156175def test_suite(): 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testExposeDCMetaTags.py

    r2139 r3134  
    33from base import * 
    44 
    5 METATAG = '.*(<meta\s+(?:(?:name="%s"\s*)|(?:content="(?P<tagcontent>.*?)"\s*)){2}/>)' 
     5METATAG = '.*(<meta\s+(?:(?:name="%s"\s*)|(?:content="(?P<tagcontent>.' \ 
     6          '*?)"\s*)){2}/>)' 
     7 
    68 
    79class TestExposeDCMetaTags(FunctionalTestCase): 
     
    911    def afterSetUp(self): 
    1012        self.sp = self.portal.portal_properties.site_properties 
    11         self.basic_auth = ':'.join((portal_owner,default_password)) 
     13        self.basic_auth = ':'.join((portal_owner, default_password)) 
    1214        self.loginAsPortalOwner() 
    1315        # Preparation for functional testing 
     
    1618 
    1719    def test_propertyOff(self): 
    18         self.sp.manage_changeProperties(exposeDCMetaTags = False) 
    19         self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
    20         m1 = re.match(METATAG % "DC.format", self.html, re.S|re.M) 
    21         m2 = re.match(METATAG % "DC.distribution", self.html, re.S|re.M) 
    22         self.assert_(not (m1 or m2), 'DC meta tags avaliable when exposeDCMetaTags=False') 
     20        self.sp.manage_changeProperties(exposeDCMetaTags=False) 
     21        self.html = str(self.publish(self.portal.id + '/my_doc', 
     22                                     self.basic_auth)) 
     23        m1 = re.match(METATAG % "DC.format", self.html, re.S | re.M) 
     24        m2 = re.match(METATAG % "DC.distribution", self.html, re.S | re.M) 
     25        self.assert_(not (m1 or m2), 'DC meta tags avaliable when ' \ 
     26                     'exposeDCMetaTags=False') 
    2327 
    2428    def test_propertyOn(self): 
    25         self.sp.manage_changeProperties(exposeDCMetaTags = True) 
    26         self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
    27         m1 = re.match(METATAG % "DC.format", self.html, re.S|re.M) 
    28         m2 = re.match(METATAG % "DC.type", self.html, re.S|re.M) 
    29         self.assert_(m1 and m2, 'DC meta tags not avaliable when createManager=True') 
     29        self.sp.manage_changeProperties(exposeDCMetaTags=True) 
     30        self.html = str(self.publish(self.portal.id + '/my_doc', 
     31                                     self.basic_auth)) 
     32        m1 = re.match(METATAG % "DC.format", self.html, re.S | re.M) 
     33        m2 = re.match(METATAG % "DC.type", self.html, re.S | re.M) 
     34        self.assert_(m1 and m2, 'DC meta tags not avaliable when ' \ 
     35                     'createManager=True') 
    3036 
    3137    def test_descriptionInPropertyOff(self): 
    32         self.sp.manage_changeProperties(exposeDCMetaTags = False) 
     38        self.sp.manage_changeProperties(exposeDCMetaTags=False) 
    3339        self.my_doc.setDescription("My document description") 
    34         self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
    35         m = re.match(METATAG % "description", self.html, re.S|re.M) 
    36         self.assert_(m, 'No "description" meta tag when expose DC meta tags is Off') 
     40        self.html = str(self.publish(self.portal.id + '/my_doc', 
     41                                     self.basic_auth)) 
     42        m = re.match(METATAG % "description", self.html, re.S | re.M) 
     43        self.assert_(m, 'No "description" meta tag when expose DC meta tags ' \ 
     44                     'is Off') 
    3745 
    3846    def test_descriptionInPropertyOn(self): 
    39         self.sp.manage_changeProperties(exposeDCMetaTags = True) 
     47        self.sp.manage_changeProperties(exposeDCMetaTags=True) 
    4048        self.my_doc.setDescription("My document description") 
    41         self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
    42         m = re.match(METATAG % "description", self.html, re.S|re.M) 
    43         self.assert_(m, 'No "description" meta tag when expose DC meta tags is On') 
     49        self.html = str(self.publish(self.portal.id + '/my_doc', 
     50                                     self.basic_auth)) 
     51        m = re.match(METATAG % "description", self.html, re.S | re.M) 
     52        self.assert_(m, 'No "description" meta tag when expose DC meta tags ' \ 
     53                     'is On') 
    4454 
    4555    def test_dateValidRange(self): 
    46         self.sp.manage_changeProperties(exposeDCMetaTags = True) 
    47         EFFDSTR, EXPDSTR =  "2009/12/23", "2010/03/10" 
     56        self.sp.manage_changeProperties(exposeDCMetaTags=True) 
     57        EFFDSTR, EXPDSTR = "2009/12/23", "2010/03/10" 
    4858        self.my_doc.setExpirationDate(EXPDSTR) 
    4959        self.my_doc.setEffectiveDate(EFFDSTR) 
    50         self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
    51         m = re.match(METATAG % "DC.date.valid_range", self.html, re.S|re.M) 
     60        self.html = str(self.publish(self.portal.id + '/my_doc', 
     61                                     self.basic_auth)) 
     62        m = re.match(METATAG % "DC.date.valid_range", self.html, re.S | re.M) 
    5263        content = m and m.group("tagcontent") 
    5364        fact = content and map(DateTime, content.split("-")) 
    5465        expect = map(DateTime, [EFFDSTR, EXPDSTR]) 
    55         self.assert_( fact == expect, '"DC.date.valid_range" meta tags content="%s", ' \ 
    56                       'but "%s" must be' % ( fact, expect )) 
     66        self.assert_(fact == expect, '"DC.date.valid_range" meta tags ' \ 
     67                     'content="%s", but "%s" must be' % (fact, expect)) 
     68 
    5769 
    5870def test_suite(): 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testInstallation.py

    r2244 r3134  
    2424DEFAULT_METATAGS_ORDER = [ 
    2525    'DC.contributors', 'DC.creator', 'DC.date.created', 
    26     'DC.date.modified','DC.description', 'DC.distribution', 
     26    'DC.date.modified', 'DC.description', 'DC.distribution', 
    2727    'DC.format', 'DC.language', 'DC.publisher', 'DC.rights', 
    2828    'DC.subject', 'DC.type', 'description', 'distribution', 
     
    3131 
    3232SEO_CONTENT = ['File', 'Document', 'News Item'] 
    33 CONTENTTYPES_WITH_SEOACTION = ['File', 'Document', 'News Item', 'Folder', 'Event'] 
     33CONTENTTYPES_WITH_SEOACTION = ['File', 'Document', 'News Item', 'Folder', 
     34                               'Event'] 
    3435CONTENTTYPES_WITH_SEOACTION.sort() 
    3536 
     
    6061 
    6162    def testAddingPropertyFields(self): 
    62         """ Test adding property field to portal_properties.maps_properties sheet """ 
     63        """ Test adding property field to portal_properties.maps_properties 
     64            sheet 
     65        """ 
    6366        map_sheet = self.properties[PROPERTY_SHEET] 
    6467        for key, value in PROPS.items(): 
    65             self.failUnless(map_sheet.hasProperty(key) and list(map_sheet.getProperty(key)) == value) 
     68            self.failUnless(map_sheet.hasProperty(key) and \ 
     69                            list(map_sheet.getProperty(key)) == value) 
    6670 
    6771    def test_configlet_install(self): 
    6872        configTool = getToolByName(self.portal, 'portal_controlpanel', None) 
    69         self.assert_(PROJECT_NAME in [a.getId() for a in configTool.listActions()], 'Configlet not found') 
     73        self.assert_(PROJECT_NAME in [a.getId() for a in \ 
     74                                      configTool.listActions()], \ 
     75                     'Configlet not found') 
    7076 
    7177    def test_viewlets_install(self): 
     
    7884        alsoProvides(request, IPloneSEOLayer) 
    7985        view = queryMultiAdapter((self.portal, request), name="plone") 
    80         manager = queryMultiAdapter( (self.portal['front-page'], request, view), 
     86        manager = queryMultiAdapter((self.portal['front-page'], request, view), 
    8187                                     IViewletManager, name='plone.htmlhead') 
    8288        for p in VIEWLETS: 
    83             self.assert_(manager.get(p) is not None, "Not registered '%s' viewlet" % p) 
     89            self.assert_(manager.get(p) is not None, "Not registered '%s' " \ 
     90                         "viewlet" % p) 
    8491 
    8592    def test_browser_layer(self): 
     
    9299 
    93100    def test_action_install(self): 
    94         atool=getToolByName(self.portal, 'portal_actions') 
     101        atool = getToolByName(self.portal, 'portal_actions') 
    95102        action_ids = [a.id for a in atool.listActions()] 
    96103        self.assert_("SEOProperties" in action_ids, 
    97104                     "Not added 'SEOProperties' action") 
    98105 
     106 
    99107class TestUninstallation(TestCase): 
    100108 
     
    106114        properties = getToolByName(self.portal, 'portal_properties') 
    107115        self.assert_(hasattr(properties.aq_base, PROPERTY_SHEET), 
    108             "'%s' property sheet not uninstalled" % PROPERTY_SHEET) 
     116                     "'%s' property sheet not uninstalled" % PROPERTY_SHEET) 
    109117 
    110118    def test_configlet_uninstall(self): 
     
    113121 
    114122        configTool = getToolByName(self.portal, 'portal_controlpanel', None) 
    115         self.assertEqual(PROJECT_NAME in [a.getId() for a in configTool.listActions()], False, 
    116             'Configlet found after uninstallation') 
     123        self.assertEqual(PROJECT_NAME in [a.getId() for a in \ 
     124                                          configTool.listActions()], False, 
     125                         'Configlet found after uninstallation') 
    117126 
    118127    def test_viewlets_uninstall(self): 
     
    121130        request = self.app.REQUEST 
    122131        view = queryMultiAdapter((self.portal, request), name="plone") 
    123         manager = queryMultiAdapter( (self.portal['front-page'], request, view), 
    124                                      IViewletManager, name='plone.htmlhead') 
     132        manager = queryMultiAdapter((self.portal['front-page'], request, view), 
     133                                    IViewletManager, name='plone.htmlhead') 
    125134        for p in VIEWLETS: 
    126135            self.assertEqual(manager.get(p) is None, True, 
     
    136145 
    137146    def test_action_uninstall(self): 
    138         atool=getToolByName(self.portal, 'portal_actions') 
     147        atool = getToolByName(self.portal, 'portal_actions') 
    139148        action_ids = [a.id for a in atool.listActions()] 
    140149        self.assertEqual("SEOProperties" in action_ids, False, 
    141             "'SEOProperties' action not removed from portal_actions " \ 
    142             "on uninstallation") 
     150                         "'SEOProperties' action not removed from " \ 
     151                         "portal_actions on uninstallation") 
     152 
    143153 
    144154class TestReinstallation(TestCase): 
     
    149159        self.setup_tool = getToolByName(self.portal, 'portal_setup') 
    150160        self.pprops_tool = getToolByName(self.portal, 'portal_properties') 
    151         self.seoprops_tool = getToolByName(self.pprops_tool, 'seo_properties', None) 
    152         # Set earlier version profile (2.0.0) for using upgrade steps  
    153         self.setup_tool.setLastVersionForProfile('%s:default' % PROJECT_NAME, '2.0.0') 
     161        self.seoprops_tool = getToolByName(self.pprops_tool, 'seo_properties', 
     162                                           None) 
     163        # Set earlier version profile (2.0.0) for using upgrade steps 
     164        self.setup_tool.setLastVersionForProfile('%s:default' % PROJECT_NAME, 
     165                                                 '2.0.0') 
    154166 
    155167    def testChangeDomain(self): 
    156         # Test changed of content type's domain from 'quintagroup.seoptimizer' to 'plone' 
     168        # Test changed of content type's domain from 'quintagroup.seoptimizer' 
     169        # to 'plone' 
    157170        for type in SEO_CONTENT: 
    158             self.types_tool.getTypeInfo(type).i18n_domain = 'quintagroup.seoptimizer' 
     171            i18n_domain = 'quintagroup.seoptimizer' 
     172            self.types_tool.getTypeInfo(type).i18n_domain = i18n_domain 
    159173        self.qi.reinstallProducts([PROJECT_NAME]) 
    160174        for type in SEO_CONTENT: 
    161             self.assertEqual(self.types_tool.getTypeInfo(type).i18n_domain, 'plone', 
    162                 "Not changed of %s content type's domain to 'plone'" % type) 
     175            self.assertEqual(self.types_tool.getTypeInfo(type).i18n_domain, 
     176                             'plone', "Not changed of %s content type's " \ 
     177                             "domain to 'plone'" % type) 
    163178 
    164179    def testCutItemsMetatagsOrderList(self): 
    165         # Test changed format metatags order list from "metaname accessor" to "metaname" 
    166         value, expect_mto = ['name1 accessor1', 'name2 accessor2'], ['name1','name2'] 
     180        # Test changed format metatags order list from "metaname accessor" 
     181        # to "metaname" 
     182        value, expect_mto = ['name1 accessor1', 'name2 accessor2'], \ 
     183                            ['name1', 'name2'] 
    167184        self.seoprops_tool.manage_changeProperties(metatags_order=value) 
    168185        self.qi.reinstallProducts([PROJECT_NAME]) 
     
    170187        mto.sort() 
    171188        self.assertEqual(mto, expect_mto, 
    172                     "Not changed format metatags order list from \"metaname accessor\" to"\ 
    173                     " \"metaname\". %s != %s" %(mto, expect_mto)) 
     189                         "Not changed format metatags order list from \"" \ 
     190                         "metaname accessor\" to \"metaname\". %s != %s" \ 
     191                         % (mto, expect_mto)) 
    174192 
    175193    def testAddMetatagsOrderList(self): 
     
    180198        mto.sort() 
    181199        self.assertEqual(mto, DEFAULT_METATAGS_ORDER, 
    182                     "Not added metatags order list with default values."\ 
    183                     "%s != %s" %(mto, DEFAULT_METATAGS_ORDER)) 
     200                         "Not added metatags order list with default values." \ 
     201                         "%s != %s" % (mto, DEFAULT_METATAGS_ORDER)) 
    184202 
    185203    def testMigrationActions(self): 
     
    188206 
    189207        # Add seoaction to content type for testing 
     208 
    190209        for type in CONTENTTYPES_WITH_SEOACTION: 
    191             self.types_tool.getTypeInfo(type).addAction(id='seo_properties', 
    192                                                    name='SEO Properties', 
    193                                                    action=None, 
    194                                                    condition=None, 
    195                                                    permission=(u'Modify portal content',), 
    196                                                    category='object', 
    197                                                   ) 
     210            self.types_tool.getTypeInfo(type).addAction( 
     211                                    id='seo_properties', 
     212                                    name='SEO Properties', 
     213                                    action=None, 
     214                                    condition=None, 
     215                                    permission=(u'Modify portal content',), 
     216                                    category='object', 
     217                                   ) 
    198218            # Check presence seoaction in content type 
    199             seoaction = [act.id for act in self.types_tool.getTypeInfo(type).listActions() 
    200                                           if act.id == 'seo_properties'] 
     219            seoaction = [act.id for act in \ 
     220                         self.types_tool.getTypeInfo(type).listActions() \ 
     221                         if act.id == 'seo_properties'] 
    201222            self.assertEqual(bool(seoaction), True, 
    202                     "Not added seoaction to content type %s for testing" % type) 
     223                             "Not added seoaction to content type %s for " \ 
     224                             "testing" % type) 
    203225 
    204226        self.qi.reinstallProducts([PROJECT_NAME]) 
     
    206228        # Check presence seoaction in content type 
    207229        for type in CONTENTTYPES_WITH_SEOACTION: 
    208             seoaction = [act.id for act in self.types_tool.getTypeInfo(type).listActions() 
    209                                           if act.id == 'seo_properties'] 
     230            seoaction = [act.id for act in \ 
     231                         self.types_tool.getTypeInfo(type).listActions() \ 
     232                         if act.id == 'seo_properties'] 
    210233            self.assertEqual(bool(seoaction), False, 
    211234                "Not removed seoaction in content type %s" % type) 
    212235 
    213         # Check added content type names in seo properties tool if content types have seoaction 
     236        # Check added content type names in seo properties tool 
     237        # if content types have seoaction 
    214238        ctws = list(self.seoprops_tool.content_types_with_seoproperties) 
    215239        ctws.sort() 
    216240        self.assertEqual(ctws, CONTENTTYPES_WITH_SEOACTION, 
    217             "Not added content type names in seo properties tool if content types have seoaction."\ 
    218             " %s != %s" %(ctws, CONTENTTYPES_WITH_SEOACTION)) 
     241                         "Not added content type names in seo properties " \ 
     242                         "tool if content types have seoaction. %s != %s" \ 
     243                         % (ctws, CONTENTTYPES_WITH_SEOACTION)) 
    219244 
    220245    def testRemoveSkin(self): 
     
    223248        skinstool = getToolByName(self.portal, 'portal_skins') 
    224249        for skin in skinstool.getSkinSelections(): 
    225             paths  = ','.join((skinstool.getSkinPath(skin), layer)) 
     250            paths = ','.join((skinstool.getSkinPath(skin), layer)) 
    226251            skinstool.addSkinSelection(skin, paths) 
    227252        self.qi.reinstallProducts([PROJECT_NAME]) 
     
    230255            path = map(string.strip, string.split(path, ',')) 
    231256            self.assertEqual(layer in path, False, 
    232                 '%s layer found in %s after uninstallation' %(layer, skin)) 
     257                             '%s layer found in %s after uninstallation' \ 
     258                             % (layer, skin)) 
    233259 
    234260    def testMigrateCanonical(self): 
     
    239265        doc.manage_addProperty('qSEO_canonical', 'val', 'string') 
    240266        value = doc.getProperty('qSEO_canonical') 
    241         assert doc.getProperty('qSEO_canonical') == 'val'  
     267        assert doc.getProperty('qSEO_canonical') == 'val' 
    242268 
    243269        self.qi.reinstallProducts([PROJECT_NAME]) 
    244270        value = doc.getProperty(PROPERTY_LINK) 
    245271        has_prop = bool(doc.hasProperty('qSEO_canonical')) 
    246         self.assertEqual(has_prop, False, "Property 'qSEO_canonical' is not deleted.") 
    247         self.assertEqual(value == 'val', True, 
    248                 "Property not migrated from 'qSEO_canonical' to '%s'." % PROPERTY_LINK) 
     272        self.assertEqual(has_prop, False, "Property 'qSEO_canonical' is " \ 
     273                         "not deleted.") 
     274        self.assertEqual(value == 'val', True, "Property not migrated from " \ 
     275                         "'qSEO_canonical' to '%s'." % PROPERTY_LINK) 
     276 
    249277 
    250278def test_suite(): 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testMetaTagsDuplication.py

    r2139 r3134  
    22 
    33GENERATOR = re.compile('.*(<meta\s+(?:(?:name="generator"\s*)|' \ 
    4                        '(?:content=".*?"\s*)){2}/>)', re.S|re.M) 
     4                       '(?:content=".*?"\s*)){2}/>)', re.S | re.M) 
    55DESCRIPTION = re.compile('.*(<meta\s+(?:(?:name="description"\s*)|' \ 
    6                          '(?:content=".*?"\s*)){2}/>)', re.S|re.M) 
     6                         '(?:content=".*?"\s*)){2}/>)', re.S | re.M) 
     7 
    78 
    89class InstallMixin: 
     
    2829    def test_GeneratorMetaSEOInstalled(self): 
    2930        lengen = len(GENERATOR.findall(self.html)) 
    30         self.assert_(lengen==1, "There is %d generator meta tag(s) " \ 
     31        self.assert_(lengen == 1, "There is %d generator meta tag(s) " \ 
    3132           "when seoptimizer installed" % lengen) 
    32   
     33 
    3334    def test_DescriptionMetaSEOInstalled(self): 
    3435        lendesc = len(DESCRIPTION.findall(self.html)) 
    35         self.assert_(lendesc==1, "There is %d DESCRIPTION meta tag(s) " \ 
     36        self.assert_(lendesc == 1, "There is %d DESCRIPTION meta tag(s) " \ 
    3637           "when seoptimizer installed" % lendesc) 
    3738 
     
    4546    def test_GeneratorMetaSEOUninstalled(self): 
    4647        lengen = len(GENERATOR.findall(self.html)) 
    47         self.assert_(lengen<=1, "There is %d generator meta tag(s) " \ 
     48        self.assert_(lengen <= 1, "There is %d generator meta tag(s) " \ 
    4849            "when seoptimizer uninstalled" % lengen) 
    4950 
    5051    def test_DescriptionMetaSEOUninstalled(self): 
    5152        lendesc = len(DESCRIPTION.findall(self.html)) 
    52         self.assert_(lendesc==1, "There is %d DESCRIPTION meta tag(s) " \ 
     53        self.assert_(lendesc == 1, "There is %d DESCRIPTION meta tag(s) " \ 
    5354           "when seoptimizer uninstalled" % lendesc) 
    5455 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testUsageKeywords.py

    r2928 r3134  
    88KWSTMPL = '.*(<meta\s+(?:(?:name="keywords"\s*)|(?:content="%s"\s*)){2}/>)' 
    99 
     10 
    1011class TestUsageKeywords(FunctionalTestCase): 
    1112 
     
    1314        self.sp = self.portal.portal_properties.seo_properties 
    1415        self.pu = self.portal.plone_utils 
    15         self.basic_auth = ':'.join((portal_owner,default_password)) 
     16        self.basic_auth = ':'.join((portal_owner, default_password)) 
    1617        self.loginAsPortalOwner() 
    1718        #Preparation for functional testing 
     
    3132        for seokws in [('foo',), ('foo', 'bar')]: 
    3233            self.my_doc._updateProperty('qSEO_keywords', seokws) 
    33             html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
     34            html = str(self.publish(self.portal.id + '/my_doc', 
     35                                    self.basic_auth)) 
    3436            expect = ',\s*'.join(seokws) 
    35             open('/tmp/testrender_SEOKeywords','w').write(html) 
    36             self.assert_(re.match(KWSTMPL % expect, html, re.S|re.M), 
     37            open('/tmp/testrender_SEOKeywords', 'w').write(html) 
     38            self.assert_(re.match(KWSTMPL % expect, html, re.S | re.M), 
    3739                         "No '%s' keyword found" % str(seokws)) 
    3840 
     
    4042        self.my_doc.setText('<p>local subject</p>') 
    4143        self.my_doc.setSubject('subject') 
    42         html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
     44        html = str(self.publish(self.portal.id + '/my_doc', self.basic_auth)) 
    4345 
    4446        expect = "subject" 
    45         self.assert_(re.match(KWSTMPL % expect, html, re.S|re.M), 
     47        self.assert_(re.match(KWSTMPL % expect, html, re.S | re.M), 
    4648                     "No '%s' keyword find" % expect) 
    4749 
     
    5153        self.my_doc.setSubject('subject') 
    5254        self.my_doc.manage_addProperty('qSEO_keywords', SEOKWS, 'lines') 
    53         html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
     55        html = str(self.publish(self.portal.id + '/my_doc', self.basic_auth)) 
    5456 
    5557        expect = ',\s*'.join(SEOKWS) 
    56         self.assert_(re.match(KWSTMPL % expect, html, re.S|re.M), 
     58        self.assert_(re.match(KWSTMPL % expect, html, re.S | re.M), 
    5759                     "No '%s' keywords find" % SEOKWS) 
    5860 
    5961    def testbehave_noSEOKeywordsNoSubject(self): 
    6062        """Nor seo keywords not subject added""" 
    61         html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
     63        html = str(self.publish(self.portal.id + '/my_doc', self.basic_auth)) 
    6264        self.assertFalse(re.match('.*(<meta\s[^\>]*name="keywords"[^\>]*>)', 
    63                                   html, re.S|re.M), "'keyword' meta tag found") 
     65                                  html, re.S | re.M), 
     66                         "'keyword' meta tag found") 
    6467 
    6568 
     
    8184        self.chckView = queryMultiAdapter((self.my_doc, self.app.REQUEST), 
    8285            name="checkSEOKeywords") 
    83          
     86 
    8487    def patchURLLib(self, fnc): 
    8588        self.orig_urlopen = urllib2.urlopen 
    8689        self.urlfd = StringIO() 
    8790        urllib2.urlopen = fnc 
    88      
     91 
    8992    def unpatchURLLib(self): 
    9093        urllib2.urlopen = self.orig_urlopen 
     
    99102        def patch_urlopen(*args, **kwargs): 
    100103            if args[0] == self.my_doc.absolute_url(): 
    101                 self.urlfd.write(unicode(self.my_doc() + self.key).encode("utf-8")) 
     104                self.urlfd.write(unicode(self.my_doc() + 
     105                                 self.key).encode("utf-8")) 
    102106                self.urlfd.seek(0) 
    103107                return self.urlfd 
     
    110114        self.assertTrue('3' in self.chckView()) 
    111115        # 2. Opened urllib file descriptor must be closed 
    112         self.assertTrue(self.urlfd.closed, "Opened file descriptor was not closed.") 
     116        self.assertTrue(self.urlfd.closed, 
     117                        "Opened file descriptor was not closed.") 
    113118        self.unpatchURLLib() 
    114          
     119 
    115120    def test_ExternalURLError(self): 
    116121        def patch_urlopen(*args, **kwargs): 
     
    131136        # 2. Opened urllib file descriptor should not be closed because 
    132137        #    it even not returned to the view 
    133         self.assertFalse(self.urlfd.closed, "Opened file descriptor was closed.") 
     138        self.assertFalse(self.urlfd.closed, 
     139                         "Opened file descriptor was closed.") 
    134140        self.unpatchURLLib() 
    135      
     141 
    136142    def test_ExternalIOError(self): 
    137143        def patch_urlopen(*args, **kwargs): 
    138144            if args[0] == self.my_doc.absolute_url(): 
    139                 self.urlfd.write(unicode(self.my_doc() + self.key).encode("utf-8")) 
     145                self.urlfd.write(unicode(self.my_doc() + 
     146                                 self.key).encode("utf-8")) 
    140147                self.urlfd.seek(0) 
    141148                return self.urlfd 
    142149            else: 
    143150                return self.orig_urlopen(*args, **kwargs) 
     151 
    144152        def patch_read(*args, **kwargs): 
    145153            raise Exception("General exception") 
    146154        # Patch urllib2.urlopen to emulate external url retrieval 
    147155        self.patchURLLib(fnc=patch_urlopen) 
    148         # Patch opened by urllib2 file descriptor to emulate IOError during reading 
     156        # Patch opened by urllib2 file descriptor to emulate 
     157        # IOError during reading 
    149158        self.urlfd.read = patch_read 
    150159        self.seo._updateProperty("external_keywords_test", True) 
     
    153162        self.assertRaises(Exception, self.chckView) 
    154163        # 2. Opened urllib file descriptor must be closed 
    155         self.assertTrue(self.urlfd.closed, "Opened file descriptor was not closed.") 
     164        self.assertTrue(self.urlfd.closed, 
     165                        "Opened file descriptor was not closed.") 
    156166        self.unpatchURLLib() 
    157          
     167 
    158168 
    159169def test_suite(): 
     
    163173    suite.addTest(makeSuite(TestCalcKeywords)) 
    164174    return suite 
    165  
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/test_doctest.py

    r3011 r3134  
    33 
    44from base import * 
     5 
    56 
    67def test_suite(): 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/upgrades.py

    r2238 r3134  
    77logger = logging.getLogger('quintagroup.seoptimizer') 
    88FIX_PTYPES_DOMAIN = ['Document', 'File', 'News Item'] 
    9 REMOVE_SEOPROPERTIES = ['additional_keywords', 'settings_use_keywords_sg', 
    10                         'settings_use_keywords_lg', 'filter_keywords_by_content', 
     9REMOVE_SEOPROPERTIES = ['additional_keywords', 
     10                        'settings_use_keywords_sg', 
     11                        'settings_use_keywords_lg', 
     12                        'filter_keywords_by_content', 
    1113                       ] 
     14 
    1215 
    1316def changeDomain(plone_tools): 
     
    2326                       "changed to \'plone\'." % ptype.id) 
    2427 
     28 
    2529def changeMetatagsOrderList(plone_tools): 
    26     """ Change format metatags order list from "metaname accessor" to "metaname". 
     30    """ Change format metatags order list 
     31        from "metaname accessor" to "metaname". 
    2732    """ 
    2833    types_tool = plone_tools.types() 
     
    3742            seoprops_tool.manage_changeProperties(metatags_order=mto_new) 
    3843    else: 
    39         setup_tool.runImportStepFromProfile('profile-quintagroup.seoptimizer:default', 
    40                                             'propertiestool') 
     44        name_profile = 'profile-quintagroup.seoptimizer:default' 
     45        setup_tool.runImportStepFromProfile(name_profile, 'propertiestool') 
    4146 
    4247 
     
    4752    types_tool = plone_tools.types() 
    4853    seoprops_tool = plone_tools.properties().seo_properties 
    49     ctws = list(seoprops_tool.getProperty('content_types_with_seoproperties', [])) 
     54    property_name = 'content_types_with_seoproperties' 
     55    ctws = list(seoprops_tool.getProperty(property_name, [])) 
    5056    flag = False 
    5157    for ptype in types_tool.objectValues(): 
     
    6066                       "type in portal actions." % ptype.id) 
    6167    if flag: 
    62         seoprops_tool.manage_changeProperties(content_types_with_seoproperties=ctws) 
     68        seo_change_properties = seoprops_tool.manage_changeProperties 
     69        seo_change_properties(content_types_with_seoproperties=ctws) 
     70 
    6371 
    6472def removeNonUseSeoProperties(plone_tools): 
     
    6876    remove_properties = [] 
    6977    for pr in REMOVE_SEOPROPERTIES: 
    70       if seoprops_tool.hasProperty(pr): 
    71           remove_properties.append(pr) 
    72           logger.log(logging.INFO, "Removed %s property in seoproperties tool." % pr) 
     78        if seoprops_tool.hasProperty(pr): 
     79            remove_properties.append(pr) 
     80            logger.log(logging.INFO, "Removed %s property in " 
     81                       "seoproperties tool." % pr) 
    7382    if not remove_properties: 
    7483        seoprops_tool.manage_delProperties(remove_properties) 
     84 
    7585 
    7686def removeSkin(plone_tools): 
     
    8090    skins_tool = plone_tools.url().getPortalObject().portal_skins 
    8191    for skinName in skins_tool.getSkinSelections(): 
    82         skin_paths = skins_tool.getSkinPath(skinName).split(',')  
    83         paths = [l.strip() for l in skin_paths if not (l == layer or l.startswith(layer+'/'))] 
     92        skin_paths = skins_tool.getSkinPath(skinName).split(',') 
     93        paths = [l.strip() for l in skin_paths \ 
     94                           if not (l == layer or l.startswith(layer + '/'))] 
    8495        logger.log(logging.INFO, "Removed layers from %s skin." % skinName) 
    8596        skins_tool.addSkinSelection(skinName, ','.join(paths)) 
     97 
    8698 
    8799def migrateCanonical(plone_tools): 
     
    92104    portal = plone_tools.url().getPortalObject() 
    93105    allCTTypes = types.listContentTypes() 
    94     obj_metatypes =  [m.content_meta_type for m in types.objectValues() \ 
    95                       if m.getId() in allCTTypes] 
     106    obj_metatypes = [m.content_meta_type for m in types.objectValues() \ 
     107                     if m.getId() in allCTTypes] 
    96108    portal.ZopeFindAndApply( 
    97109                            portal, 
     
    99111                            apply_func=renameProperty 
    100112                            ) 
     113 
    101114 
    102115def renameProperty(obj, path): 
     
    115128                         "property for %%(url)s object" % str(e) 
    116129 
    117         logger.log(level, msg % {'url':obj.absolute_url(), 'name':PROPERTY_LINK} ) 
     130        logger.log(level, msg % {'url': obj.absolute_url(), 
     131                                 'name': PROPERTY_LINK}) 
    118132        obj.manage_delProperties(['qSEO_canonical']) 
     133 
    119134 
    120135def upgrade_2_to_3(setuptool): 
    121136    """ Upgrade quintagroup.seoptimizer from version 2.x.x to 3.0.0. 
    122137    """ 
    123     plone_tools = queryMultiAdapter((setuptool, setuptool.REQUEST), name="plone_tools") 
    124     setuptool.runAllImportStepsFromProfile('profile-quintagroup.seoptimizer:upgrade_2_to_3') 
     138    plone_tools = queryMultiAdapter((setuptool, setuptool.REQUEST), 
     139                                    name="plone_tools") 
     140    profile_name = 'profile-quintagroup.seoptimizer:upgrade_2_to_3' 
     141    setuptool.runAllImportStepsFromProfile(profile_name) 
    125142    migrationActions(plone_tools) 
    126143    changeDomain(plone_tools) 
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/util.py

    r2139 r3134  
    1313 
    1414    security.declarePublic('items') 
     15 
    1516    def items(self): 
    1617        primary_metatags = self.pmt 
    17         lst = [(name,self[name]) for name in primary_metatags                    \ 
    18                                                  if name in self.keys()] +      \ 
    19               [(name, self[name]) for name in self.keys()                        \ 
    20                                                  if name not in primary_metatags] 
     18        lst = [(name, self[name]) for name in primary_metatags \ 
     19                                  if name in self.keys()] + \ 
     20              [(name, self[name]) for name in self.keys() \ 
     21                                  if name not in primary_metatags] 
    2122        return lst 
    2223 
     24    security.declarePublic('__init__') 
    2325 
    24     security.declarePublic('__init__') 
    2526    def __init__(self, *args, **kwargs): 
    26         super(SortedDict,self).__init__(*args, **kwargs) 
     27        super(SortedDict, self).__init__(*args, **kwargs) 
    2728        self.pmt = [] 
     29    security.declarePublic('__setitem__') 
    2830 
    29  
    30     security.declarePublic('__setitem__') 
    3131    def __setitem__(self, i, y): 
    32         super(SortedDict,self).__setitem__(i, y) 
     32        super(SortedDict, self).__setitem__(i, y) 
    3333        if i not in self.pmt: 
    3434            self.pmt.append(i) 
     35    security.declarePublic('pop') 
    3536 
    36     security.declarePublic('pop') 
    3737    def pop(self, k, *args, **kwargs): 
    38         super(SortedDict,self).pop(k, *args, **kwargs) 
     38        super(SortedDict, self).pop(k, *args, **kwargs) 
    3939        if k in self.pmt: 
    4040            self.pmt.remove(k) 
  • quintagroup.seoptimizer/trunk/setup.py

    r3013 r3134  
    1212      description="Quintagroup Search Engine Optimization Tool", 
    1313      long_description=open("README.txt").read() + "\n" + 
    14                        open(os.path.join("docs", "INSTALL.txt")).read() + "\n" + 
    15                        open(os.path.join("docs", "HISTORY.txt")).read(), 
     14          open(os.path.join("docs", "INSTALL.txt")).read() + "\n" + 
     15          open(os.path.join("docs", "HISTORY.txt")).read(), 
    1616 
    17       # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers 
     17      # Get more strings from 
     18      # http://www.python.org/pypi?%3Aaction=list_classifiers 
    1819      classifiers=[ 
    1920        "Framework :: Plone", 
     
    2425        ], 
    2526      keywords='', 
    26       author='Myroslav Opyr, Volodymyr Romaniuk, Mykola Kharechko, Vitaliy Podoba, Volodymyr Cherepanyak, Taras Melnychuk, Vitaliy Stepanov, Andriy Mylenkyy', 
     27      author='Myroslav Opyr, Volodymyr Romaniuk, Mykola Kharechko, ' \ 
     28             'Vitaliy Podoba, Volodymyr Cherepanyak, Taras Melnychuk, '\ 
     29             'Vitaliy Stepanov, Andriy Mylenkyy', 
    2730      author_email='support@quintagroup.com', 
    28       url='http://quintagroup.com/services/plone-development/products/qSEOptimizer/', 
     31      url='http://quintagroup.com/services/'\ 
     32          'plone-development/products/qSEOptimizer/', 
    2933      license='GPL', 
    3034      packages=find_packages(exclude=['ez_setup']), 
Note: See TracChangeset for help on using the changeset viewer.