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

Last change on this file since 2652 was 2652, checked in by chervol, 14 years ago

#27: Fixed 'field under' URL (force pass blog object to blog_item_view and use it URL in 'field under')

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1from Products.Five import BrowserView
2from Products.CMFCore.utils import getToolByName
3from Products.CMFPlone.PloneBatch import Batch
4from collective.blog.view.interfaces import IBlogEntryRetriever
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        return IBlogEntryRetriever(self.context).get_entries(year=year, month=month)
27
28    def batch(self):
29        portal_properties = getToolByName(self.context, 'portal_properties')
30        site_properties = getattr(portal_properties, 'site_properties')
31        b_size = site_properties.getProperty('blog_view_items', 10)
32        b_start = self.request.form.get('b_start', 0)
33        return Batch(self.blogitems(), b_size, b_start, orphan=2)
34
35    def commentsEnabled(self, ob):
36        if USE_PAD:
37            conversation = IConversation(ob)
38            return conversation.enabled()
39        else:
40            return self.portal_discussion.isDiscussionAllowedFor(ob)
41       
42    def commentCount(self, ob):
43        if USE_PAD:
44            conversation = IConversation(ob)
45            return len(conversation)
46        else:
47            discussion = self.portal_discussion.getDiscussionFor(ob)
48            return discussion.replyCount(ob)
49       
50    def item_url(self, item):
51        portal_properties = getToolByName(self.context, 'portal_properties')
52        site_properties = getattr(portal_properties, 'site_properties')
53        use_view = site_properties.getProperty('typesUseViewActionInListings')
54        url = item.getURL()
55        if item.portal_type in use_view:
56            return '%s/view' % url
57        return url
Note: See TracBrowser for help on using the repository browser.