-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exercício 17: Adiciona tipo de conteúdo Secretaria
- Loading branch information
1 parent
852f8f6
commit dd44f30
Showing
7 changed files
with
168 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from plone.dexterity.content import Container | ||
from plone.schema.email import Email | ||
from plone.supermodel import model | ||
from portal.governo import _ | ||
from zope import schema | ||
from zope.interface import implementer | ||
|
||
|
||
class ISecretaria(model.Schema): | ||
"""Definição de uma Secretaria de governo.""" | ||
|
||
model.fieldset( | ||
"contato", | ||
_("Contato"), | ||
fields=[ | ||
"email", | ||
"telefone", | ||
], | ||
) | ||
email = Email( | ||
title=_("Email"), | ||
required=True, | ||
) | ||
|
||
telefone = schema.TextLine( | ||
title=_("Telefone"), | ||
description=_("Informe o telefone de contato"), | ||
required=False, | ||
) | ||
|
||
|
||
@implementer(ISecretaria) | ||
class Secretaria(Container): | ||
"""Uma secretaria de governo.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:zcml="http://namespaces.zope.org/zcml" | ||
i18n_domain="portal.governo" | ||
> | ||
|
||
<configure zcml:condition="installed AccessControl.security"> | ||
|
||
<permission | ||
id="portal.governo.secretaria.add" | ||
title="portal.governo: Add Secretaria" | ||
/> | ||
|
||
</configure> | ||
|
||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<rolemap> | ||
<permissions> | ||
|
||
<permission acquire="False" | ||
name="portal.governo: Add Secretaria" | ||
> | ||
<role name="Manager" /> | ||
<role name="Site Administrator" /> | ||
</permission> | ||
</permissions> | ||
</rolemap> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
backend/src/portal/governo/profiles/default/types/Secretaria.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<object xmlns:i18n="http://xml.zope.org/namespaces/i18n" | ||
meta_type="Dexterity FTI" | ||
name="Secretaria" | ||
i18n:domain="portal.governo" | ||
> | ||
|
||
<!-- Basic properties --> | ||
<property name="title" | ||
i18n:translate="" | ||
>Secretaria</property> | ||
<property name="description" | ||
i18n:translate="" | ||
>Uma Secretaria dentro da estrutura de governo</property> | ||
|
||
<property name="allow_discussion">False</property> | ||
<property name="factory">Secretaria</property> | ||
|
||
<!-- Hierarchy control --> | ||
<property name="filter_content_types">False</property> | ||
<property name="allowed_content_types" /> | ||
<property name="global_allow">True</property> | ||
|
||
<!-- Schema, class and security --> | ||
<property name="add_permission">portal.governo.secretaria.add</property> | ||
<property name="klass">portal.governo.content.secretaria.Secretaria</property> | ||
<property name="schema">portal.governo.content.secretaria.ISecretaria</property> | ||
|
||
<!-- Enabled behaviors --> | ||
<property name="behaviors" | ||
purge="false" | ||
> | ||
<element value="plone.basic" /> | ||
<element value="plone.namefromtitle" /> | ||
<element value="plone.shortname" /> | ||
<element value="plone.excludefromnavigation" /> | ||
<element value="volto.blocks" /> | ||
<element value="volto.preview_image" /> | ||
<element value="plone.constraintypes" /> | ||
<element value="plone.navigationroot" /> | ||
<element value="plone.versioning" /> | ||
</property> | ||
|
||
</object> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from plone import api | ||
from plone.dexterity.fti import DexterityFTI | ||
from portal.governo.content.secretaria import Secretaria | ||
from zope.component import createObject | ||
|
||
import pytest | ||
|
||
|
||
CONTENT_TYPE = "Secretaria" | ||
|
||
|
||
@pytest.fixture | ||
def secretaria_payload() -> dict: | ||
"""Return a payload to create a new secretaria.""" | ||
return { | ||
"type": "Secretaria", | ||
"id": "casacivil", | ||
"title": "Casa Civil", | ||
"description": ( | ||
"A Casa Civil do Governo do Estado foi criada em janeiro de 1954," | ||
"pelo então governador Ernesto Dornelles" | ||
), | ||
"email": "[email protected]", | ||
"telefone": "(51) 3210.4193", | ||
} | ||
|
||
|
||
class TestSecretaria: | ||
@pytest.fixture(autouse=True) | ||
def _setup(self, get_fti, portal): | ||
self.fti = get_fti(CONTENT_TYPE) | ||
self.portal = portal | ||
|
||
def test_fti(self): | ||
assert isinstance(self.fti, DexterityFTI) | ||
|
||
def test_factory(self): | ||
factory = self.fti.factory | ||
obj = createObject(factory) | ||
assert obj is not None | ||
assert isinstance(obj, Secretaria) | ||
|
||
@pytest.mark.parametrize( | ||
"behavior", | ||
[ | ||
"plone.basic", | ||
"plone.namefromtitle", | ||
"plone.shortname", | ||
"plone.excludefromnavigation", | ||
"plone.versioning", | ||
"volto.blocks", | ||
"plone.constraintypes", | ||
"plone.navigationroot", | ||
"volto.preview_image", | ||
], | ||
) | ||
def test_has_behavior(self, get_behaviors, behavior): | ||
assert behavior in get_behaviors(CONTENT_TYPE) | ||
|
||
def test_create(self, secretaria_payload): | ||
with api.env.adopt_roles(["Manager"]): | ||
content = api.content.create(container=self.portal, **secretaria_payload) | ||
assert content.portal_type == CONTENT_TYPE | ||
assert isinstance(content, Secretaria) |