-
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 21: Passo de atualização para o tipo Área
- Loading branch information
Showing
10 changed files
with
180 additions
and
6 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 trepr.intranet import _ | ||
from zope import schema | ||
from zope.interface import implementer | ||
|
||
|
||
class IArea(model.Schema): | ||
"""Definição de uma Área.""" | ||
|
||
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(IArea) | ||
class Area(Container): | ||
"""Uma Área no TRE-PR.""" |
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="trepr.intranet" | ||
> | ||
|
||
<configure zcml:condition="installed AccessControl.security"> | ||
|
||
<permission | ||
id="trepr.intranet.area.add" | ||
title="trepr.intranet: Add Area" | ||
/> | ||
|
||
</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
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="trepr.intranet: Add Area" | ||
> | ||
<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
43 changes: 43 additions & 0 deletions
43
backend/src/trepr/intranet/profiles/default/types/Area.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,43 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<object xmlns:i18n="http://xml.zope.org/namespaces/i18n" | ||
meta_type="Dexterity FTI" | ||
name="Area" | ||
i18n:domain="trepr.intranet" | ||
> | ||
|
||
<!-- Basic properties --> | ||
<property name="title" | ||
i18n:translate="" | ||
>Área</property> | ||
<property name="description" | ||
i18n:translate="" | ||
>Uma Área dentro do TRE-PR</property> | ||
|
||
<property name="allow_discussion">False</property> | ||
<property name="factory">Area</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">trepr.intranet.area.add</property> | ||
<property name="klass">trepr.intranet.content.area.Area</property> | ||
<property name="schema">trepr.intranet.content.area.IArea</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.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
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,60 @@ | ||
from plone import api | ||
from plone.dexterity.fti import DexterityFTI | ||
from trepr.intranet.content.area import Area | ||
from zope.component import createObject | ||
|
||
import pytest | ||
|
||
|
||
CONTENT_TYPE = "Area" | ||
|
||
|
||
@pytest.fixture | ||
def area_payload() -> dict: | ||
"""Return a payload to create a new area.""" | ||
return { | ||
"type": "Area", | ||
"id": "ti", | ||
"title": "Tecnologia da Informação", | ||
"description": ("Área responsável por TI"), | ||
"email": "[email protected]", | ||
"telefone": "(41) 3210.1234", | ||
} | ||
|
||
|
||
class TestArea: | ||
@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, Area) | ||
|
||
@pytest.mark.parametrize( | ||
"behavior", | ||
[ | ||
"plone.basic", | ||
"plone.namefromtitle", | ||
"plone.shortname", | ||
"plone.excludefromnavigation", | ||
"plone.versioning", | ||
"volto.blocks", | ||
"plone.constraintypes", | ||
"volto.preview_image", | ||
], | ||
) | ||
def test_has_behavior(self, get_behaviors, behavior): | ||
assert behavior in get_behaviors(CONTENT_TYPE) | ||
|
||
def test_create(self, area_payload): | ||
with api.env.adopt_roles(["Manager"]): | ||
content = api.content.create(container=self.portal, **area_payload) | ||
assert content.portal_type == CONTENT_TYPE | ||
assert isinstance(content, Area) |
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