source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/browser/commonview.py @ 3002

Last change on this file since 3002 was 3002, checked in by mylan, 11 years ago

Merged revisions 3948,3950-3951,3954-3964,3978-3981,3984-3992,4016-4018,4028-4037,4039 via svnmerge from
http://svn.quintagroup.com/products/quintagroup.plonegooglesitemaps/branches/blacklist

........

r3948 | mylan | 2010-10-21 16:34:22 +0300 (Thu, 21 Oct 2010) | 1 line


#228: Added IBlackoutFilterUtility interface with skeleton of id and path utilities with appropriate tests.

........

r3950 | mylan | 2010-10-22 11:58:53 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Added tests for default id and path filters

........

r3951 | mylan | 2010-10-22 11:59:25 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Added default id and path blackout filters

........

r3954 | mylan | 2010-10-22 14:38:20 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Added TestFormDataProcessing? tests

........

r3955 | mylan | 2010-10-22 14:38:57 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Added getBOFiltered method to sitemap common view

........

r3956 | mylan | 2010-10-22 15:17:40 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Simplify blacklists filter utility tests

........

r3957 | mylan | 2010-10-22 15:23:24 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Minor name updates in blackout list tests

........

r3958 | mylan | 2010-10-22 15:54:10 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Added tests for relative path in path-filter

........

r3959 | mylan | 2010-10-22 15:54:50 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Added relative path processing in default path-filter

........

r3960 | mylan | 2010-10-22 15:57:18 +0300 (Fri, 22 Oct 2010) | 1 line


#228: Fixed name of the relative path filtering test

........

r3961 | mylan | 2010-10-25 13:51:32 +0300 (Mon, 25 Oct 2010) | 1 line


#228: Fix relative path filter tests and utility

........

r3962 | mylan | 2010-10-25 17:38:55 +0300 (Mon, 25 Oct 2010) | 1 line


#228: Fixed default Path filter

........

r3963 | mylan | 2010-10-25 17:49:27 +0300 (Mon, 25 Oct 2010) | 1 line


#228: Added request to extended list of args for a filter utility.

........

r3964 | mylan | 2010-10-25 17:50:57 +0300 (Mon, 25 Oct 2010) | 1 line


#228: Fixed rewrited blackout filter utility and functionality.

........

r3978 | mylan | 2010-10-28 19:26:11 +0300 (Thu, 28 Oct 2010) | 1 line


#228: Remake filter utility to multiadapter, fix tests

........

r3979 | mylan | 2010-10-28 19:57:24 +0300 (Thu, 28 Oct 2010) | 1 line


#228: Fix filter naming overhead, fix tests

........

r3980 | mylan | 2010-10-28 21:10:51 +0300 (Thu, 28 Oct 2010) | 1 line


#228: Fix overhead in parsing of filter arguments. Added test (breakage yet)

........

r3981 | mylan | 2010-10-29 12:57:34 +0300 (Fri, 29 Oct 2010) | 1 line


#228: Add blackout_list value clean-up on editing sitemap

........

r3984 | mylan | 2010-10-29 13:53:54 +0300 (Fri, 29 Oct 2010) | 1 line


#228: Update description of blackout list, remove preparations to filtering

........

r3985 | mylan | 2010-10-29 16:14:29 +0300 (Fri, 29 Oct 2010) | 1 line


#228: Added doc tests bases

........

r3986 | mylan | 2010-10-29 16:53:41 +0300 (Fri, 29 Oct 2010) | 1 line


#228: Added basic doctests of filtering

........

r3987 | mylan | 2010-10-29 16:57:40 +0300 (Fri, 29 Oct 2010) | 1 line


#228: Minor fixes of filtering doctests.

........

r3988 | mylan | 2010-11-01 13:31:04 +0200 (Mon, 01 Nov 2010) | 1 line


#228: Added doctests of id, path, default filters

........

r3989 | mylan | 2010-11-01 15:20:03 +0200 (Mon, 01 Nov 2010) | 1 line


#228: Fixed default behavior filter doctests

........

r3990 | mylan | 2010-11-01 15:20:51 +0200 (Mon, 01 Nov 2010) | 1 line


#228: Added example of new filter creation in doctests

........

r3991 | mylan | 2010-11-01 15:35:10 +0200 (Mon, 01 Nov 2010) | 1 line


#228: Clean-up, simplify filters doctests

........

r3992 | mylan | 2010-11-01 15:39:55 +0200 (Mon, 01 Nov 2010) | 1 line


#228: Force to show all doctests failures.

........

r4016 | mylan | 2010-11-05 14:19:46 +0200 (Fri, 05 Nov 2010) | 1 line


#228: Fix incorrect black_list field editing in tests

........

r4017 | mylan | 2010-11-05 14:21:35 +0200 (Fri, 05 Nov 2010) | 1 line


#228: minor docstring update for getBOFiltered method

........

r4018 | mylan | 2010-11-05 14:23:56 +0200 (Fri, 05 Nov 2010) | 1 line


#228: Remake filterOut method of into generator for default filters

........

r4028 | mylan | 2010-11-08 13:58:10 +0200 (Mon, 08 Nov 2010) | 1 line


#228: Added Plone v3.0 support

........

r4029 | mylan | 2010-11-08 16:35:22 +0200 (Mon, 08 Nov 2010) | 1 line


#228: Fixed tests issues

........

r4030 | mylan | 2010-11-08 16:49:28 +0200 (Mon, 08 Nov 2010) | 1 line


