Skip to content

Commit

Permalink
Exercício 28: Vocabulário de estados
Browse files Browse the repository at this point in the history
  • Loading branch information
jadirj committed Oct 11, 2024
1 parent a18204b commit 9c1dd57
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
3 changes: 2 additions & 1 deletion backend/src/trepr/intranet/content/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ class IArea(model.Schema):
required=False,
)

estado = schema.TextLine(
estado = schema.Choice(
title=_("Estado"),
vocabulary="trepr.intranet.vocabulary.estados",
required=False,
)

Expand Down
5 changes: 4 additions & 1 deletion backend/src/trepr/intranet/vocabularies/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<configure xmlns="http://namespaces.zope.org/zope">

<utility
name="trepr.intranet.vocabulary.estados"
component=".estados.vocab_estados"
/>
</configure>
45 changes: 45 additions & 0 deletions backend/src/trepr/intranet/vocabularies/estados.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from trepr.intranet import _
from zope.interface import provider
from zope.schema.interfaces import IVocabularyFactory
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary


OPCOES = [
("AC", _("Acre")),
("AL", _("Alagoas")),
("AP", _("Amapá")),
("AM", _("Amazonas")),
("BA", _("Bahia")),
("CE", _("Ceará")),
("DF", _("Distrito Federal")),
("ES", _("Espírito Santo")),
("GO", _("Goiás")),
("MA", _("Maranhão")),
("MT", _("Mato Grosso")),
("MS", _("Mato Grosso do Sul")),
("MG", _("Minas Gerais")),
("PA", _("Pará")),
("PB", _("Paraíba")),
("PR", _("Paraná")),
("PE", _("Pernambuco")),
("PI", _("Piauí")),
("RJ", _("Rio de Janeiro")),
("RN", _("Rio Grande do Norte")),
("RS", _("Rio Grande do Sul")),
("RO", _("Rondônia")),
("RR", _("Roraima")),
("SC", _("Santa Catarina")),
("SP", _("São Paulo")),
("SE", _("Sergipe")),
("TO", _("Tocantins")),
]


@provider(IVocabularyFactory)
def vocab_estados(context) -> SimpleVocabulary:
"""Estados do Brasil."""
terms = []
for token, title in OPCOES:
terms.append(SimpleTerm(token, token, title))
return SimpleVocabulary(terms)
23 changes: 23 additions & 0 deletions backend/tests/vocabularies/test_voc_estados.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from trepr.intranet import PACKAGE_NAME
from zope.schema.vocabulary import SimpleVocabulary

import pytest


class TestVocabEstados:
name = f"{PACKAGE_NAME}.vocabulary.estados"

@pytest.fixture(autouse=True)
def _vocab(self, get_vocabulary, portal):
self.vocab = get_vocabulary(self.name, portal)

def test_vocabulary(self):
assert self.vocab is not None
assert isinstance(self.vocab, SimpleVocabulary)

@pytest.mark.parametrize(
"token",
["PR", "SP", "DF"],
)
def test_token(self, token):
assert token in [x for x in self.vocab.by_token]
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const EnderecoInfo = ({ content }) => {
<span>Cidade</span>: <span>{cidade}</span>
</Container>
<Container className="email">
<span>Estado</span>: <span>{estado}</span>
<span>Estado</span>: <span>{estado.token}</span>
</Container>
<Container className="email">
<span>CEP</span>: <span>{cep}</span>
Expand Down

0 comments on commit 9c1dd57

Please sign in to comment.