Skip to content

Commit

Permalink
Added PseudoMessage class that be be used in viewlet template.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgeulette committed Jul 12, 2019
1 parent cc86e87 commit 8758e89
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Changelog
0.19 (unreleased)
-----------------

- Nothing changed yet.

- Added PseudoMessage class that be be used in viewlet template.
[sgeulette]

0.18 (2019-05-27)
-----------------
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ The optional 'messages' profile adds some usefull examples that can be activated
* message for imminent or current maintenance : (given to anonymous)
* message for staging site

There is also a PseudoMessage class that can be instantiated and used in viewlet templates.

Improvements
------------

Expand Down
21 changes: 21 additions & 0 deletions src/collective/messagesviewlet/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
from z3c.form.browser.radio import RadioFieldWidget
from zope import schema
from zope.interface import alsoProvides
from zope.interface import implements
from zope.interface import Invalid
from zope.interface import invariant
from zope.schema.fieldproperty import FieldProperty
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary

Expand Down Expand Up @@ -156,3 +158,22 @@ def end_index(obj):
return DateTime(2099, 01, 01)
else:
return add_timezone(obj.end)


class PseudoMessage(object):
"""
This is not the class used with dexterity !
This class is intended to be used in another context to instantiate messages that can be used in viewlet.
"""

implements(IMessage)

# Provide the minimal fields, needed in viewlet templates:
msg_type = FieldProperty(IMessage["msg_type"])
text = FieldProperty(IMessage["text"])
can_hide = FieldProperty(IMessage["can_hide"])
hidden_uid = FieldProperty(IMessage["hidden_uid"])

def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)

0 comments on commit 8758e89

Please sign in to comment.