Skip to content

Commit

Permalink
Remove dependency on five.grok (#79)
Browse files Browse the repository at this point in the history
* Remove dependency on five.grok

* Remove dependency on plone.directives.form

* Fix browser views and tests

* Fix changelog
  • Loading branch information
hvelarde authored Jun 13, 2018
1 parent 240bf75 commit fd2a45f
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 92 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@
'plone.api',
'plone.app.content',
'plone.app.contenttypes',
'plone.app.dexterity [grok]',
'plone.app.dexterity',
'plone.app.portlets',
'plone.app.referenceablebehavior',
'plone.app.textfield',
'plone.app.upgrade',
'plone.app.uuid',
'plone.app.versioningbehavior',
'plone.app.vocabularies',
'plone.autoform',
'plone.behavior',
'plone.dexterity',
'plone.directives.form',
'plone.indexer',
'plone.memoize',
'plone.portlets',
Expand Down
5 changes: 5 additions & 0 deletions src/brasil/gov/agenda/browser/__init__.py
Original file line number Diff line number Diff line change
@@ -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
14 changes: 3 additions & 11 deletions src/brasil/gov/agenda/browser/agenda.py
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
20 changes: 8 additions & 12 deletions src/brasil/gov/agenda/browser/agendadiaria.py
Original file line number Diff line number Diff line change
@@ -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),
Expand All @@ -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')

Expand Down
20 changes: 8 additions & 12 deletions src/brasil/gov/agenda/browser/compromisso.py
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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')

Expand Down
46 changes: 42 additions & 4 deletions src/brasil/gov/agenda/browser/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five"
xmlns:grok="http://namespaces.zope.org/grok"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:i18n="http://namespaces.zope.org/i18n"
i18n_domain="brasil.gov.agenda">

<five:registerPackage package="." />
<browser:page
for="brasil.gov.agenda.interfaces.IAgenda"
name="view"
class="brasil.gov.agenda.browser.AgendaView"
permission="zope2.View"
layer="brasil.gov.agenda.interfaces.IBrowserLayer"
template="templates/agendaview.pt"
/>

<grok:grok package="." />
<browser:page
for="brasil.gov.agenda.interfaces.IAgendaDiaria"
name="view"
class="brasil.gov.agenda.browser.AgendaDiariaView"
permission="zope2.View"
layer="brasil.gov.agenda.interfaces.IBrowserLayer"
template="templates/agendadiariaview.pt"
/>

<browser:page
for="brasil.gov.agenda.interfaces.ICompromisso"
name="view"
class="brasil.gov.agenda.browser.CompromissoView"
permission="zope2.View"
layer="brasil.gov.agenda.interfaces.IBrowserLayer"
template="templates/compromissoview.pt"
/>

<browser:page
for="brasil.gov.agenda.interfaces.ICompromisso"
name="ical_view"
class="brasil.gov.agenda.browser.ICSView"
permission="zope2.View"
layer="brasil.gov.agenda.interfaces.IBrowserLayer"
/>

<browser:page
for="brasil.gov.agenda.interfaces.ICompromisso"
name="vcal_view"
class="brasil.gov.agenda.browser.VCSView"
permission="zope2.View"
layer="brasil.gov.agenda.interfaces.IBrowserLayer"
/>

</configure>
18 changes: 5 additions & 13 deletions src/brasil/gov/agenda/browser/ics.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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',
Expand Down
18 changes: 5 additions & 13 deletions src/brasil/gov/agenda/browser/vcs.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -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',
Expand Down
3 changes: 0 additions & 3 deletions src/brasil/gov/agenda/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -37,8 +36,6 @@
package=".subscribers"
/>

<grok:grok package="." />

<!-- Suporte a arquivos estaticos -->
<browser:resourceDirectory name="brasil.gov.agenda" directory="static" />

Expand Down
8 changes: 4 additions & 4 deletions src/brasil/gov/agenda/tests/test_agendadiaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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'<img src="http://nohost/plone/test-folder/agenda/@@images/',
view.imagem())

Expand Down
4 changes: 2 additions & 2 deletions src/brasil/gov/agenda/tests/test_compromisso.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def test_compromisso_view_title(self):
portal = self.portal
self.setupContent(portal)
view = self.compromisso.restrictedTraverse('@@view')
view.update()
view.setup()
# FIXME: Correção do teste para não levar em consideração a língua
# para não quebrar o build após o rebase pedido em
# https://github.com/plonegovbr/brasil.gov.agenda/pull/38#issuecomment-88449501
Expand All @@ -283,7 +283,7 @@ def test_compromisso_view_imagem(self):
portal = self.portal
self.setupContent(portal)
view = self.compromisso.restrictedTraverse('@@view')
view.update()
view.setup()
self.assertIn(u'<img src="http://nohost/plone/agenda-presidente/@@images/',
view.imagem())

Expand Down
Loading

0 comments on commit fd2a45f

Please sign in to comment.