Changeset 2916 in products


Ignore:
Timestamp:
Oct 22, 2010 11:38:57 AM (14 years ago)
Author:
mylan
Message:

#228: Added getBOFiltered method to sitemap common view

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.plonegooglesitemaps/branches/blacklist/quintagroup/plonegooglesitemaps/browser/commonview.py

    r2742 r2916  
    11from string import find 
    22from zope.interface import implements, Interface, Attribute 
     3from zope.component import queryUtility 
    34 
    45from Acquisition import aq_inner, aq_parent 
     
    78 
    89from quintagroup.plonegooglesitemaps import qPloneGoogleSitemapsMessageFactory as _ 
     10from quintagroup.plonegooglesitemaps.config import BLACKOUT_PREFIX 
     11from quintagroup.plonegooglesitemaps.interfaces import IBlackoutFilterUtility 
    912from quintagroup.plonegooglesitemaps.browser.utils import additionalURLs, applyOperations 
    1013 
     
    6871        result = [] 
    6972        objects = self.getFilteredObjects() 
    70         blackout_list = self.context.getBlackout_list() 
    7173        reg_exps = self.context.getReg_exp() 
    7274 
    73         brain_url_map = applyOperations([ob for ob in objects  
    74             if (ob.getId not in blackout_list)], 
    75             reg_exps) 
    76  
     75        brain_url_map = applyOperations(self.getBOFiltered(objects), reg_exps) 
    7776        # Prepare dictionary for view 
    7877        for url, b in brain_url_map.items(): 
     
    8281        self.num_entries = len(result) 
    8382        return result 
     83 
     84    def getBOFiltered(self, objects): 
     85        """Return blkack-out filtered objects 
     86          Every record in blackout_list filter should follow the spec: 
     87             [extra filter data, separated by ':':][<filter name>:]<filter data> 
     88          For example: 
     89          1|  index.html 
     90          2|  id:index.html 
     91          3|  path:/folder_1_level/obj_in_folder 
     92          4|  path:./folder_near_sitemap/obj_in_folder 
     93          5|  extra_arg1:extra_arg2:super_filter:super arg-1, super arg-2 
     94          
     95          1->used default "id" filter - remove "index.html" objects; 
     96          2->explicit "id" filter - remove "index.html" objects; 
     97          3->"path" filter - remove /folder_1_level/obj_in_folder object, 
     98              path from the root of the plone site; 
     99          4->same to 3), but path get from the folder, where sitemap is located; 
     100          5->filter name is "super_filter" (must be registered IBlackoutFilterUtility, 
     101             named "seoptimzier.blackoutfilter.super_filter:), which get list of extra 
     102             parameters, e.g. [extra_arg1,extra_arg2] to the filterOut method in 
     103             "extras" option, and get filter arguments: super arg-1, super arg-2 
     104           
     105          class SuperFilterUtility(object): 
     106              def filterOut(self, fdata, fargs, **kwargs): 
     107                  sitemap = kwargs.get("sitemap") 
     108                  extras = kwargs.get("extras") # [extra_arg1,extra_arg2] 
     109                  # some logic to filter-out fdata by fargs with taking into 
     110                  # consideration extras ... 
     111        """ 
     112        blackout_list = filter(None, self.context.getBlackout_list()) 
     113        for frec in blackout_list: 
     114            fspec = frec.split(":") 
     115            fargs = fspec.pop() 
     116            fname = BLACKOUT_PREFIX + (fspec and fspec.pop() or "id") 
     117            futility = queryUtility(IBlackoutFilterUtility, name=fname) 
     118            if futility: 
     119                kw = {"sitemap": self.context, 
     120                      "extras": fspec} 
     121                objects = futility.filterOut(objects, fargs, **kw) 
     122        return objects 
    84123 
    85124    def updateRequest(self): 
Note: See TracChangeset for help on using the changeset viewer.