From fd2a45f120722aa4488bcdb7babf6b661ee4556f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Velarde?= Date: Wed, 13 Jun 2018 10:06:43 -0300 Subject: [PATCH] Remove dependency on five.grok (#79) * Remove dependency on five.grok * Remove dependency on plone.directives.form * Fix browser views and tests * Fix changelog --- CHANGES.rst | 3 ++ setup.py | 4 +- src/brasil/gov/agenda/browser/__init__.py | 5 ++ src/brasil/gov/agenda/browser/agenda.py | 14 ++---- src/brasil/gov/agenda/browser/agendadiaria.py | 20 ++++---- src/brasil/gov/agenda/browser/compromisso.py | 20 ++++---- src/brasil/gov/agenda/browser/configure.zcml | 46 +++++++++++++++++-- src/brasil/gov/agenda/browser/ics.py | 18 ++------ src/brasil/gov/agenda/browser/vcs.py | 18 ++------ src/brasil/gov/agenda/configure.zcml | 3 -- .../gov/agenda/tests/test_agendadiaria.py | 8 ++-- .../gov/agenda/tests/test_compromisso.py | 4 +- src/brasil/gov/agenda/tests/test_setup.py | 15 ------ src/brasil/gov/agenda/tiles/agenda.py | 2 +- 14 files changed, 88 insertions(+), 92 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 833675d..653384c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,9 @@ Changelog 2.0a2 (unreleased) ^^^^^^^^^^^^^^^^^^ +- Remove dependência no five.grok. + [hvelarde] + - Remove atalhos para adicionar agendas diárias e compromissos. [hvelarde] diff --git a/setup.py b/setup.py index 8172432..13ed262 100644 --- a/setup.py +++ b/setup.py @@ -46,7 +46,7 @@ 'plone.api', 'plone.app.content', 'plone.app.contenttypes', - 'plone.app.dexterity [grok]', + 'plone.app.dexterity', 'plone.app.portlets', 'plone.app.referenceablebehavior', 'plone.app.textfield', @@ -54,9 +54,9 @@ 'plone.app.uuid', 'plone.app.versioningbehavior', 'plone.app.vocabularies', + 'plone.autoform', 'plone.behavior', 'plone.dexterity', - 'plone.directives.form', 'plone.indexer', 'plone.memoize', 'plone.portlets', diff --git a/src/brasil/gov/agenda/browser/__init__.py b/src/brasil/gov/agenda/browser/__init__.py index 40a96af..67651d9 100644 --- a/src/brasil/gov/agenda/browser/__init__.py +++ b/src/brasil/gov/agenda/browser/__init__.py @@ -1 +1,6 @@ # -*- coding: utf-8 -*- +from brasil.gov.agenda.browser.agenda import AgendaView # noqa: F401 +from brasil.gov.agenda.browser.agendadiaria import AgendaDiariaView # noqa: E501,F401 +from brasil.gov.agenda.browser.compromisso import CompromissoView # noqa: E501,F401 +from brasil.gov.agenda.browser.ics import ICSView # noqa: F401 +from brasil.gov.agenda.browser.vcs import VCSView # noqa: F401 diff --git a/src/brasil/gov/agenda/browser/agenda.py b/src/brasil/gov/agenda/browser/agenda.py index c9bc3b8..6a0635f 100644 --- a/src/brasil/gov/agenda/browser/agenda.py +++ b/src/brasil/gov/agenda/browser/agenda.py @@ -1,25 +1,17 @@ # -*- coding: utf-8 -*- from brasil.gov.agenda import _ from brasil.gov.agenda.config import AGENDADIARIAFMT -from brasil.gov.agenda.interfaces import IAgenda from brasil.gov.agenda.utils import AgendaMixin from DateTime import DateTime -from five import grok from Products.CMFCore.utils import getToolByName +from Products.Five.browser import BrowserView from zope.component import getMultiAdapter from zope.i18nmessageid import Message from zope.publisher.publish import mapply -grok.templatedir('templates') - - -class AgendaView (grok.View, AgendaMixin): - """ Visao padrao da agenda - """ - - grok.name('view') - grok.context(IAgenda) +class AgendaView(BrowserView, AgendaMixin): + """Visao padrao da agenda.""" def update(self): plone_tools = getMultiAdapter((self.context, self.request), diff --git a/src/brasil/gov/agenda/browser/agendadiaria.py b/src/brasil/gov/agenda/browser/agendadiaria.py index 8bf4858..61a9861 100644 --- a/src/brasil/gov/agenda/browser/agendadiaria.py +++ b/src/brasil/gov/agenda/browser/agendadiaria.py @@ -1,26 +1,18 @@ # -*- coding: utf-8 -*- from Acquisition import aq_parent from brasil.gov.agenda import _ -from brasil.gov.agenda.interfaces import IAgendaDiaria from brasil.gov.agenda.utils import AgendaMixin from datetime import datetime -from five import grok from Products.CMFCore.utils import getToolByName +from Products.Five.browser import BrowserView from zope.component import getMultiAdapter from zope.i18nmessageid import Message -grok.templatedir('templates') +class AgendaDiariaView(BrowserView, AgendaMixin): + """Visao padrao da agenda.""" - -class AgendaDiariaView (grok.View, AgendaMixin): - """ Visao padrao da agenda - """ - - grok.name('view') - grok.context(IAgendaDiaria) - - def update(self): + def setup(self): plone_tools = getMultiAdapter((self.context, self.request), name='plone_tools') context_state = getMultiAdapter((self.context, self.request), @@ -37,6 +29,10 @@ def update(self): self.date.month, self.date.year) return self.context.REQUEST.RESPONSE.redirect(url) + def __call__(self): + self.setup() + return self.index() + def _format_time(self, value): return value.strftime('%Hh%M') diff --git a/src/brasil/gov/agenda/browser/compromisso.py b/src/brasil/gov/agenda/browser/compromisso.py index 096c277..97d4f5d 100644 --- a/src/brasil/gov/agenda/browser/compromisso.py +++ b/src/brasil/gov/agenda/browser/compromisso.py @@ -1,24 +1,16 @@ # -*- coding: utf-8 -*- - from Acquisition import aq_parent from brasil.gov.agenda import _ -from brasil.gov.agenda.interfaces import ICompromisso -from five import grok from Products.CMFCore.utils import getToolByName +from Products.Five.browser import BrowserView from zope.component import getMultiAdapter from zope.i18nmessageid import Message -grok.templatedir('templates') - +class CompromissoView(BrowserView): + """Visao padrao do tipo compromisso.""" -class CompromissoView (grok.View): - """ Visao padrao do tipo compromisso - """ - grok.name('view') - grok.context(ICompromisso) - - def update(self): + def setup(self): self._ts = getToolByName(self.context, 'translation_service') context_state = getMultiAdapter((self.context, self.request), name=u'plone_context_state') @@ -39,6 +31,10 @@ def update(self): self.date.month, self.date.year) return self.context.REQUEST.RESPONSE.redirect(url) + def __call__(self): + self.setup() + return self.index() + def _format_time(self, value): return value.strftime('%Hh%M') diff --git a/src/brasil/gov/agenda/browser/configure.zcml b/src/brasil/gov/agenda/browser/configure.zcml index a404340..7b0eac9 100644 --- a/src/brasil/gov/agenda/browser/configure.zcml +++ b/src/brasil/gov/agenda/browser/configure.zcml @@ -1,12 +1,50 @@ - + - + + + + + + + diff --git a/src/brasil/gov/agenda/browser/ics.py b/src/brasil/gov/agenda/browser/ics.py index d8fcdae..2ae56dc 100644 --- a/src/brasil/gov/agenda/browser/ics.py +++ b/src/brasil/gov/agenda/browser/ics.py @@ -1,15 +1,13 @@ # -*- coding: utf-8 -*- - from brasil.gov.agenda.config import PROJECTNAME -from brasil.gov.agenda.interfaces import ICompromisso from brasil.gov.agenda.utils import rfc2445dt from cStringIO import StringIO from DateTime import DateTime -from five import grok from plone.uuid.interfaces import IUUID from Products.ATContentTypes.lib.calendarsupport import foldLine from Products.ATContentTypes.lib.calendarsupport import n2rn from Products.ATContentTypes.lib.calendarsupport import vformat +from Products.Five.browser import BrowserView # iCal header and footer @@ -42,15 +40,11 @@ """ -class ICSView (grok.View): - """ Visao vCal - """ - grok.name('ical_view') - grok.context(ICompromisso) +class ICSView(BrowserView): + """ICS view.""" def getICal(self): - """get iCal data - """ + """Get iCal data.""" context = self.context out = StringIO() map = { @@ -87,9 +81,7 @@ def getICal(self): out.write(ICS_EVENT_END) return out.getvalue() - def render(self): - """vCalendar output - """ + def __call__(self): response = self.request.response response.setHeader('Content-Type', 'text/calendar') response.setHeader('Content-Disposition', diff --git a/src/brasil/gov/agenda/browser/vcs.py b/src/brasil/gov/agenda/browser/vcs.py index 22b113d..21c1a98 100644 --- a/src/brasil/gov/agenda/browser/vcs.py +++ b/src/brasil/gov/agenda/browser/vcs.py @@ -1,15 +1,13 @@ # -*- coding: utf-8 -*- - from brasil.gov.agenda.config import PROJECTNAME -from brasil.gov.agenda.interfaces import ICompromisso from brasil.gov.agenda.utils import rfc2445dt from cStringIO import StringIO from DateTime import DateTime -from five import grok from plone.uuid.interfaces import IUUID from Products.ATContentTypes.lib.calendarsupport import foldLine from Products.ATContentTypes.lib.calendarsupport import n2rn from Products.ATContentTypes.lib.calendarsupport import vformat +from Products.Five.browser import BrowserView # vCal header and footer @@ -42,15 +40,11 @@ """ -class VCSView (grok.View): - """ Visao vCal - """ - grok.name('vcal_view') - grok.context(ICompromisso) +class VCSView(BrowserView): + """VCS view.""" def getVCal(self): - """get vCal data - """ + """Get vCal data.""" context = self.context out = StringIO() map = { @@ -73,9 +67,7 @@ def getVCal(self): out.write(VCS_EVENT_END) return out.getvalue() - def render(self): - """vCalendar output - """ + def __call__(self): response = self.request.response response.setHeader('Content-Type', 'text/x-vCalendar') response.setHeader('Content-Disposition', diff --git a/src/brasil/gov/agenda/configure.zcml b/src/brasil/gov/agenda/configure.zcml index 3db9203..2eb220f 100644 --- a/src/brasil/gov/agenda/configure.zcml +++ b/src/brasil/gov/agenda/configure.zcml @@ -2,7 +2,6 @@ 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" xmlns:zcml="http://namespaces.zope.org/zcml" i18n_domain="brasil.gov.agenda"> @@ -37,8 +36,6 @@ package=".subscribers" /> - - diff --git a/src/brasil/gov/agenda/tests/test_agendadiaria.py b/src/brasil/gov/agenda/tests/test_agendadiaria.py index ac7e3d2..78f128a 100644 --- a/src/brasil/gov/agenda/tests/test_agendadiaria.py +++ b/src/brasil/gov/agenda/tests/test_agendadiaria.py @@ -263,7 +263,7 @@ def test_view_sem_compromissos(self): agendadiaria = self.agendadiaria view = agendadiaria.restrictedTraverse('@@view') # AgendaDiaria sem compromissos e sem nada no campo atualizacao - view.update() + view.setup() sem_compromissos = view.exibe_sem_compromissos() self.assertTrue(sem_compromissos) @@ -272,7 +272,7 @@ def test_view_sem_compromissos(self): 'text/html', 'text/x-html-safe', encoding='utf-8') - view.update() + view.setup() sem_compromissos = view.exibe_sem_compromissos() self.assertFalse(sem_compromissos) @@ -288,7 +288,7 @@ def test_view_sem_compromissos(self): reuniao.location = u'Palacio do Planalto' reuniao.attendees = u'Mario de Andrade\nTarsila do Amaral' reuniao.reindexObject() - view.update() + view.setup() sem_compromissos = view.exibe_sem_compromissos() self.assertFalse(sem_compromissos) @@ -305,7 +305,7 @@ def test_agendadiaria_icon(self): def test_agendadiaria_view_imagem(self): view = self.agendadiaria.restrictedTraverse('@@view') - view.update() + view.setup() self.assertIn(u'