Ignore:
Timestamp:
Apr 20, 2011 8:20:36 AM (13 years ago)
Author:
zidane
Message:

fixes pep8

Location:
quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser/commonview.py

    r3002 r3152  
    77from Products.CMFCore.utils import getToolByName 
    88 
    9 from quintagroup.plonegooglesitemaps import qPloneGoogleSitemapsMessageFactory as _ 
     9from quintagroup.plonegooglesitemaps \ 
     10    import qPloneGoogleSitemapsMessageFactory as _ 
    1011from quintagroup.plonegooglesitemaps.interfaces import IBlackoutFilter 
    11 from quintagroup.plonegooglesitemaps.browser.utils import additionalURLs, applyOperations 
     12from quintagroup.plonegooglesitemaps.browser.utils import additionalURLs, \ 
     13    applyOperations 
    1214 
    1315 
     
    3335    numEntries = Attribute("Return number of entries") 
    3436 
     37 
    3538class CommonSitemapView(BrowserView): 
    3639    """ 
     
    4245    # with mapping data 
    4346    additional_maps = () 
    44  
    4547 
    4648    def __init__(self, context, request): 
     
    7577        # Prepare dictionary for view 
    7678        for url, b in brain_url_map.items(): 
    77             res_map = {'url' : url,} 
    78             [res_map.update({k : f(b)}) for k, f in self.additional_maps] 
     79            res_map = {'url': url, } 
     80            [res_map.update({k: f(b)}) for k, f in self.additional_maps] 
    7981            result.append(res_map) 
    8082        self.num_entries = len(result) 
     
    9193          4|  path:./folder_near_sitemap/obj_in_folder 
    9294          5|  foo_filter:arg-1, arg-2 
    93           
     95 
    9496          1->used default "id" filter - remove "index.html" objects; 
    9597          2->explicit "id" filter - remove "index.html" objects; 
    9698          3->"path" filter - remove /folder_1_level/obj_in_folder object, 
    9799              path from the root of the plone site; 
    98           4->same to 3), but path get from the folder, where sitemap is located; 
     100          4->same to 3), but path get from the folder, where sitemap is 
     101             located; 
    99102          5->filter name is "foo_filter" (must be registered IBlackoutFilter, 
    100103             named "foo_filter"), which get filter arguments: arg-1, arg-2 
    101           
     104 
    102105          Detailed explanation look in filters.txt doctest. 
    103         """  
     106        """ 
    104107        blackout_list = self.context.getBlackout_list() 
    105108        for frec in blackout_list: 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser/configletview.py

    r3006 r3152  
    88 
    99from quintagroup.plonegooglesitemaps.interfaces import ISitemap 
    10 from quintagroup.plonegooglesitemaps import qPloneGoogleSitemapsMessageFactory as _ 
     10from quintagroup.plonegooglesitemaps \ 
     11    import qPloneGoogleSitemapsMessageFactory as _ 
     12 
    1113 
    1214def splitNum(num): 
     
    1416    prefn = 3 
    1517    for c in str(num)[::-1]: 
    16         res.insert(0,c) 
    17         if not len(res)%prefn: 
    18             res.insert(0,',') 
     18        res.insert(0, c) 
     19        if not len(res) % prefn: 
     20            res.insert(0, ',') 
    1921            prefn += 4 
    20     return "".join(res[0]==',' and res[1:] or res) 
     22    return "".join(res[0] == ',' and res[1:] or res) 
     23 
    2124 
    2225class IConfigletSettingsView(Interface): 
     
    2528    """ 
    2629 
    27     sitemaps = Attribute("Returns mapping of sitemap's type to list of appropriate objects") 
    28     hasContentSM = Attribute("Returns boolean about existance of content sitemap") 
    29     hasMobileSM = Attribute("Returns boolean about existance of mobile sitemap") 
     30    sitemaps = Attribute("Returns mapping of sitemap's type to list of " \ 
     31                         "appropriate objects") 
     32    hasContentSM = Attribute("Returns boolean about existance of content " \ 
     33                             "sitemap") 
     34    hasMobileSM = Attribute("Returns boolean about existance of mobile " \ 
     35                            "sitemap") 
    3036    hasNewsSM = Attribute("Returns boolean about existance of news sitemap") 
    3137    sm_types = Attribute("List of sitemap types") 
     
    4652    def uploadVerificationFile(vfile): 
    4753        """ Upload passed site verification file to the site. 
    48             On success - update googlesitemaps verification files list.  
     54            On success - update googlesitemaps verification files list. 
    4955            Return tuple where : 
    5056              1. boolean value - is verification file successfully created. 
     
    5359                2.2. if failure - error descirption 
    5460        """ 
     61 
    5562 
    5663class ConfigletSettingsView(BrowserView): 
     
    6572        self.request = request 
    6673 
    67         self.tools = queryMultiAdapter((self.context, self.request), name="plone_tools") 
    68         self.pps = queryMultiAdapter((self.context, self.request), name="plone_portal_state") 
    69         self.sitemaps = [i.getObject() for i in self.tools.catalog()(portal_type='Sitemap')] 
     74        self.tools = queryMultiAdapter((self.context, self.request), 
     75                                       name="plone_tools") 
     76        self.pps = queryMultiAdapter((self.context, self.request), 
     77                                     name="plone_portal_state") 
     78        self.sitemaps = [i.getObject() for i in \ 
     79                         self.tools.catalog()(portal_type='Sitemap')] 
    7080 
    7181    @property 
     
    8898        sitemaps = {} 
    8999        for sm in self.sitemaps: 
    90             smlist = sitemaps.setdefault(sm.getSitemapType(),[]) 
    91             smlist.append({'url':sm.absolute_url(),'id':sm.id}) 
    92         sitemaps['all'] = sitemaps.setdefault('content',[]) + \ 
    93                           sitemaps.setdefault('mobile',[]) + \ 
    94                           sitemaps.setdefault('news',[]) 
     100            smlist = sitemaps.setdefault(sm.getSitemapType(), []) 
     101            smlist.append({'url': sm.absolute_url(), 'id': sm.id}) 
     102        sitemaps['all'] = sitemaps.setdefault('content', []) + \ 
     103                          sitemaps.setdefault('mobile', []) + \ 
     104                          sitemaps.setdefault('news', []) 
    95105        return sitemaps 
    96106 
     
    98108        sitemaps = {} 
    99109        for sm in self.sitemaps: 
    100             smlist = sitemaps.setdefault(sm.getSitemapType(),[]) 
     110            smlist = sitemaps.setdefault(sm.getSitemapType(), []) 
    101111            smlist.append(sm.absolute_url()) 
    102112        return sitemaps 
    103113 
    104114    def sitemapsDict(self): 
    105         content, mobile, news = [],[],[] 
     115        content, mobile, news = [], [], [] 
    106116        for sm in self.sitemaps: 
    107117            data = self.getSMData(sm) 
     
    116126    def getSMData(self, ob): 
    117127        size, entries = self.getSitemapData(ob) 
    118         return {'sm_type'    : ob.getSitemapType().capitalize(), 
    119                 'sm_id'      : ob.id, 
    120                 'sm_url'     : ob.absolute_url(), 
    121                 'sm_size'    : size and splitNum(size) or '', 
    122                 'sm_entries' : entries and splitNum(entries) or '', 
     128        return {'sm_type': ob.getSitemapType().capitalize(), 
     129                'sm_id': ob.id, 
     130                'sm_url': ob.absolute_url(), 
     131                'sm_size': size and splitNum(size) or '', 
     132                'sm_entries': entries and splitNum(entries) or '', 
    123133               } 
    124134 
     
    128138        if view: 
    129139            resp = self.request.RESPONSE 
    130             bview = queryMultiAdapter((ob,self.request), name=view) 
     140            bview = queryMultiAdapter((ob, self.request), name=view) 
    131141            if bview: 
    132142                try: 
    133143                    size = len(bview()) 
    134144                    entries = bview.numEntries 
    135                     self.request.RESPONSE.setHeader('Content-Type', 'text/html') 
     145                    self.request.RESPONSE.setHeader('Content-Type', 
     146                                                    'text/html') 
    136147                except: 
    137148                    pass 
     
    140151    def getVerificationFiles(self): 
    141152        vfs = [] 
    142         props = getattr(self.tools.properties(),'googlesitemap_properties') 
     153        props = getattr(self.tools.properties(), 'googlesitemap_properties') 
    143154        if props: 
    144155            portal_ids = self.pps.portal().objectIds() 
    145             props_vfs = list(props.getProperty('verification_filenames',[])) 
     156            props_vfs = list(props.getProperty('verification_filenames', [])) 
    146157            vfs = [vf for vf in props_vfs if vf in portal_ids] 
    147             if not props_vfs==vfs: 
     158            if not props_vfs == vfs: 
    148159                props._updateProperty('verification_filenames', vfs) 
    149160        return vfs 
     
    157168            portal.manage_addFile(id="", file=vfile) 
    158169            portal[vfilename].manage_addProperty( 
    159                 'CreatedBy', 'quintagroupt.plonegooglesitemaps','string') 
     170                'CreatedBy', 'quintagroupt.plonegooglesitemaps', 'string') 
    160171        except BadRequestException, e: 
    161172            return False, str(e) 
    162173        else: 
    163174            props = self.tools.properties().googlesitemap_properties 
    164             vfilenames = list(props.getProperty('verification_filenames',[])) 
     175            vfilenames = list(props.getProperty('verification_filenames', [])) 
    165176            vfilenames.append(vfilename) 
    166             props.manage_changeProperties(verification_filenames = vfilenames) 
     177            props.manage_changeProperties(verification_filenames=vfilenames) 
    167178        return True, vfilename 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser/mobilesitemapview.py

    r2742 r3152  
    22from quintagroup.plonegooglesitemaps.browser.commonview import * 
    33 
    4 MOBILE_INTERFACES = ['quintagroup.mobileextender.interfaces.IMobile',] 
     4MOBILE_INTERFACES = ['quintagroup.mobileextender.interfaces.IMobile', ] 
     5 
    56 
    67class MobileSitemapView(CommonSitemapView): 
     
    1112 
    1213    additional_maps = ( 
    13         ('modification_date', lambda x:DateTime(x.ModificationDate).HTML4()), 
     14        ('modification_date', lambda x: DateTime(x.ModificationDate).HTML4()), 
    1415    ) 
    1516 
    1617    def getFilteredObjects(self): 
    1718        return self.portal_catalog( 
    18             path = self.search_path, 
    19             portal_type = self.context.getPortalTypes(), 
    20             review_state = self.context.getStates(), 
    21             object_provides = MOBILE_INTERFACES, 
     19            path=self.search_path, 
     20            portal_type=self.context.getPortalTypes(), 
     21            review_state=self.context.getStates(), 
     22            object_provides=MOBILE_INTERFACES, 
    2223            ) 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser/newssitemapview.py

    r2751 r3152  
    77reTrailingParenthtical = re.compile("\s*\(.*\)\s*", re.S) 
    88 
    9 formatDate = lambda d:DateTime(d).strftime("%Y-%m-%d") 
     9formatDate = lambda d: DateTime(d).strftime("%Y-%m-%d") 
     10 
    1011 
    1112class NewsSitemapView(CommonSitemapView): 
     
    1718    @property 
    1819    def additional_maps(self): 
    19          
     20 
    2021        return ( 
    21             ('publication_date', lambda x:x.Date and formatDate(x.Date) or ""), 
    22             ('keywords', lambda x:x.Subject and ', '.join(x.Subject) or ""), 
    23             ('title', lambda x:x.Title or x.getId or x.id), 
    24             ('name', lambda x:x.Title and reTrailingParenthtical.sub("",x.Title) or ""), 
    25             ('language', lambda x:x.Language or self.default_language()), 
    26             ('access', lambda x:x.gsm_access or ""), 
    27             ('genres', lambda x:x.gsm_genres and ", ".join(x.gsm_genres) or ""), 
    28             ('stock', lambda x:x.gsm_stock or ""), 
     22            ('publication_date', lambda x: x.Date and \ 
     23                                 formatDate(x.Date) or ""), 
     24            ('keywords', lambda x: x.Subject and ', '.join(x.Subject) or ""), 
     25            ('title', lambda x: x.Title or x.getId or x.id), 
     26            ('name', lambda x: x.Title and \ 
     27                     reTrailingParenthtical.sub("", x.Title) or ""), 
     28            ('language', lambda x: x.Language or self.default_language()), 
     29            ('access', lambda x: x.gsm_access or ""), 
     30            ('genres', lambda x: x.gsm_genres and \ 
     31                       ", ".join(x.gsm_genres) or ""), 
     32            ('stock', lambda x: x.gsm_stock or ""), 
    2933        ) 
    3034 
    3135    @memoize 
    3236    def default_language(self): 
    33         pps = getMultiAdapter((self.context, self.request), name="plone_portal_state") 
     37        pps = getMultiAdapter((self.context, self.request), 
     38                              name="plone_portal_state") 
    3439        return pps.default_language 
    3540 
     
    3742        min_date = DateTime() - 3 
    3843        return self.portal_catalog( 
    39             path = self.search_path, 
    40             portal_type = self.context.getPortalTypes(), 
    41             review_state = self.context.getStates(), 
    42             effective = {"query": min_date, 
    43                          "range": "min" } 
     44            path=self.search_path, 
     45            portal_type=self.context.getPortalTypes(), 
     46            review_state=self.context.getStates(), 
     47            effective={"query": min_date, 
     48                       "range": "min"} 
    4449            ) 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser/sitemapview.py

    r2742 r3152  
    11from DateTime import DateTime 
    22from quintagroup.plonegooglesitemaps.browser.commonview import * 
     3 
    34 
    45class SitemapView(CommonSitemapView): 
     
    910 
    1011    additional_maps = ( 
    11         ('modification_date', lambda x:DateTime(x.ModificationDate).HTML4()), 
     12        ('modification_date', lambda x: DateTime(x.ModificationDate).HTML4()), 
    1213    ) 
    1314 
    1415    def getFilteredObjects(self): 
    1516        return self.portal_catalog( 
    16             path = self.search_path, 
    17             portal_type = self.context.getPortalTypes(), 
    18             review_state = self.context.getStates() 
     17            path=self.search_path, 
     18            portal_type=self.context.getPortalTypes(), 
     19            review_state=self.context.getStates() 
    1920            ) 
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser/utils.py

    r2181 r3152  
    1414_marker = [] 
    1515 
     16 
    1617def searchAndReplace(string, what, withs): 
    1718    """Emulate sed command s/""" 
    18     res = re.sub(what,withs,string) 
     19    res = re.sub(what, withs, string) 
    1920    return res 
    20 OPERATORS = {'s': searchAndReplace,} 
     21OPERATORS = {'s': searchAndReplace, } 
     22 
    2123 
    2224def applyOperations(objects, operations): 
    2325    """Parse Operations """ 
    24     operations=[OPERATIONS_PARSE.match(op).groups() for op in operations] 
     26    operations = [OPERATIONS_PARSE.match(op).groups() for op in operations] 
    2527    result = {} 
    2628    for ob in objects: 
     
    3840        if url in result.keys(): 
    3941            continue 
    40         #TODO: replace brain with only data necessary to  
     42        #TODO: replace brain with only data necessary to 
    4143        #generate sitemap 
    42         result[url]=ob 
     44        result[url] = ob 
    4345    return result 
     46 
    4447 
    4548def additionalURLs(context): 
     
    4952    plone_home = getToolByName(context, 'portal_url')() 
    5053    root = context.getPhysicalRoot().absolute_url() 
    51     URLs =  context.getUrls() 
     54    URLs = context.getUrls() 
    5255 
    5356    for url in URLs: 
    5457        if ADD_ZOPE.match(url): 
    55             res.append(root+url) 
     58            res.append(root + url) 
    5659        elif ADD_PLONE.match(url): 
    57             res.append(plone_home+'/'+url) 
     60            res.append(plone_home + '/' + url) 
    5861        else: 
    5962            res.append(url) 
Note: See TracChangeset for help on using the changeset viewer.