Changeset 1237

Show
Ignore:
Timestamp:
09/11/08 04:05:17
Author:
liebster
Message:

General code cleanup and modernization.Converted into a complete GenericSetup? profile.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • qPingTool/branches/plone-3.1/History.txt

    r829 r1237  
     11.0.0 - Unreleased 
     2 
     3  * Converted `Extension/Install.py` into a complete GenericSetup profile. 
     4  * Updated tests to run with Plone 3.x. 
     5  * General code cleanup and modernization. 
     6 
    170.3 
    28 
  • qPingTool/branches/plone-3.1/PingInfo.py

    r697 r1237  
     1from Globals import DTMLFile 
     2from AccessControl import ClassSecurityInfo 
    13from Products.Archetypes.public import * 
    2 from Products.Archetypes.BaseContent import BaseContentMixin 
    3 from Products.CMFCore.ActionInformation import ActionInformation 
    4 from Products.CMFCore.Expression import Expression, createExprContext 
    5 from Products.CMFCore.utils import getToolByName 
    6 from Acquisition import aq_inner, aq_parent 
     4from Products.CMFCore.permissions import ModifyPortalContent 
    75from Products.CMFDefault.utils import _dtmldir 
    8 from config import * 
    9 from AccessControl import ClassSecurityInfo 
    10 from Globals import InitializeClass, DTMLFile 
     6from Products.ATContentTypes.content.base import ATCTContent 
     7from Products.ATContentTypes.content.schemata import ATContentTypeSchema, finalizeATCTSchema 
     8from Products.ATContentTypes.lib.historyaware import HistoryAwareMixin 
     9from config import RSS_LIST, PROJECTNAME 
    1110 
    12 schema = BaseContentMixin.schema +  Schema(( 
    13     #StringField('id', 
    14     #            required=1, 
    15     #            widget=StringWidget(size=70, 
    16     #                                label_msgid = 'label_id', 
    17     #                                description_msgid = 'help_id'), 
    18     #            ), 
     11PingInfoSchema =  ATContentTypeSchema.copy() +  Schema(( 
     12    TextField('description', 
     13        default = '', 
     14        searchable = 0, 
     15        widget = TextAreaWidget( 
     16            label_msgid = 'label_description', 
     17            description_msgid = 'help_description',), 
     18               ), 
    1919    StringField('url', 
    2020                required=1, 
     
    3030    StringField('rss_version', 
    3131                vocabulary=RSS_LIST, 
    32                 default='Blog', 
     32                default='Weblog', 
    3333                widget=SelectionWidget(label_msgid = 'label_rss_version', 
    3434                                    description_msgid = 'help_rss_version'), 
    35                 ), 
    36     )) 
     35    )), 
     36    marshall=RFC822Marshaller() 
     37    ) 
     38     
     39finalizeATCTSchema(PingInfoSchema) 
    3740 
    38  
    39 class PingInfo(BaseContentMixin): 
     41class PingInfo(ATCTContent, HistoryAwareMixin): 
    4042    """Ping Info container 
    4143       id - name of the server to ping 
     
    4446       rss_version - rss version supported by the server 
    4547    """ 
    46  
    47     schema = schema 
     48    __implements__ = (ATCTContent.__implements__, 
     49                      HistoryAwareMixin.__implements__, 
     50                     ) 
     51    schema = PingInfoSchema 
    4852 
    4953    """ 
     
    5559        return self.contributors 
    5660 
    57     try: 
    58         from Products.CMFCore import permissions 
    59         security.declareProtected(permissions.ModifyPortalContent, 'manage_metadata' ) 
    60     except: 
    61         from Products.CMFCore.CMFCorePermissions import ModifyPortalContent 
    62         security.declareProtected(ModifyPortalContent, 'manage_metadata' ) 
    63  
     61    security.declareProtected(ModifyPortalContent, 'manage_metadata' ) 
    6462    manage_metadata = DTMLFile('zmi_metadata', _dtmldir) 
    6563 
    6664 
    67 registerType(PingInfo
     65registerType(PingInfo, PROJECTNAME
  • qPingTool/branches/plone-3.1/PingTool.py

    r697 r1237  
    1 #from Globals import InitializeClass 
    21import os 
     2from Acquisition import aq_base 
     3from zLOG import LOG 
     4from zope.interface import implements 
     5from AccessControl import ClassSecurityInfo 
     6from Products.PageTemplates.PageTemplateFile import PageTemplateFile 
     7from Products.Archetypes.public import * 
    38from Products.CMFCore.ActionProviderBase import ActionProviderBase 
     9from Products.CMFCore.permissions import ManagePortal 
     10from Products.CMFCore.utils import getToolByName 
     11from Products.ATContentTypes.content.folder import ATFolder 
     12from Products.CMFPlone.interfaces.OrderedContainer import IOrderedContainer 
    413from Products.CMFPlone.PloneFolder import PloneFolder 
    5 from config import TOOL_ID, PROJECTNAME 
    6 from Products.Archetypes.public import * 
    7 from Products.ATContentTypes.content.folder import ATFolder 
    8 from Products.ATContentTypes.content.base import updateActions, updateAliases 
    9 from Products.CMFPlone.interfaces.OrderedContainer import IOrderedContainer 
    10 from Products.CMFCore.ActionInformation import ActionInformation 
    11 from Products.CMFCore.Expression import Expression 
    12 from Products.CMFCore.CMFCorePermissions import ManageProperties 
    13 from Acquisition import aq_base 
    14 from Products.CMFCore.utils import _getViewFor 
    15 from Products.PageTemplates.PageTemplateFile import PageTemplateFile 
    1614from Products.XMLRPCMethod.XMLRPCMethod import RPCThread, XMLRPCMethod 
    17 from Products.CMFCore.utils import getToolByName 
    18 from util import getCanonicalURL 
    19 from zLOG import LOG 
     15 
     16from interfaces import IPingTool 
     17from adapter import ICanonicalURL 
     18from config import PROJECTNAME 
    2019 
    2120_marker = [] 
     
    3029 
    3130 
    32 class PingTool(ATFolder, PloneFolder, ActionProviderBase): #(BaseFolder, PloneFolder, ActionProviderBase): 
    33     """This tool serve for operation with ActionInfo objects 
     31class PingTool(ATFolder, PloneFolder): 
    3432    """ 
    3533 
    36     #schema = BaseSchema 
    37     filter_content_types = 1 
    38     allowed_content_types = ('PingInfo',) 
    39     global_allowed = 0 
     34    >>> IPingTool.implementedBy(PingTool) 
     35    True 
     36    """ 
     37    security = ClassSecurityInfo() 
    4038 
    41     meta_type = archetype_name = portal_type = 'PingTool' 
     39    implements(IPingTool) 
     40    __implements__ = (IOrderedContainer,) 
    4241 
    43     ######## 
    44     content_icon   = 'tool.gif' 
    45     immediate_view = 'view' 
    46     default_view   = 'view' 
    47  
    48     ######## 
    49     __implements__ = (IOrderedContainer,) 
    50     _actions = ( ActionInformation( 
    51                     id='ping' 
    52                   , title='Ping setup' 
    53                   , action=Expression( 
    54                         text='string:${folder_url}/ping_setup') 
    55                   , condition=Expression( 
    56                         text='python: folder is object and portal.portal_syndication.isSyndicationAllowed(object)') 
    57                   , permissions=(ManageProperties,) 
    58                   , category='folder' 
    59                   , visible=1 
    60                   ), 
    61                ) 
    62  
    63     actions = updateActions(ATFolder, 
    64         ({'id'         : 'view' \ 
    65          ,'name'       : 'View' \ 
    66          ,'action'     : 'string:folder_contents' \ 
    67          ,'permissions': ('Manage portal',) \ 
    68          ,'category'   :'object' \ 
    69          }, 
    70         ) 
    71     ) 
    72      
    73     aliases = updateAliases(ATFolder, 
    74         {'(Default)'   : 'folder_listing' \ 
    75         ,'view'        : 'folder_contents' \ 
    76         }, 
    77     ) 
    78  
     42    archetype_name = portal_type = 'PingTool' 
    7943    manage_options =  ( 
    8044            {'label' : 'Overview', 'action' : 'manage_overview'}, 
     
    8549    manage_overview._need__name__ = 0 
    8650 
     51    def om_icons(self): 
     52        """ Checking on ZMI for canonical_url setting.""" 
     53        icons = ({'path':'misc_/qPingTool/tool.gif' \ 
     54                    ,'alt':self.meta_type \ 
     55                    ,'title':self.meta_type \ 
     56                },) 
     57        if not ICanonicalURL(self).getCanonicalURL(): 
     58            icons = icons + ({'path':'misc_/PageTemplates/exclamation.gif' \ 
     59                                ,'alt':'Error' \ 
     60                                ,'title':'PingTool needs setting canonical_url' \ 
     61                                },) 
     62        return icons 
     63 
     64    security.declareProtected(ManagePortal, 'pingFeedReader') 
    8765    def pingFeedReader(self,context): 
    8866        """ ping """ 
    89         status = 'success' 
    90         message = 'The servers are pinged' 
    91         if context.meta_type == 'BlogFolder': 
    92             blog = context.simpleblog_tool.getFrontPage(context) 
    93         else: 
    94             blog = context 
    95  
    96         title = blog.Title() 
    97         portal = context.portal_url.getPortalObject() 
    98         canonical_url = getCanonicalURL(context) 
     67         
     68        status = 'failed' 
     69        blog = context 
     70        pingProp = self.getPingProperties(blog) 
     71        if not pingProp['enable_ping']: 
     72            message = 'Ping is dissabled.' 
     73            return status, message 
     74        canonical_url = ICanonicalURL(self).getCanonicalURL() 
    9975        if canonical_url: 
    10076            url = context.portal_url.getRelativeContentURL(blog) 
    10177            url = canonical_url + url 
    10278        else: 
    103             return status, 'Ping is impossible.See portal_pingtool.' 
     79            return status, 'Ping is impossible.Setup canonical_url.' 
    10480 
    10581        ps = getToolByName(context,'portal_syndication') 
    106         rss_templates = {'Blog':'','RSS1':'/RSS','RSS2':'/RSS2'} 
    107         pingProp = self.getPingProperties(blog) 
    108         result = 'ok' 
    109         if not pingProp['enable_ping']: 
    110            message = 'Ping is dissabled' 
    111            return status, message 
     82        rss_templates = {'Weblog':'','RSS1':'/RSS','RSS2':'/RSS2'} 
    11283        if ps.isSyndicationAllowed(blog): 
     84            status = 'success' 
     85            message = 'The servers are pinged.' 
    11386            sites = pingProp['ping_sites'] 
    11487            if sites: 
     
    12194                    PingMethod = XMLRPCMethod('myid',"",site_url,site_method,25) 
    12295                    blog_url = url + site_rss_version 
     96                    title = blog.Title() 
    12397                    try:  
    12498                        #LOG('qPing', 0, title, blog_url, site_url) 
    125                         result = PingMethod(title,blog_url) 
     99                        result_ping = PingMethod(title,blog_url) 
     100                        result = result_ping['message'] 
    126101                    except: 
    127                         LOG('qPingTool', 100,"The site "+  site_url+" generated error for "+ blog_url, result) 
    128                     message += '\n'+ str(result) 
     102                        result = 'The site %s generated error for %s.' % (site_url, blog_url) 
     103                        LOG('qPingTool', 100, result) 
     104                    message += '\nReturned message from %s: %s' % (site_url, str(result)) 
     105        else: 
     106            message = 'The %s is not syndication allowed' % url  
    129107        return status, message 
    130108 
    131  
     109    security.declareProtected(ManagePortal, 'setupPing') 
    132110    def setupPing(self,context, 
    133111                  enable_ping=0, 
     
    137115        obj=aq_base(context) 
    138116        status = 'success' 
    139         message = 'Your changes have been saved' 
     117        message = "Changes saved." 
    140118        syInfo = getattr(obj, 'syndication_information', None) 
    141119 
     
    149127        return status, message 
    150128 
     129    security.declareProtected(ManagePortal, 'getPingProperties') 
    151130    def getPingProperties(self, context): 
    152131        """ """ 
     
    159138        return  pingPropeties 
    160139 
    161     def om_icons(self): 
    162         """ Checking on ZMI for canonical_url setting.""" 
    163         icons = ({'path':'misc_/qPingTool/tool.gif' \ 
    164                     ,'alt':self.meta_type \ 
    165                     ,'title':self.meta_type \ 
    166                 },) 
    167         if not getCanonicalURL(self): 
    168             icons = icons + ({'path':'misc_/PageTemplates/exclamation.gif' \ 
    169                                 ,'alt':'Error' \ 
    170                                 ,'title':'PingTool needs setting canonical_url' \ 
    171                                 },) 
    172         return icons 
    173  
    174 registerType(PingTool) 
     140registerType(PingTool, PROJECTNAME) 
  • qPingTool/branches/plone-3.1/__init__.py

    r697 r1237  
    1 from Globals import package_home 
    21from Products.Archetypes.public import process_types, listTypes 
    32from Products.CMFCore import utils 
    4 from Products.CMFCore.DirectoryView import registerDirectory 
    5 import os, os.path 
    63import PingInfo, PingTool 
    74from config import * 
    85 
    9 try: 
    10     from adapter import registerAdapter 
    11     registerAdapter() 
    12 except: 
    13     from Products.CMFCore.utils import getToolByName 
    14     from Products.CMFPlone.URLTool import URLTool 
    15     def getCanonicalURL(self): 
    16         portal = getToolByName(self, 'portal_url').getPortalObject() 
    17         return portal.getProperty('canonical_url', None) 
    18     #URLTool.security.declarePublic('getCanonicalURL') 
    19     URLTool.getCanonicalURL = getCanonicalURL 
    20  
    21  
    22 registerDirectory(SKINS_DIR, GLOBALS) 
    236tools = ( PingTool.PingTool, ) 
    247 
     
    2710    allow_module('Products.qPingTool.util') 
    2811 
    29     utils.ToolInit("PingTool", tools=tools, product_name=PROJECTNAME, icon=TOOL_ICON, 
     12    utils.ToolInit("PingTool", tools=tools, icon=TOOL_ICON, 
    3013                  ).initialize(context) 
    3114 
  • qPingTool/branches/plone-3.1/adapter.py

    r697 r1237  
    1 from zope.interface import Interface, implements #, Attribute 
     1from zope.component import adapts 
     2from zope.interface import Interface, implements 
     3 
     4from interfaces import IPingTool 
    25from Products.CMFCore.utils import getToolByName 
    36 
     
    2023class CanonicalURL(object): 
    2124    """ CanonicalURL adapter 
     25 
     26    >>> ICanonicalURL.implementedBy(CanonicalURL) 
     27    True 
     28    >>> ICanonicalURL(CanonicalURL(object)) is not None 
     29    True 
    2230    """ 
     31 
     32    adapts(IPingTool) 
    2333    implements(ICanonicalURL) 
    2434 
     
    5565        #portal = getToolByName(self, 'portal_url').getPortalObject() 
    5666        #return portal.hasProperty('canonical_url') 
    57  
    58 # Register adapter 
    59  
    60 def registerAdapter(): 
    61     from Products.CMFPlone.interfaces import IPloneBaseTool 
    62     from zope.component import provideAdapter 
    63     provideAdapter(CanonicalURL, adapts=[IPloneBaseTool,], provides=ICanonicalURL ) 
  • qPingTool/branches/plone-3.1/config.py

    r697 r1237  
    1 from Products.CMFCore import CMFCorePermissions 
    21from Products.Archetypes.utils import DisplayList 
     2from Products.CMFCore.permissions import ManagePortal 
    33 
    4 SKINS_DIR = 'skins' 
    54GLOBALS = globals() 
    65PROJECTNAME = 'qPingTool' 
    76 
    8 ADD_PERMISSION = CMFCorePermissions.ManagePortal 
    9  
    10 TOOL_ID = 'portal_pingtool' 
     7ADD_PERMISSION = ManagePortal 
    118 
    129TOOL_ICON = 'skins/qpingtool/tool.gif' 
    1310 
    14 RSS_LIST = DisplayList((('Blog','Blog'),('RSS','RSS1'),('RSS2','RSS2'))) 
     11RSS_LIST = DisplayList((('Weblog','Weblog'),('RSS','RSS1'),('RSS2','RSS2'))) 
    1512 
    1613CONFIGURATION_CONFIGLET = 'pingtool_config' 
  • qPingTool/branches/plone-3.1/www/overview.zpt

    r697 r1237  
    11<tal:header tal:replace="structure here/manage_page_header|nothing">Header</tal:header> 
    22<tal:message tal:define="manage_tabs_message options/manage_tabs_message | request/manage_tabs_message | nothing" 
    3     tal:replace="structure here/manage_tabs">Tabs</tal:message> 
     3             tal:replace="structure here/manage_tabs">Tabs</tal:message> 
    44<tal:body  
    5    tal:define="canonical_url_value request/canonical_url_value | python:modules['Products.qPingTool.util'].getCanonicalURL(here)
    6                hasCanonicalURL request/hasCanonicalURL | python:test(canonical_url_value, 1, 0); 
    7                action python:test(hasCanonicalURL, 'Update', 'Add'); 
     5   tal:define="portal here/portal_url/getPortalObject
     6               canonical_url_value request/canonical_url_value | python:portal.getProperty('canonical_url'); 
     7               hasCanonicalURL request/hasCanonicalURL | python:portal.hasProperty('canonical_url'); 
    88               button request/submit | nothing; 
    99               submitted request/submitted | nothing;"> 
     10   <div tal:condition="submitted" 
     11        tal:omit-tag=""> 
     12      <tal:common> 
     13         <div tal:condition="python:button=='Update' and hasCanonicalURL"> 
     14            <tal:block define="result python:portal.manage_changeProperties(canonical_url=canonical_url_value)"/> 
     15         </div> 
     16         <div tal:condition="python:button=='Add' and not hasCanonicalURL"> 
     17            <tal:block define="result python:portal.manage_addProperty('canonical_url', canonical_url_value, 'string')"/> 
     18         </div> 
     19      </tal:common> 
     20   </div> 
    1021 
    11 <div tal:condition="submitted" 
    12      tal:omit-tag="string:"> 
    13   <tal:common 
    14     define="portal here/portal_url/getPortalObject;"> 
    15     <div tal:condition="python:button=='Update'"> 
    16         <tal:block define="result python:portal.manage_changeProperties(canonical_url=canonical_url_value)"/> 
    17     </div> 
    18     <div tal:condition="python:button=='Add'"> 
    19         <tal:block define="result python:portal.manage_addProperty('canonical_url', canonical_url_value, 'string')"/> 
    20     </div> 
    21   </tal:common> 
    22 </div> 
     22   <h3>Overview</h3> 
     23   <p> 
     24      <strong>portal_pingtool</strong> is symple tool to enable pinging of external feed agregators. 
     25   </p> 
     26   <div tal:omit-tag="" 
     27        tal:define="hasCanonicalURL request/hasCanonicalURL | python:portal.hasProperty('canonical_url'); 
     28                    action python:test(hasCanonicalURL, 'Update', 'Add');"> 
     29      <h3 tal:content="string:$action Canonical URL">Update Canonical URL</h3> 
     30      <p tal:condition="not:hasCanonicalURL">Until you setup canonical_url - Ping Tool will not work.</p> 
    2331 
    24 <h3>Overview</h3> 
     32      <form method="post" action="" tal:attributes="action python:'manage_'+template.getId()"> 
     33         <input type="hidden" name="submitted" value="1" /> 
     34         <p class="form-help" 
     35            tal:content="string:To $action the property, enter a canonical URL value and click the &quot;$action&quot; button"> 
     36            To Add/Update the property, enter a canonical URL value and click the &quot;Add/Update&quot; button. 
     37         </p> 
    2538 
    26 <p> <strong>portal_pingtool</strong> is symple tool to enable pinging of external feed agregators. 
    27 </p> 
    28  
    29  
    30 <h3 tal:content="string:$action Canonical URL">Update Canonical URL</h3> 
    31  
    32   <p tal:condition="not:hasCanonicalURL">Until you setup canonical_url - Ping Tool will not work.</p> 
    33  
    34   <form method="put" action="" tal:attributes="action template/getId"> 
    35     <input type="hidden" name="submitted" value="1" /> 
    36  
    37     <p class="form-help" 
    38        tal:content="string:To $action the property, enter a canonical URL value and click the &quot;$action&quot; button"> 
    39     To Add/Update the property, enter a canonical URL value 
    40     and click the &quot;Add/Update&quot; button. 
    41     </p> 
    42  
    43     <table> 
    44       <tr> 
    45         <td align="left" valign="top"> 
    46           <div class="form-label">Canonical URL</div> 
    47         </td> 
    48         <td align="left" valign="top"> 
    49           <input type="text" size="30" value="" name="canonical_url_value" 
    50               tal:attributes="value canonical_url_value | nothing"/> 
    51       </tr> 
    52       <tr> 
    53         <td align="right" valign="top"> 
    54           <div class="form-element"> 
    55             <input class="form-element" type="submit" name="submit" value="Save" 
    56                     tal:attributes="value string:$action;" /> 
    57           </div> 
    58         </td> 
    59       </tr> 
    60     </table> 
    61   </form> 
     39         <table> 
     40            <tr> 
     41               <td align="left" valign="top"> 
     42                  <div class="form-label">Canonical URL</div> 
     43               </td> 
     44               <td align="left" valign="top"> 
     45                  <input type="text" size="30" value="" name="canonical_url_value" 
     46                     tal:attributes="value canonical_url_value | nothing"/> 
     47            </tr> 
     48            <tr> 
     49               <td align="right" valign="top"> 
     50                  <div class="form-element"> 
     51                     <input class="form-element" type="submit" name="submit" value="Save" 
     52                        tal:attributes="value string:$action;" /> 
     53                  </div> 
     54               </td> 
     55            </tr> 
     56         </table> 
     57      </form> 
     58   </div> 
    6259</tal:body> 
    6360<tal:footer tal:replace="structure here/manage_page_footer|nothing">footer</tal:footer>