[396] | 1 | from string import find |
---|
| 2 | from zope.interface import implements, Interface |
---|
| 3 | |
---|
| 4 | from Products.Five import BrowserView |
---|
| 5 | from Products.CMFCore.utils import getToolByName |
---|
| 6 | |
---|
| 7 | from Products.qPloneGoogleSitemaps import qPloneGoogleSitemapsMessageFactory as _ |
---|
| 8 | from utils import additionalURLs, applyOperations |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | class 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 | |
---|
| 31 | class CommonSitemapView(BrowserView): |
---|
| 32 | """ |
---|
| 33 | Sitemap browser view |
---|
| 34 | """ |
---|
| 35 | implements(ISitemapView) |
---|
| 36 | |
---|
[402] | 37 | # key, function map for extend return results |
---|
| 38 | # with mapping data |
---|
| 39 | additional_maps = () |
---|
| 40 | |
---|
| 41 | |
---|
[396] | 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): |
---|
[402] | 55 | """ Return brains |
---|
| 56 | """ |
---|
[396] | 57 | return [] |
---|
| 58 | |
---|
| 59 | def results(self): |
---|
[402] | 60 | """ Prepare mapping for template |
---|
| 61 | """ |
---|
| 62 | result = [] |
---|
| 63 | objects = self.getFilteredObjects() |
---|
[396] | 64 | blackout_list = self.context.getBlackout_list() |
---|
| 65 | reg_exps = self.context.getReg_exp() |
---|
[402] | 66 | |
---|
| 67 | brain_url_map = applyOperations([ob for ob in objects |
---|
[396] | 68 | if (ob.getId not in blackout_list)], |
---|
| 69 | reg_exps) |
---|
| 70 | |
---|
[402] | 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 | |
---|
[396] | 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) |
---|