Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed Jul 3, 2018
1 parent bee56eb commit ea79e88
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Changelog
Esta versão inabilita o uso do portlet de Busca de Agenda.
Remova manualmente todos os portlets de Busca de Agenda antes de atualizar.

- Remove o campo ``subjects`` dos tipos de conteúdo ``Agenda``, ``AgendaDiaria`` e ``Compromisso`` por ser considerado `desnecessário <https://listas.interlegis.gov.br/pipermail/plonegov-br/2018-June/004767.html>`_.
- Remove o campo ``subjects`` do tipos de conteúdo ``Compromisso`` por ser considerado `desnecessário <https://listas.interlegis.gov.br/pipermail/plonegov-br/2018-June/004767.html>`_.
[hvelarde]

- Inabilita o uso do portlet de Busca de Agenda.
Expand Down
10 changes: 10 additions & 0 deletions src/brasil/gov/agenda/content/agenda.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# -*- coding: utf-8 -*-
from brasil.gov.agenda.interfaces import IAgenda
from plone.dexterity.content import Container
from plone.dexterity.utils import safe_utf8
from plone.indexer.decorator import indexer
from zope.interface import implementer


@implementer(IAgenda)
class Agenda(Container):
"""Agenda de um membro do Governo Brasileiro"""


@indexer(IAgenda)
def tags(obj):
"""Indexa tags de Agenda."""
if obj.subjects is None:
return ()
return tuple(safe_utf8(s) for s in obj.subjects)
17 changes: 17 additions & 0 deletions src/brasil/gov/agenda/content/agendadiaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from DateTime import DateTime
from plone import api
from plone.dexterity.content import Container
from plone.dexterity.utils import safe_utf8
from plone.indexer.decorator import indexer
from plone.supermodel.interfaces import IDefaultFactory
from Products.CMFPlone.utils import safe_hasattr
Expand Down Expand Up @@ -86,6 +87,14 @@ def default_location(context):
return getattr(context, 'location', u'')


@provider(IContextAwareDefaultFactory)
def default_subjects(context):
# XXX: deal with testing issues https://stackoverflow.com/q/35799092/644075
if not safe_hasattr(context, 'aq_parent'):
return ()
return getattr(context, 'subjects', ())


@provider(IDefaultFactory)
def default_date():
""" Retorna um dia no futuro """
Expand All @@ -102,6 +111,14 @@ def validate(self, value):
raise Invalid(_(u'Ja existe uma agenda para esta data'))


@indexer(IAgendaDiaria)
def tags(obj):
"""Indexa tags de AgendaDiaria."""
if obj.subjects is None:
return ()
return tuple(safe_utf8(s) for s in obj.subjects)


@indexer(IAgendaDiaria)
def SearchableText_AgendaDiaria(obj):
""" Indexa os dados dos compromissos dentro desta AgendaDiaria
Expand Down
3 changes: 3 additions & 0 deletions src/brasil/gov/agenda/content/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<configure xmlns="http://namespaces.zope.org/zope">

<adapter name="Subject" factory=".agenda.tags" />

<adapter name="start" factory=".compromisso.start_date" />
<adapter name="end" factory=".compromisso.end_date" />
<adapter name="exclude_from_nav" factory=".compromisso.exclude_from_nav" />
Expand All @@ -9,5 +11,6 @@
<adapter name="EffectiveDate" factory=".agendadiaria.EffectiveDate" />
<adapter name="exclude_from_nav" factory=".agendadiaria.exclude_from_nav" />
<adapter name="SearchableText" factory=".agendadiaria.SearchableText_AgendaDiaria" />
<adapter name="Subject" factory=".agendadiaria.tags" />

</configure>
10 changes: 10 additions & 0 deletions src/brasil/gov/agenda/content/schema/Agenda.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,15 @@
<required>False</required>
<title i18n:translate="label_event_location">Event Location</title>
</field>
<field name="subjects" type="zope.schema.Tuple" indexer:searchable="true">
<description i18n:translate="">Tags são utilizadas para organização de conteúdo</description>
<default_value>()</default_value>
<missing_value>()</missing_value>
<required>False</required>
<title>Tags</title>
<value_type type="zope.schema.TextLine">
<title>Tag</title>
</value_type>
</field>
</schema>
</model>
11 changes: 11 additions & 0 deletions src/brasil/gov/agenda/content/schema/AgendaDiaria.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,16 @@
<required>False</required>
<title i18n:translate="">Atualizacao</title>
</field>
<field name="subjects" type="zope.schema.Tuple" indexer:searchable="true">
<description i18n:translate="">Tags são utilizadas para organização de conteúdo</description>
<defaultFactory>brasil.gov.agenda.content.agendadiaria.default_subjects</defaultFactory>
<default_value>()</default_value>
<missing_value>()</missing_value>
<required>False</required>
<title>Tags</title>
<value_type type="zope.schema.TextLine">
<title>Tag</title>
</value_type>
</field>
</schema>
</model>
10 changes: 10 additions & 0 deletions src/brasil/gov/agenda/tests/test_agenda.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ def test_exclude_from_nav_default(self):
behavior = IExcludeFromNavigation(self.agenda)
self.assertFalse(behavior.exclude_from_nav)

def test_subjects_catalog(self):
agenda = self.agenda
agenda.subjects = (u'Brasil', u'México')
agenda.reindexObject(idxs=['Subject'])
ct = self.portal.portal_catalog
results = ct.searchResults(portal_type='Agenda')
b = results[0]
self.assertIn('Brasil', b.Subject)
self.assertIn('México', b.Subject)

def test_agendadiaria_ordering(self):
# Create two AgendaDiaria objects
api.content.create(container=self.agenda, type='AgendaDiaria', id='2013-10-17')
Expand Down
18 changes: 18 additions & 0 deletions src/brasil/gov/agenda/tests/test_agendadiaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ def test_exclude_from_nav(self):
def test_exclude_from_nav_behavior(self):
self.assertFalse(IExcludeFromNavigation.providedBy(self.agendadiaria))

def test_subjects_catalog(self):
agendadiaria = self.agendadiaria
agendadiaria.subjects = (u'Brasil', u'México')
agendadiaria.reindexObject(idxs=['Subject'])
ct = self.portal.portal_catalog
results = ct.searchResults(portal_type='AgendaDiaria')
b = results[0]
self.assertIn('Brasil', b.Subject)
self.assertIn('México', b.Subject)

def test_default_subjects(self):
from brasil.gov.agenda.content.agendadiaria import default_subjects
agenda = self.agenda
agenda.subjects = (u'Brasil', u'México')
# default_factory é executado no container
self.assertIn(u'Brasil', default_subjects(agenda))
self.assertIn(u'México', default_subjects(agenda))

def test_datevalidator(self):
from brasil.gov.agenda.content.agendadiaria import DateValidator
from zope.interface.exceptions import Invalid
Expand Down

0 comments on commit ea79e88

Please sign in to comment.