-
Notifications
You must be signed in to change notification settings - Fork 1
/
blog.py
71 lines (55 loc) · 2.15 KB
/
blog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
from Acquisition import aq_inner
from plone import api
from plone.app.layout.viewlets import ViewletBase
from Products.CMFCore.interfaces import ISiteRoot
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from sc.blog.config import BLOG_BLACKLISTED_TYPES
from sc.blog.content import IBlog
import pkg_resources
try:
pkg_resources.get_distribution('plone.app.contenttypes')
except pkg_resources.DistributionNotFound:
# Don`t have plone.app.contenttypes
from Products.Five.browser import BrowserView as ViewBase
else:
# Has plone.app.contenttypes
from plone.app.contenttypes.browser.folder import FolderView as ViewBase
class View(ViewBase):
"""Default view. Looks like a standard Folder Full View."""
index = ViewPageTemplateFile('templates/folder_full_view.pt')
def get_blog_friendly_types(self):
"""Return the portal types than should be displayed as post entries
inside a Blog. Some content types (like Blog, File, Folder and Image)
are excluded by default.
:returns: a tuple with the names of the portal types
"""
plone_utils = api.portal.get_tool(name='plone_utils')
friendly_types = plone_utils.getUserFriendlyTypes()
blog_types = set(friendly_types) - set(BLOG_BLACKLISTED_TYPES)
return tuple(blog_types)
def __call__(self):
return self.index()
class BlogHeader(ViewletBase):
"""A viewlet to include a header in the container (Blog) and contained
(News Article) elements.
"""
def update(self):
""" check if we are inside a Blog, if its true
set it into self.blog
"""
self.context = aq_inner(self.context)
self.blog = None
# is context a Blog or inside a Blog?
for ob in self.context.aq_chain:
if ISiteRoot.providedBy(ob):
break
if IBlog.providedBy(ob):
self.blog = ob
break
def available(self):
"""Check if we're inside a Blog."""
return bool(self.blog)
def blog_url(self):
"""Return the blog URL."""
return self.blog.absolute_url()