source: products/qPloneGoogleSitemaps/branches/contenttype/browser/commonview.py @ 402

Last change on this file since 402 was 402, checked in by crchemist, 18 years ago

All tests passed.

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1from string import find
2from zope.interface import implements, Interface
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
31class CommonSitemapView(BrowserView):
32    """
33    Sitemap browser view
34    """
35    implements(ISitemapView)
36
37    # key, function map for extend return results
38    # with mapping data
39    additional_maps = ()
40
41
42    def __init__(self, context, request):
43        self.context = context
44        self.request = request
45
46    @property
47    def portal_catalog(self):
48        return getToolByName(self.context, 'portal_catalog')
49
50    @property
51    def portal(self):
52        return getToolByName(self.context, 'portal_url').getPortalObject()
53
54    def getFilteredObjects(self):
55        """ Return brains
56        """
57        return []
58
59    def results(self):
60        """ Prepare mapping for template
61        """
62        result = []
63        objects = self.getFilteredObjects()
64        blackout_list = self.context.getBlackout_list()
65        reg_exps = self.context.getReg_exp()
66
67        brain_url_map = applyOperations([ob for ob in objects
68            if (ob.getId not in blackout_list)],
69            reg_exps)
70
71        # Prepare dictionary for view
72        for url, b in brain_url_map.items():
73            res_map = {'url' : url,}
74            [res_map.update({k : f(b)}) for k, f in self.additional_maps]
75            result.append(res_map)
76        return result
77
78    def updateRequest(self):
79        self.request.RESPONSE.setHeader('Content-Type', 'text/xml')
80        try:
81            compression = self.context.enableHTTPCompression()
82            if compression:
83                compression(request=self.request)
84        except:
85            pass
86
87    def getAdditionalURLs(self):
88        return additionalURLs(self.context)
Note: See TracBrowser for help on using the repository browser.