Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/collective/collective.messa…
Browse files Browse the repository at this point in the history
…gesviewlet
  • Loading branch information
gbastien committed Mar 4, 2019
2 parents 9db21d2 + 6c72e4d commit 2124f78
Show file tree
Hide file tree
Showing 57 changed files with 804 additions and 279 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ include =
omit =
*/test*
*/upgrades/*
*/upgrades.py
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ output.xml
*.html
*.komodoproject
share/
local/
pip-selfcheck.json
33 changes: 17 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
language: python

python:
- 2.7

sudo: false
cache:
pip: true
directories:
- buildout-cache/downloads
- buildout-cache/eggs

- eggs
- downloads
python:
- 2.7
env:
- PLONE_VERSION=4.3
- PLONE_VERSION=5.1
install:
- mkdir -p buildout-cache/{eggs,downloads}
- python bootstrap-buildout.py --version=2.10.0 -c travis.cfg
- bin/buildout -Nc travis.cfg

- sed -ie "s#5-latest#$PLONE_VERSION-latest#" buildout.cfg
- python bootstrap-buildout.py --version=2.11.4
- bin/buildout -N buildout:download-cache=downloads code-analysis:return-status-codes=True annotate
- bin/buildout -N buildout:download-cache=downloads code-analysis:return-status-codes=True
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- firefox -v
script:
- bin/test
- bin/coverage run bin/test

after_success:
- bin/coverage run bin/test
- bin/createcoverage --output-dir htmlcov
- pip install coveralls==0.5
- coveralls

notifications:
email:
- devs@imio.be
11 changes: 8 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ Changelog
=========


0.17 (unreleased)
0.16 (unreleased)
-----------------

- Evaluate TAL condition using behavior `evaluate` method instead calling
directly submethod `utils.evaluateExpressionFor` so behavior method
`complete_extra_expr_ctx` is called.
[gbastien]
- Call JS on portal_url so it can be cached by the browser.
[gbastien]
- Tests on Plone5 and Plone4.
[bsuttor]
- Manage profiles differently
[sgeulette]


0.16 (2018-10-18)
-----------------
Expand All @@ -31,8 +38,6 @@ Changelog
0.13 (2018-06-13)
-----------------

- Call JS on portal_url so it can be cached by the browser.
[gbastien]
- Add <span> around cross <img> to ease override.
[mgennart]

Expand Down
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/make
#
# plone-path is added when "vhost_path: mount/site" is defined in puppet
plone=$(shell grep plone-path port.cfg|cut -c 14-)
hostname=$(shell hostname)
instance1_port=$(shell grep instance1-http port.cfg|cut -c 18-)
disable=1
copydata=1
instance=instance-debug
profile=collective.messagesviewlet:base

all: run

.PHONY: bootstrap
bootstrap:
virtualenv-2.7 .
./bin/python bootstrap-buildout.py

.PHONY: setup
setup:
if [ -f /usr/bin/virtualenv-2.7 ] ; then virtualenv-2.7 .;else virtualenv -p python2.7 .;fi
./bin/pip install --upgrade pip
./bin/pip install -r requirements.txt

.PHONY: buildout
buildout:
if ! test -f bin/buildout;then make setup;fi
bin/buildout -v

.PHONY: run
run:
if ! test -f bin/instance1;then make buildout;fi
bin/instance1 fg

.PHONY: cleanall
cleanall:
rm -fr lib bin/buildout develop-eggs downloads eggs parts .installed.cfg
42 changes: 19 additions & 23 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
[buildout]
extends =
https://raw.github.com/collective/buildout.plonetest/master/test-4.x.cfg
https://raw.github.com/collective/buildout.plonetest/master/test-5.x.cfg
versions.cfg

extensions = mr.developer

parts =
instance
omelette
test
robot
coverage
report
code-analysis
createcoverage
releaser
i18ndude
omelette
robot
resources

develop = .
show-picked-versions = true

always-checkout = force
auto-checkout +=

test-eggs = collective.messagesviewlet [test]

[remotes]
coll = https://github.com/collective
coll_push = git@github.com:collective


[sources]


[instance]
recipe = plone.recipe.zope2instance
user = admin:admin
Expand All @@ -49,7 +51,7 @@ environment-vars =


[code-analysis]
recipe = plone.recipe.codeanalysis
recipe = plone.recipe.codeanalysis[recommended]
directory = ${buildout:directory}/src/collective
flake8-exclude = bootstrap.py,bootstrap-buildout.py,docs,*.egg.,omelette
flake8-ignore = W391
Expand All @@ -59,7 +61,7 @@ flake8-extensions =
flake8-blind-except
flake8-debugger
flake8-coding

return-status-codes = False

[omelette]
recipe = collective.recipe.omelette
Expand All @@ -70,7 +72,7 @@ eggs = ${instance:eggs}
recipe = zc.recipe.testrunner
eggs =
${instance:eggs}
collective.messagesviewlet [test]
${buildout:test-eggs}
robotframework-selenium2screenshots
defaults = ['-s', 'collective.messagesviewlet', '--auto-color', '--auto-progress']
environment = testenv
Expand All @@ -87,20 +89,9 @@ eggs =
plone.app.robotframework[debug,ride,reload]


[coverage]
[createcoverage]
recipe = zc.recipe.egg
eggs = coverage
initialization =
include = '--source=${buildout:directory}/src/collective/messagesviewlet'
sys.argv = sys.argv[:] + ['run', include, 'bin/test', '--all', '-s', 'collective.messagesviewlet']


[report]
recipe = zc.recipe.egg
eggs = coverage
scripts = coverage=report
initialization =
sys.argv = sys.argv[:] + ['html', '-i']
eggs = createcoverage


