From 6d972eb1cd8ad361f6bd2f5ae33ba8b030c45b4c Mon Sep 17 00:00:00 2001 From: Rodrigo Ferreira de Souza Date: Wed, 15 Feb 2017 23:19:09 -0200 Subject: [PATCH] Fix view when plone.app.contenttypes is installed --- CHANGES.rst | 4 ++++ src/sc/blog/browser/blog.py | 25 +++++++++++++------------ src/sc/blog/browser/configure.zcml | 4 +++- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index f9ea4cb..df93504 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,9 @@ There's a frood who really knows where his towel is. 1.0b4 (unreleased) ^^^^^^^^^^^^^^^^^^ +- Fix view when plone.app.contenttypes is installed (closes `#16`_). + [rodfersou] + - Remove dependency on five.grok (closes `#11`_). [rodfersou] @@ -92,3 +95,4 @@ There's a frood who really knows where his towel is. .. _`#7`: https://github.com/simplesconsultoria/sc.blog/issues/7 .. _`#9`: https://github.com/simplesconsultoria/sc.blog/issues/9 .. _`#11`: https://github.com/simplesconsultoria/sc.blog/issues/11 +.. _`#16`: https://github.com/simplesconsultoria/sc.blog/issues/16 diff --git a/src/sc/blog/browser/blog.py b/src/sc/blog/browser/blog.py index 533f75f..59bf559 100644 --- a/src/sc/blog/browser/blog.py +++ b/src/sc/blog/browser/blog.py @@ -3,13 +3,24 @@ from plone import api from plone.app.layout.viewlets import ViewletBase from Products.CMFCore.interfaces import ISiteRoot -from Products.Five.browser import BrowserView from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from sc.blog.config import BLOG_BLACKLISTED_TYPES from sc.blog.content import IBlog +import pkg_resources -class View(BrowserView): + +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.""" @@ -31,16 +42,6 @@ def __call__(self): return self.index() -class BlogSummaryView(View): - - """Looks like a standard Folder Summary View.""" - - index = ViewPageTemplateFile('templates/folder_summary_view.pt') - - def __call__(self): - return self.index() - - class BlogHeader(ViewletBase): """A viewlet to include a header in the container (Blog) and contained diff --git a/src/sc/blog/browser/configure.zcml b/src/sc/blog/browser/configure.zcml index e23cb91..ed7fb10 100644 --- a/src/sc/blog/browser/configure.zcml +++ b/src/sc/blog/browser/configure.zcml @@ -9,6 +9,7 @@ for="..content.IBlog" name="view" class=".blog.View" + template="templates/folder_full_view.pt" permission="zope2.View" layer="..interfaces.IBlogLayer" /> @@ -16,7 +17,8 @@