Skip to content

Commit

Permalink
Exercício 41
Browse files Browse the repository at this point in the history
  • Loading branch information
jadirj committed Oct 15, 2024
1 parent 6e17603 commit 451ef41
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions backend/src/trepr/intranet/subscribers/area.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from trepr.intranet import logger
from trepr.intranet.content.area import Area
from zope.lifecycleevent import ObjectAddedEvent
from zope.lifecycleevent import ObjectModifiedEvent


def _update_excluded_from_nav(obj: Area):
Expand All @@ -13,3 +14,8 @@ def _update_excluded_from_nav(obj: Area):
def added(obj: Area, event: ObjectAddedEvent):
"""Post creation handler for Area."""
_update_excluded_from_nav(obj)


def modified(obj: Area, event: ObjectModifiedEvent):
"""Post modified handler for Area."""
_update_excluded_from_nav(obj)
6 changes: 6 additions & 0 deletions backend/src/trepr/intranet/subscribers/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
handler=".area.added"
/>

<subscriber
for="trepr.intranet.content.area.IArea
zope.lifecycleevent.IObjectModifiedEvent"
handler=".area.modified"
/>

</configure>
14 changes: 14 additions & 0 deletions backend/tests/content/test_content_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from plone.dexterity.fti import DexterityFTI
from trepr.intranet.content.area import Area
from zope.component import createObject
from zope.event import notify
from zope.lifecycleevent import ObjectModifiedEvent

import pytest

Expand Down Expand Up @@ -95,3 +97,15 @@ def test_subscriber_added_without_description_value(self, area_payload):
payload["description"] = ""
area = api.content.create(container=container, **payload)
assert area.exclude_from_nav is True

def test_subscriber_modified(self, area_payload):
container = self.portal
with api.env.adopt_roles(["Manager"]):
area = api.content.create(container=container, **area_payload)
assert area.exclude_from_nav is False
# Altera a descricao
area.description = ""
# Dispara o evento de modificacao
notify(ObjectModifiedEvent(area))
# Agora o objeto desaparece da navegação
assert area.exclude_from_nav is True

0 comments on commit 451ef41

Please sign in to comment.