source: products/qPloneGoogleSitemaps/trunk/browser/commonview.py

Last change on this file was 793, checked in by chervol, 13 years ago

add place for EditorProfile?

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