Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 5 - Remove dependency on five.grok #22

Merged
merged 1 commit into from
May 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
1.1b2 (unreleased)
------------------

- Remove dependency on five.grok (closes `#5`_).
[rodfersou]

- Package is now compatible with Plone 5.
[hvelarde]

Expand Down Expand Up @@ -95,6 +98,7 @@ Changelog
- Initial release.

.. _`#3`: https://github.com/collective/collective.liveblog/issues/3
.. _`#5`: https://github.com/collective/collective.liveblog/issues/5
.. _`#6`: https://github.com/collective/collective.liveblog/issues/6
.. _`#7`: https://github.com/collective/collective.liveblog/issues/7
.. _`#10`: https://github.com/collective/collective.liveblog/issues/10
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@
include_package_data=True,
zip_safe=False,
install_requires=[
'five.grok',
'plone.api',
'plone.app.dexterity [grok]',
'plone.app.dexterity',
'plone.app.layout',
'plone.batching',
'plone.dexterity',
'plone.directives.form',
'plone.memoize',
'plone.namedfile [blobs]',
'Products.CMFPlone >=4.3',
Expand Down
37 changes: 37 additions & 0 deletions src/collective/liveblog/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,41 @@
layer="collective.liveblog.interfaces.IBrowserLayer"
/>

<browser:page
for="collective.liveblog.interfaces.ILiveblog"
name="view"
class="collective.liveblog.browser.view.View"
permission="zope2.View"
layer="collective.liveblog.interfaces.IBrowserLayer"
template="templates/view.pt"
/>

<browser:page
for="collective.liveblog.interfaces.ILiveblog"
name="update"
class="collective.liveblog.browser.update.Update"
permission="collective.liveblog.AddMicroUpdate"
layer="collective.liveblog.interfaces.IBrowserLayer"
template="templates/update.pt"
/>

<browser:page
for="collective.liveblog.interfaces.ILiveblog"
name="recent-updates"
class="collective.liveblog.browser.recent_updates.RecentUpdates"
permission="zope2.View"
layer="collective.liveblog.interfaces.IBrowserLayer"
template="templates/recent_updates.pt"
/>

<browser:viewlet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're missing here the for directive

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

for="collective.liveblog.interfaces.ILiveblog"
name="collective.liveblog.header"
manager="plone.app.layout.viewlets.interfaces.IAboveContent"
class=".header.Header"
permission="zope2.View"
template="templates/header.pt"
layer="..interfaces.IBrowserLayer"
/>

</configure>
15 changes: 2 additions & 13 deletions src/collective/liveblog/browser/header.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
# -*- coding: utf-8 -*-
from five import grok
from plone.app.layout.viewlets.interfaces import IAboveContent
from collective.liveblog.interfaces import ILiveblog
from collective.liveblog.interfaces import IBrowserLayer
from plone.app.layout.viewlets.common import ViewletBase

grok.templatedir('templates')


class Header(grok.Viewlet):
class Header(ViewletBase):

"""A viewlet to include a header in the Liveblog."""

grok.name('collective.liveblog.header')
grok.context(ILiveblog)
grok.layer(IBrowserLayer)
grok.require('zope2.View')
grok.viewletmanager(IAboveContent)

def available(self):
"""Return True if an image has been defined."""
return self.context.image is not None
15 changes: 2 additions & 13 deletions src/collective/liveblog/browser/recent_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,19 @@
from App.Common import rfc1123_date
from collective.liveblog.browser.base import BaseView
from collective.liveblog.config import PROJECTNAME
from collective.liveblog.interfaces import IBrowserLayer
from collective.liveblog.interfaces import ILiveblog
from datetime import datetime
from five import grok
# from plone.memoize import ram
from time import time
from zope.publisher.browser import BrowserView

import logging

logger = logging.getLogger(PROJECTNAME)

grok.templatedir('templates')


class RecentUpdates(grok.View, BaseView):
class RecentUpdates(BrowserView, BaseView):

"""Helper view for Liveblog."""

grok.context(ILiveblog)
grok.layer(IBrowserLayer)
grok.name('recent-updates')
grok.require('zope2.View')
grok.template('recent_updates')

def _needs_hard_refresh(self):
"""Return True if a hard refresh of the page is needed.

Expand Down
4 changes: 2 additions & 2 deletions src/collective/liveblog/browser/templates/header.pt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
i18n:domain="collective.liveblog"
tal:omit-tag="">
<body tal:omit-tag="">
<tal:viewlet condition="viewlet/available">
<tal:viewlet condition="view/available">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure we need this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't want to raise an exception, yes

<div id="liveblog-header">
<img tal:define="scale context/@@images"
tal:replace="structure python:scale.scale('image').tag()" />
</div>
</tal:viewlet>
</body>
</html>
</html>
23 changes: 7 additions & 16 deletions src/collective/liveblog/browser/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,16 @@
from collective.liveblog.browser.view import View
from collective.liveblog.config import BATCH_SIZE
from collective.liveblog.config import ORPHAN
from collective.liveblog.interfaces import IBrowserLayer
from collective.liveblog.interfaces import ILiveblog
from five import grok
from plone import api
from plone.batching import Batch
from zope.i18n import translate
from zope.security import checkPermission


grok.templatedir('templates')


class Update(View):

"""View to add micro-updates to a Liveblog."""

grok.context(ILiveblog)
grok.layer(IBrowserLayer)
grok.require('collective.liveblog.AddMicroUpdate')

def update(self):
self.start = int(self.request.get('b_start', 0))
if self.start != 0:
msg = _(u'You must be on the first page of the batch to add micro-updates.')
api.portal.show_message(msg, self.request, type='info')

@property
def batch(self):
"""Encapsulate sequence in batches of size."""
Expand All @@ -52,3 +36,10 @@ def automatic_updates_enabled(self):
"""
enabled = super(Update, self).automatic_updates_enabled
return enabled and self.start == 0

def __call__(self):
self.start = int(self.request.get('b_start', 0))
if self.start != 0:
msg = _(u'You must be on the first page of the batch to add micro-updates.')
api.portal.show_message(msg, self.request, type='info')
return self.index()
12 changes: 2 additions & 10 deletions src/collective/liveblog/browser/view.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
# -*- coding: utf-8 -*-
from collective.liveblog.browser.base import BaseView
from collective.liveblog.interfaces import IBrowserLayer
from collective.liveblog.interfaces import ILiveblog
from five import grok
from plone import api
from plone.memoize import ram
from time import time

grok.templatedir('templates')
from zope.publisher.browser import BrowserView


def _updates_cachekey(method, self):
return (self.context.absolute_url_path(), int(self.context.modified()))


class View(grok.View, BaseView):
class View(BrowserView, BaseView):

"""Default view for Liveblog."""

grok.context(ILiveblog)
grok.layer(IBrowserLayer)
grok.require('zope2.View')

@ram.cache(_updates_cachekey)
def updates(self):
"""Return the list of micro-updates in the Liveblog in reverse order;
Expand Down
4 changes: 0 additions & 4 deletions src/collective/liveblog/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:five="http://namespaces.zope.org/five"
xmlns:grok="http://namespaces.zope.org/grok"
xmlns:i18n="http://namespaces.zope.org/i18n"
i18n_domain="collective.liveblog">

<i18n:registerTranslations directory="locales" />
<five:registerPackage package="." />

<include package="five.grok" />
<include package="plone.app.dexterity" />

<include package=".caching" />
Expand All @@ -24,8 +22,6 @@
title="collective.liveblog: Add MicroUpdate"
/>

<grok:grok package="." />

<include file="profiles.zcml" />

<browser:resourceDirectory name="collective.liveblog" directory="static" />
Expand Down
5 changes: 2 additions & 3 deletions src/collective/liveblog/content.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
from collective.liveblog.adapters import IMicroUpdateContainer
from collective.liveblog.interfaces import ILiveblog
from five import grok
from plone import api
from plone.dexterity.content import Container
from zope.interface import implementer


@implementer(ILiveblog)
class Liveblog(Container):

"""A liveblog is a blog post which is intended to provide a rolling
Expand All @@ -15,8 +16,6 @@ class Liveblog(Container):
are used to detect if a hard refresh of the views is needed.
"""

grok.implements(ILiveblog)

_last_microupdate_edition = '0.0'
_last_microupdate_deletion = '0.0'

Expand Down
3 changes: 1 addition & 2 deletions src/collective/liveblog/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from collective.liveblog import _
from plone.directives import form
from plone.namedfile.field import NamedBlobImage
from zope.interface import Interface

Expand All @@ -10,7 +9,7 @@ class IBrowserLayer(Interface):
"""A layer specific for this add-on product."""


class ILiveblog(form.Schema):
class ILiveblog(Interface):

"""A liveblog is a blog post which is intended to provide a rolling
textual coverage of an ongoing event.
Expand Down