[2652] | 1 | from Products.Five import BrowserView |
---|
| 2 | from Products.CMFCore.utils import getToolByName |
---|
| 3 | from Products.CMFPlone.PloneBatch import Batch |
---|
[2656] | 4 | from quintagroup.blog.star.interfaces import IQGBlogEntryRetriever |
---|
[2652] | 5 | try: |
---|
| 6 | from plone.app.discussion.interfaces import IConversation |
---|
| 7 | USE_PAD = True |
---|
| 8 | except ImportError: |
---|
| 9 | USE_PAD = False |
---|
| 10 | |
---|
| 11 | class 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)) |
---|
[2660] | 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'] |
---|
[2656] | 31 | return IQGBlogEntryRetriever(self.context).get_entries( |
---|
[2660] | 32 | year=year, month=month, **req) |
---|
[2652] | 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 |
---|