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

Last change on this file since 2660 was 2660, checked in by chervol, 14 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.3 KB
Line 
1from Products.Five import BrowserView
2from Products.CMFCore.utils import getToolByName
3from Products.CMFPlone.PloneBatch import Batch
4from quintagroup.blog.star.interfaces import IQGBlogEntryRetriever
5try:
6    from plone.app.discussion.interfaces import IConversation
7    USE_PAD = True
8except ImportError:
9    USE_PAD = False
10   
11class BlogView(BrowserView):
12    """
13    Blog view
14    """
15
16    def __init__(self, context, request):
17        self.context = context
18        self.request = request
19        self.portal_discussion = getToolByName(self.context, 'portal_discussion')
20       
21    def blogitems(self):
22        """List all blog items as brains"""
23        # XXX Could perhaps be cached?
24        year = int(self.request.form.get('year',0))
25        month = int(self.request.form.get('month',0))
26        # add all request parameters exept year and month
27        req = dict(self.request.form)
28        for k in ['year', 'month']:
29            if req.has_key(k):
30                del req['year']
31        return IQGBlogEntryRetriever(self.context).get_entries(
32            year=year, month=month, **req)
33
34    def batch(self):
35        portal_properties = getToolByName(self.context, 'portal_properties')
36        site_properties = getattr(portal_properties, 'site_properties')
37        b_size = site_properties.getProperty('blog_view_items', 10)
38        b_start = self.request.form.get('b_start', 0)
39        return Batch(self.blogitems(), b_size, b_start, orphan=2)
40
41    def commentsEnabled(self, ob):
42        if USE_PAD:
43            conversation = IConversation(ob)
44            return conversation.enabled()
45        else:
46            return self.portal_discussion.isDiscussionAllowedFor(ob)
47       
48    def commentCount(self, ob):
49        if USE_PAD:
50            conversation = IConversation(ob)
51            return len(conversation)
52        else:
53            discussion = self.portal_discussion.getDiscussionFor(ob)
54            return discussion.replyCount(ob)
55       
56    def item_url(self, item):
57        portal_properties = getToolByName(self.context, 'portal_properties')
58        site_properties = getattr(portal_properties, 'site_properties')
59        use_view = site_properties.getProperty('typesUseViewActionInListings')
60        url = item.getURL()
61        if item.portal_type in use_view:
62            return '%s/view' % url
63        return url
Note: See TracBrowser for help on using the repository browser.