Skip to content

Commit

Permalink
Exercício 32 - Cargo
Browse files Browse the repository at this point in the history
  • Loading branch information
jadirj committed Oct 14, 2024
1 parent fb71ab1 commit 1b25470
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
8 changes: 8 additions & 0 deletions backend/src/trepr/intranet/content/pessoa.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from plone.dexterity.content import Container
from plone.supermodel import model
from trepr.intranet import _
from zope import schema
from zope.interface import implementer


class IPessoa(model.Schema):
"""Definição de uma Pessoa."""

cargo = schema.Choice(
title=_("Cargo"),
vocabulary="trepr.intranet.vocabulary.cargos",
required=False,
)


@implementer(IPessoa)
class Pessoa(Container):
Expand Down
19 changes: 19 additions & 0 deletions backend/src/trepr/intranet/vocabularies/cargos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from zope.interface import provider
from zope.schema.interfaces import IVocabularyFactory
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary


OPCOES = [
("servidor", "Servidor"),
("terceiro", "Tercerizado"),
]


@provider(IVocabularyFactory)
def vocab_cargos(context) -> SimpleVocabulary:
"""Cargos da estrutura do TRE-PR."""
terms = []
for token, title in OPCOES:
terms.append(SimpleTerm(token, token, title))
return SimpleVocabulary(terms)
4 changes: 4 additions & 0 deletions backend/src/trepr/intranet/vocabularies/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
name="trepr.intranet.vocabulary.estados"
component=".estados.vocab_estados"
/>
<utility
name="trepr.intranet.vocabulary.cargos"
component=".cargos.vocab_cargos"
/>
</configure>
28 changes: 28 additions & 0 deletions backend/tests/vocabularies/test_voc_cargos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from trepr.intranet import PACKAGE_NAME
from zope.schema.vocabulary import SimpleVocabulary

import pytest


class TestVocabCargos:
name = f"{PACKAGE_NAME}.vocabulary.cargos"

@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,title",
[
["servidor", "Servidor"],
["terceiro", "Terceirizado"],
],
)
def test_term(self, token, title):
term = self.vocab.getTermByToken(token)
assert term is not None
assert term.title == title
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgstr ""
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language: de\n"
"Language: \n"
"Language-Team: \n"
"Content-Type: \n"
"Content-Transfer-Encoding: \n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const PessoaView = (props) => {
/>
</Container>
)}
{content.cargo && (
<span className={`cargo cargo-${content.cargo.token}`}>
{content.cargo.title}
</span>
)}
<h1 className="documentFirstHeading">{content.title}</h1>
{content.description && (
<p className="documentDescription">{content.description}</p>
Expand Down

0 comments on commit 1b25470

Please sign in to comment.