[releaser]
Expand All @@ -112,3 +103,8 @@ eggs = zest.releaser
recipe = zc.recipe.egg
eggs = i18ndude


[resources]
recipe = zc.recipe.egg
eggs = Products.CMFPlone
scripts = plone-compile-resources
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
====================
==========================
collective.messagesviewlet
====================
==========================

User documentation
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
setuptools==38.5.1
wheel==0.31.1
zc.buildout==2.11.4
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
install_requires=[
'collective.behavior.talcondition',
'plone.api',
'plone.app.contenttypes',
'plone.app.dexterity',
'plone.app.lockingbehavior',
'plone.formwidget.datetime >= 1.2',
Expand Down
4 changes: 4 additions & 0 deletions src/collective/messagesviewlet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# -*- coding: utf-8 -*-
"""Init and utils."""

from plone import api
from zope.i18nmessageid import MessageFactory


_ = MessageFactory('collective.messagesviewlet')

HAS_PLONE_5 = api.env.plone_version().startswith('5')
10 changes: 10 additions & 0 deletions src/collective/messagesviewlet/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="collective.messagesviewlet">

<!-- Publish static files -->
<plone:static
zcml:condition="have plone-5"
name="collective.messagesviewlet"
directory="static"
type="plone"
/>

<browser:resourceDirectory
zcml:condition="not-have plone-5"
name="collective.messagesviewlet"
directory="static"
/>
<!-- End publish static files -->

<browser:viewlet
for="*"
Expand Down
25 changes: 23 additions & 2 deletions src/collective/messagesviewlet/browser/messagesviewlet.pt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
tal:condition= "messages"
i18n:domain="collective.messagesviewlet">

<script tal:attributes="src string:${view/portal_url}/++resource++collective.messagesviewlet/js.cookie-2.0.3.min.js"></script>
<script tal:attributes="src string:${view/portal_url}/++resource++collective.messagesviewlet/hidemessageviewlet.js"></script>
<tal:plone4 condition="python: not view.is_plone_5()">
<script tal:attributes="src string:${view/portal_url}/++resource++collective.messagesviewlet/js.cookie-2.0.3.min.js"></script>
<script tal:attributes="src string:${view/portal_url}/++resource++collective.messagesviewlet/hidemessageviewlet.js"></script>
<tal:message repeat="message messages">
<dl tal:attributes="class python:'messagesviewlet-' + message.msg_type;
id message/hidden_uid">
Expand All @@ -21,4 +22,24 @@
</span>
</dl>
</tal:message>
</tal:plone4>

<tal:plone5 condition="python: view.is_plone_5()">
<tal:message5 repeat="message messages">
<div tal:define="CSSClassName python:view.getCSSClassName(message.msg_type)"
tal:attributes="class CSSClassName;
id message/hidden_uid">
<span class="messagesviewlet-type"
i18n:translate="" tal:content="python:message.msg_type">Info</span>
<span class="content"
tal:replace="structure python: message.text.output">
The status message.
</span>
<span class="close-button" i18n:attributes='title close_title' tal:condition="message/can_hide">
</span>
</div>
</tal:message5>
</tal:plone5>

</div>

16 changes: 11 additions & 5 deletions src/collective/messagesviewlet/browser/messagesviewlet.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# -*- coding: utf-8 -*-

from collective.behavior.talcondition.behavior import ITALCondition
from collective.messagesviewlet import HAS_PLONE_5
from DateTime import DateTime

from plone import api
from plone.app.layout.navigation.defaultpage import isDefaultPage
from plone.app.layout.navigation.interfaces import INavigationRoot
from plone.app.layout.viewlets import ViewletBase
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile

from collective.behavior.talcondition.behavior import ITALCondition


class MessagesViewlet(ViewletBase):
"""This viewlet displays all messages from this product."""
Expand All @@ -19,6 +18,9 @@ def __init__(self, context, request, view, manager=None):
super(MessagesViewlet, self).__init__(context, request, view, manager=manager)
self.portal = api.portal.get()

def is_plone_5(self):
return HAS_PLONE_5

def getAllMessages(self):
catalog = api.portal.get_tool(name='portal_catalog')
# Getting user roles on context
Expand All @@ -34,12 +36,12 @@ def getAllMessages(self):
sort_on='getObjPositionInParent')
messages = []
for brain in brains:
if brain.location == 'homepage':
obj = brain._unrestrictedGetObject()
if obj.location == 'homepage':
# Test if context is PloneSite or its default page
if not INavigationRoot.providedBy(self.context) and \
not isDefaultPage(self.portal, self.context):
continue
obj = brain._unrestrictedGetObject()
# check in the cookie if message is marked as read
if obj.can_hide:
m_uids = self.request.get('messagesviewlet', '')
Expand All @@ -58,3 +60,7 @@ def getAllMessages(self):
messages.append(obj)

return messages

def getCSSClassName(self, msg_type):
mapping_type={'info':'info','significant':'warning','warning':'error'}
return "portalMessage {0}".format(mapping_type[msg_type])
10 changes: 10 additions & 0 deletions src/collective/messagesviewlet/browser/static/messagesviewlet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$(document).ready(function(){
$("#messagesviewlet .close-button").click(function(){
var m_uids = $.cookie('messagesviewlet');
var m_uid = $(this).parent().attr('id');
if (typeof m_uids === "undefined") {m_uids = m_uid;}
else {m_uids += "|" + m_uid;}
$.cookie('messagesviewlet', m_uids, { expires: 60 });
$(this).parent().hide();
});
});

0 comments on commit 2124f78

Please sign in to comment.