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

Last change on this file since 458 was 458, checked in by fenix, 18 years ago

qPloneResolveUID import

  • 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        # Prepare dictionary for view
73        for url, b in brain_url_map.items():
74            res_map = {'url' : url,}
75            [res_map.update({k : f(b)}) for k, f in self.additional_maps]
76            result.append(res_map)
77        self.num_entries = len(result)
78        return result
79
80    def updateRequest(self):
81        self.request.RESPONSE.setHeader('Content-Type', 'text/xml')
82        try:
83            compression = self.context.enableHTTPCompression()
84            if compression:
85                compression(request=self.request)
86        except:
87            pass
88
89    def getAdditionalURLs(self):
90        return additionalURLs(self.context)
91
92    @property
93    def numEntries(self):
94        return len(self.results()) + len(self.getAdditionalURLs())
Note: See TracBrowser for help on using the repository browser.