Skip to content

Commit

Permalink
Remove needless "subjects" field from content types
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed Jun 14, 2018
1 parent 70ef7da commit cd65f26
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 130 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Changelog
[hvelarde]

- Corrige tratamento de fuso horário na view padrão do tipo de conteúdo ``AgendaDiaria``;
- 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>`_.
[hvelarde]

- Corrije tratamento de fuso horário na view padrão do tipo de conteúdo ``AgendaDiaria``;
isso evita mudanças na hora dos compromissos em browsers com um fuso horário diferente do vigente no Brasil.
[rodfersou, hvelarde]

Expand Down
10 changes: 0 additions & 10 deletions src/brasil/gov/agenda/content/agenda.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
# -*- 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: 0 additions & 17 deletions src/brasil/gov/agenda/content/agendadiaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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 @@ -93,14 +92,6 @@ 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 @@ -117,14 +108,6 @@ 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
17 changes: 0 additions & 17 deletions src/brasil/gov/agenda/content/compromisso.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from brasil.gov.agenda.interfaces import ICompromisso
from DateTime import DateTime
from plone.dexterity.content import Container
from plone.dexterity.utils import safe_utf8
from plone.indexer.decorator import indexer
from Products.CMFPlone.utils import safe_hasattr
from zope.interface import implementer
Expand Down Expand Up @@ -39,14 +38,6 @@ 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(IContextAwareDefaultFactory)
def default_start_date(context):
if IAgendaDiaria.providedBy(context):
Expand Down Expand Up @@ -85,14 +76,6 @@ def end_date(obj):
return DateTime(ICompromisso(obj).end_date)


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


@indexer(ICompromisso)
def exclude_from_nav(obj):
# Compromissos sempre serao ocultos da navegacao
Expand Down
9 changes: 1 addition & 8 deletions src/brasil/gov/agenda/content/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
<configure
xmlns="http://namespaces.zope.org/zope"
i18n_domain="brasil.gov.agenda">

<adapter name="Subject" factory=".agenda.tags" />
<configure xmlns="http://namespaces.zope.org/zope">

<adapter name="start" factory=".compromisso.start_date" />
<adapter name="end" factory=".compromisso.end_date" />
<adapter name="exclude_from_nav" factory=".compromisso.exclude_from_nav" />
<adapter name="Subject" factory=".compromisso.tags" />


<adapter name="start" factory=".agendadiaria.start_date" />
<adapter name="end" factory=".agendadiaria.end_date" />
<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: 0 additions & 10 deletions src/brasil/gov/agenda/content/schema/Agenda.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,5 @@
<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: 0 additions & 11 deletions src/brasil/gov/agenda/content/schema/AgendaDiaria.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,5 @@
<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>
11 changes: 0 additions & 11 deletions src/brasil/gov/agenda/content/schema/Compromisso.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,5 @@
<defaultFactory>brasil.gov.agenda.content.compromisso.default_location</defaultFactory>
<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>
<defaultFactory>brasil.gov.agenda.content.compromisso.default_subjects</defaultFactory>
<title>Tags</title>
<value_type type="zope.schema.TextLine">
<title>Tag</title>
</value_type>
</field>
</schema>
</model>
10 changes: 0 additions & 10 deletions src/brasil/gov/agenda/tests/test_agenda.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ 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
self.agenda.invokeFactory('AgendaDiaria', '2013-10-17')
Expand Down
18 changes: 0 additions & 18 deletions src/brasil/gov/agenda/tests/test_agendadiaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,6 @@ 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
18 changes: 0 additions & 18 deletions src/brasil/gov/agenda/tests/test_compromisso.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,6 @@ def test_exclude_from_nav(self):
def test_exclude_from_nav_behavior(self):
self.assertFalse(IExcludeFromNavigation.providedBy(self.compromisso))

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

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

def test_default_start_date(self):
from brasil.gov.agenda.content.compromisso import default_start_date
date_fmt = '%Y-%m-%d %H:%M'
Expand Down

0 comments on commit cd65f26

Please sign in to comment.