Skip to content

Commit

Permalink
behaviors para local e contato
Browse files Browse the repository at this point in the history
  • Loading branch information
samoel-silva committed Oct 17, 2024
1 parent 68ce179 commit 8b01797
Show file tree
Hide file tree
Showing 14 changed files with 425 additions and 5 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ repos:
- id: codespell
additional_dependencies:
- tomli
args: ["-L", "nome,comercial"]

##
# Add extra configuration options in .meta.toml:
Expand Down
15 changes: 13 additions & 2 deletions src/procergs/sitedemo/behaviors/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
xmlns:plone="http://namespaces.plone.org/plone"
>



<plone:behavior
name="procergs.sitedemo.behavior.informacoes_secretaria"
title="Informações da Secretaria"
description="Adiciona campos de informações de secretaria."
provides=".informacoes_secretaria.IInformacoesSecretaria"
/>

<plone:behavior
name="procergs.sitedemo.behavior.contato"
title="Informações de contato"
description="Adiciona campos de contato"
provides=".contato.IContato"
/>

<plone:behavior
name="procergs.sitedemo.behavior.local"
title="Informações de local"
description="Adiciona campos de local"
provides=".local.ILocal"
/>

</configure>
102 changes: 102 additions & 0 deletions src/procergs/sitedemo/behaviors/contato.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from plone.autoform import directives
from plone.autoform.interfaces import IFormFieldProvider
from plone.schema.email import Email
from plone.supermodel import model
from procergs.sitedemo import _
from procergs.sitedemo.utils import validadores
from zope import schema
from zope.interface import provider


@provider(IFormFieldProvider)
class IContato(model.Schema):
"""Provê campos de contato."""

model.fieldset(
"contato",
_("Contato"),
fields=[
"email",
"fax",
"telefone_fax",
"tel_comercial",
"tel_celular",
"voip",
"skype",
"whatsapp",
"url",
"horarios",
"link_whatsapp",
"telefones",
],
)

email = Email(
title=_("Email"),
required=False,
constraint=validadores.is_valid_email,
)
fax = schema.TextLine(
title="FAX",
required=False,
)
telefone_fax = schema.TextLine(
title="TEL/FAX",
required=False,
)
tel_comercial = schema.TextLine(
title="Telefone Comercial",
required=False,
)
tel_celular = schema.TextLine(
title="Telefone Celular",
required=False,
)
voip = schema.TextLine(
title="VOIP",
required=False,
)
skype = schema.TextLine(
title="Skype",
required=False,
)
whatsapp = schema.TextLine(
title="WhatsApp",
required=False,
)

directives.widget(
"url",
frontendOptions={
"format": "url",
},
)
url = schema.TextLine(
title="URL",
required=False,
)
horarios = schema.TextLine(
title="Horários de Atendimento",
required=False,
)
link_whatsapp = schema.TextLine(
title="Link WhatsApp",
required=False,
)

directives.widget(
"telefones",
frontendOptions={
"widget": "lista_telefones",
},
)
telefones = schema.List(
title="Telephone Numbers",
value_type=schema.TextLine(
title="Telefone",
constraint=validadores.is_valid_telefone,
),
required=False,
min_length=1,
max_length=5,
)
4 changes: 2 additions & 2 deletions src/procergs/sitedemo/behaviors/informacoes_secretaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class IInformacoesSecretaria(model.Schema):
)

nome_secretaria_vinculada = schema.TextLine(
title=_("Gnome da Secretaria Vinculada"),
description=_("Informe o gnome da secretaria vinculada"),
title=_("Nome da Secretaria Vinculada"),
description=_("Informe o nome da secretaria vinculada"),
required=False,
)

Expand Down
78 changes: 78 additions & 0 deletions src/procergs/sitedemo/behaviors/local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from plone.autoform.interfaces import IFormFieldProvider
from plone.supermodel import model
from procergs.sitedemo import _
from zope import schema
from zope.interface import provider


@provider(IFormFieldProvider)
class ILocal(model.Schema):
"""Provê campos de endereço."""

model.fieldset(
"local",
_("Local"),
fields=[
"logradouro",
"numero",
"complemento",
"bairro",
"municipio",
"municipio_id",
"estado",
"pais",
"cep",
"coordenadas",
],
)
logradouro = schema.TextLine(
title=_("Logradouro"),
required=False,
default="",
)
numero = schema.TextLine(
title=_("Número"),
required=False,
default="",
)
complemento = schema.TextLine(
title=_("Complemento"),
description=_("Bloco, Apartamento, etc"),
required=False,
default="",
)
bairro = schema.TextLine(
title=_("Bairro"),
required=False,
default="",
)
municipio = schema.TextLine(
title=_("Municipio"),
required=False,
default="",
)
municipio_id = schema.TextLine(
title=_("Municipio ID"),
required=False,
default="",
)
estado = schema.Choice(
title=_("UF"),
vocabulary="procergs.sitedemo.vocabulary.estados",
required=False,
)
pais = schema.TextLine(
title=_("Pais"),
required=False,
default="",
)
cep = schema.TextLine(
title=_("CEP"),
required=False,
default="",
)
coordenadas = schema.TextLine(
title=_("Coordenadas"),
required=False,
default="",
)
17 changes: 17 additions & 0 deletions src/procergs/sitedemo/profiles/default/types/Plone_Site.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<object xmlns:i18n="http://xml.zope.org/namespaces/i18n"
meta_type="Dexterity FTI"
name="Plone Site"
i18n:domain="plone"
>
<!-- Enabled behaviors -->
<property name="behaviors"
purge="false"
>
<element value="procergs.sitedemo.behavior.informacoes_secretaria" />
<element value="procergs.sitedemo.behavior.contato" />
<element value="procergs.sitedemo.behavior.local" />
</property>


</object>
2 changes: 2 additions & 0 deletions src/procergs/sitedemo/profiles/default/types/Secretaria.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<element value="plone.shortname" />
<element value="plone.excludefromnavigation" />
<element value="procergs.sitedemo.behavior.informacoes_secretaria" />
<element value="procergs.sitedemo.behavior.contato" />
<element value="procergs.sitedemo.behavior.local" />
<element value="volto.preview_image" />
<element value="plone.leadimage" />
<element value="plone.constraintypes" />
Expand Down
Empty file.
13 changes: 13 additions & 0 deletions src/procergs/sitedemo/utils/validadores.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import re


def is_valid_email(value: str) -> bool:
"""Validar se o email é @rs.gov.br."""
valid = value.endswith("rs.gov.br") if value else True
return valid


def is_valid_telefone(value: str) -> bool:
"""Validar se o telefone é válido."""
pattern = re.compile(r"^(?P<ddd>[1-9]{2})(?P<fone>([2-8]|9[0-9])[0-9]{3}[0-9]{4})$")
return True if re.match(pattern, value) else False
5 changes: 4 additions & 1 deletion src/procergs/sitedemo/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="procergs.sitedemo.vocabulary.estados"
component=".estados.vocab_estados"
/>
</configure>
44 changes: 44 additions & 0 deletions src/procergs/sitedemo/vocabularies/estados.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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)
Loading

0 comments on commit 8b01797

Please sign in to comment.