#228: Fixed ran of tearing down testing layers

........

r4031 | mylan | 2010-11-08 17:04:01 +0200 (Mon, 08 Nov 2010) | 1 line


#228: Fixed differencies in forms for plone<=3.1 and plone>3.1

........

r4032 | mylan | 2010-11-10 13:48:47 +0200 (Wed, 10 Nov 2010) | 1 line


#228: Switch to use collective.testcaselayer

........

r4033 | mylan | 2010-11-10 13:49:09 +0200 (Wed, 10 Nov 2010) | 1 line


#228: Fix doctest testcase

........

r4034 | mylan | 2010-11-10 14:34:17 +0200 (Wed, 10 Nov 2010) | 1 line


#228: Fixed list of required packages for testing

........

r4035 | mylan | 2010-11-11 12:29:06 +0200 (Thu, 11 Nov 2010) | 1 line


#228: remake filters to generators

........

r4036 | mylan | 2010-11-11 15:16:53 +0200 (Thu, 11 Nov 2010) | 1 line


#228: reviewed explanation, correct grammar for filters doctest

........

r4037 | mylan | 2010-11-11 15:19:24 +0200 (Thu, 11 Nov 2010) | 1 line


#228: updated histroy, bumped version to 1.6.0

........

r4039 | mylan | 2010-11-11 19:03:01 +0200 (Thu, 11 Nov 2010) | 1 line


#228:Fixed typo in doctests

........

  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1from string import find
2from zope.interface import implements, Interface, Attribute
3from zope.component import queryMultiAdapter
4
5from Acquisition import aq_inner, aq_parent
6from Products.Five import BrowserView
7from Products.CMFCore.utils import getToolByName
8
9from quintagroup.plonegooglesitemaps import qPloneGoogleSitemapsMessageFactory as _
10from quintagroup.plonegooglesitemaps.interfaces import IBlackoutFilter
11from quintagroup.plonegooglesitemaps.browser.utils import additionalURLs, applyOperations
12
13
14class ISitemapView(Interface):
15    """
16    Sitemap view interface
17    """
18
19    def results():
20        """ Return list of dictionary objects
21            which confirm Sitemap conditions
22        """
23
24    def getAdditionalURLs():
25        """ Return additional URL list
26        """
27
28    def updateRequest():
29        """ Add compression header to RESPONSE
30            if allowed
31        """
32
33    numEntries = Attribute("Return number of entries")
34
35class CommonSitemapView(BrowserView):
36    """
37    Sitemap browser view
38    """
39    implements(ISitemapView)
40
41    # key, function map for extend return results
42    # with mapping data
43    additional_maps = ()
44
45
46    def __init__(self, context, request):
47        self.context = context
48        self.request = request
49
50    @property
51    def portal_catalog(self):
52        return getToolByName(self.context, 'portal_catalog')
53
54    @property
55    def portal(self):
56        return getToolByName(self.context, 'portal_url').getPortalObject()
57
58    @property
59    def search_path(self):
60        return '/'.join(aq_parent(aq_inner(self.context)).getPhysicalPath())
61
62    def getFilteredObjects(self):
63        """ Return brains
64        """
65        return []
66
67    def results(self):
68        """ Prepare mapping for template
69        """
70        result = []
71        objects = self.getFilteredObjects()
72        reg_exps = self.context.getReg_exp()
73
74        brain_url_map = applyOperations(self.getBOFiltered(objects), reg_exps)
75        # Prepare dictionary for view
76        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            result.append(res_map)
80        self.num_entries = len(result)
81        return result
82
83    def getBOFiltered(self, objects):
84        """Return black-out filtered objects
85          Every record in blackout_list filter should follow the spec:
86            [<filter name>:]<filter arguments>
87          For example:
88          1|  index.html
89          2|  id:index.html
90          3|  path:/folder_1_level/obj_in_folder
91          4|  path:./folder_near_sitemap/obj_in_folder
92          5|  foo_filter:arg-1, arg-2
93         
94          1->used default "id" filter - remove "index.html" objects;
95          2->explicit "id" filter - remove "index.html" objects;
96          3->"path" filter - remove /folder_1_level/obj_in_folder object,
97              path from the root of the plone site;
98          4->same to 3), but path get from the folder, where sitemap is located;
99          5->filter name is "foo_filter" (must be registered IBlackoutFilter,
100             named "foo_filter"), which get filter arguments: arg-1, arg-2
101         
102          Detailed explanation look in filters.txt doctest.
103        """ 
104        blackout_list = self.context.getBlackout_list()
105        for frec in blackout_list:
106            fspec = frec.split(":", 1)
107            fargs = fspec.pop()
108            fname = fspec and fspec.pop() or "id"
109            fengine = queryMultiAdapter((self.context, self.request),
110                          interface=IBlackoutFilter, name=fname)
111            if fengine:
112                objects = list(fengine.filterOut(objects, fargs))
113        return objects
114
115    def updateRequest(self):
116        self.request.RESPONSE.setHeader('Content-Type', 'text/xml')
117        try:
118            compression = self.context.enableHTTPCompression()
119            if compression:
120                compression(request=self.request)
121        except:
122            pass
123
124    def getAdditionalURLs(self):
125        return additionalURLs(self.context)
126
127    @property
128    def numEntries(self):
129        return len(self.results()) + len(self.getAdditionalURLs())
Note: See TracBrowser for help on using the repository browser.