source: products/quintagroup.plonegooglesitemaps/branches/migratioin_product/quintagroup/plonegooglesitemaps/browser/commonview.py @ 2826

Last change on this file since 2826 was 2742, checked in by mylan, 14 years ago

#226: Force sitemap search content related to the place, where it added to

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1from string import find
2from zope.interface import implements, Interface, Attribute
3
4from Acquisition import aq_inner, aq_parent
5from Products.Five import BrowserView
6from Products.CMFCore.utils import getToolByName
7
8from quintagroup.plonegooglesitemaps import qPloneGoogleSitemapsMessageFactory as _
9from quintagroup.plonegooglesitemaps.browser.utils import additionalURLs, applyOperations
10
11
12class ISitemapView(Interface):
13    """
14    Sitemap view interface
15    """
16
17    def results():
18        """ Return list of dictionary objects
19            which confirm Sitemap conditions
20        """
21
22    def getAdditionalURLs():
23        """ Return additional URL list
24        """
25
26    def updateRequest():
27        """ Add compression header to RESPONSE
28            if allowed
29        """
30
31    numEntries = Attribute("Return number of entries")
32
33class CommonSitemapView(BrowserView):
34    """
35    Sitemap browser view
36    """
37    implements(ISitemapView)
38
39    # key, function map for extend return results
40    # with mapping data
41    additional_maps = ()
42
43
44    def __init__(self, context, request):
45        self.context = context
46        self.request = request
47
48    @property
49    def portal_catalog(self):
50        return getToolByName(self.context, 'portal_catalog')
51
52    @property
53    def portal(self):
54        return getToolByName(self.context, 'portal_url').getPortalObject()
55
56    @property
57    def search_path(self):
58        return '/'.join(aq_parent(aq_inner(self.context)).getPhysicalPath())
59
60    def getFilteredObjects(self):
61        """ Return brains
62        """
63        return []
64
65    def results(self):
66        """ Prepare mapping for template
67        """
68        result = []
69        objects = self.getFilteredObjects()
70        blackout_list = self.context.getBlackout_list()
71        reg_exps = self.context.getReg_exp()
72
73        brain_url_map = applyOperations([ob for ob in objects
74            if (ob.getId not in blackout_list)],
75            reg_exps)
76
77        # Prepare dictionary for view
78        for url, b in brain_url_map.items():
79            res_map = {'url' : url,}
80            [res_map.update({k : f(b)}) for k, f in self.additional_maps]
81            result.append(res_map)
82        self.num_entries = len(result)
83        return result
84
85    def updateRequest(self):
86        self.request.RESPONSE.setHeader('Content-Type', 'text/xml')
87        try:
88            compression = self.context.enableHTTPCompression()
89            if compression:
90                compression(request=self.request)
91        except:
92            pass
93
94    def getAdditionalURLs(self):
95        return additionalURLs(self.context)
96
97    @property
98    def numEntries(self):
99        return len(self.results()) + len(self.getAdditionalURLs())
Note: See TracBrowser for help on using the repository browser.