source: products/quintagroup.blog.star/trunk/quintagroup/blog/star/adapters.py @ 2660

Last change on this file since 2660 was 2660, checked in by chervol, 12 years ago

#27: Update blog view to pass any request paramters to the IQGBlogEntryRequest adapter

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1import calendar
2from zope import interface, component
3from DateTime import DateTime
4from quintagroup.blog.star.interfaces import IQGBlogEntryRetriever
5from Products.CMFCore.utils import getToolByName
6from OFS.interfaces import IFolder
7from Products.ATContentTypes.interface import IATTopic
8
9class FolderEntryGetter:
10    """Gets blog entries in any sort of folder"""
11   
12    interface.implements(IQGBlogEntryRetriever)
13    component.adapts(IFolder)
14   
15    def __init__(self, context):
16        self.context = context
17   
18    def _base_query(self):
19        portal_properties = getToolByName(self.context, 'portal_properties', None)
20        site_properties = getattr(portal_properties, 'site_properties', None)
21        portal_types = site_properties.getProperty('blog_types', None)
22        if portal_types is None:
23            portal_types = ('Document', 'News Item', 'File')
24
25        path = '/'.join(self.context.getPhysicalPath())
26       
27        return dict(path={'query': path, 'depth':1},
28                    portal_type=portal_types,
29                    sort_on='effective', sort_order='reverse')
30   
31    def get_entries(self, year=None, month=None, **kw):
32        catalog = getToolByName(self.context, 'portal_catalog')
33        query = self._base_query()
34        if year:
35            if month:
36                lastday = calendar.monthrange(year, month)[1]
37                startdate = DateTime(year, month, 1, 0, 0)
38                enddate = DateTime(year, month, lastday, 23, 59, 59)
39            else:
40                startdate = DateTime(year, 1, 1, 0, 0)
41                enddate = DateTime(year, 12, 31, 0, 0)
42            query['effective'] = dict(query=(startdate, enddate),
43                                      range='minmax')
44        query.update(dict([(k,v) for k,v in kw.items() if v]))
45
46        return catalog.searchResults(**query)
47
48   
49class TopicEntryGetter(FolderEntryGetter):
50    """Gets blog entries for collections"""
51   
52    interface.implements(IQGBlogEntryRetriever)
53    component.adapts(IATTopic)
54   
55    def __init__(self, context):
56        self.context = context
57       
58    def _base_query(self):
59        return self.context.buildQuery()
Note: See TracBrowser for help on using the repository browser.