/
__init__.py
49 lines (40 loc) · 1.78 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
##############################################################################
#
# Copyright (c) 2001-2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"Non-API test details."
from zope.interface import implementer
from zope.publisher.browser import BrowserView
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.browsermenu.menu import getFirstMenuItem
@implementer(IBrowserPublisher)
class ManagementViewSelector(BrowserView):
"""View that selects the first available management view.
Support 'zmi_views' actions like: 'javascript:alert("hello")',
'../view_on_parent.html' or '++rollover++'.
"""
# Copied from zope.app.publication
# Simplified to assert just the test case we expect.
def browserDefault(self, request):
return self, ()
def __call__(self):
item = getFirstMenuItem('zmi_views', self.context, self.request)
assert item
redirect_url = item['action']
if not redirect_url.lower().startswith(('../', 'javascript:', '++')):
self.request.response.redirect(redirect_url)
return u''
raise AssertionError("Should not get here") # pragma: no cover
class LoginLogout(object):
# Dummy implementation of zope.app.security.browser.auth.LoginLogout
def __call__(self):
return None