1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# |
3
|
|
|
# This file is part of SENAITE.CORE. |
4
|
|
|
# |
5
|
|
|
# SENAITE.CORE is free software: you can redistribute it and/or modify it under |
6
|
|
|
# the terms of the GNU General Public License as published by the Free Software |
7
|
|
|
# Foundation, version 2. |
8
|
|
|
# |
9
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
10
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
11
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
12
|
|
|
# details. |
13
|
|
|
# |
14
|
|
|
# You should have received a copy of the GNU General Public License along with |
15
|
|
|
# this program; if not, write to the Free Software Foundation, Inc., 51 |
16
|
|
|
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17
|
|
|
# |
18
|
|
|
# Copyright 2018-2021 by it's authors. |
19
|
|
|
# Some rights reserved, see README and LICENSE. |
20
|
|
|
|
21
|
|
|
from bika.lims.api.security import check_permission |
22
|
|
|
from plone.app.layout.viewlets.common import PersonalBarViewlet |
23
|
|
|
from plone.app.viewletmanager.manager import OrderedViewletManager |
24
|
|
|
from plone.memoize.instance import memoize |
25
|
|
|
from plone.registry.interfaces import IRegistry |
26
|
|
|
from Products.CMFPlone.interfaces.controlpanel import ISiteSchema |
27
|
|
|
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
28
|
|
|
from senaite.core.browser.viewlets.languageselector import LanguageSelector |
29
|
|
|
from senaite.core.browser.viewlets.sections import GlobalSectionsViewlet |
30
|
|
|
from zope.component import getMultiAdapter |
31
|
|
|
from zope.component import getUtility |
32
|
|
|
|
33
|
|
|
LOGO = "/++plone++senaite.core.static/images/senaite.svg" |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
class ToolbarViewletManager(OrderedViewletManager): |
37
|
|
|
custom_template = ViewPageTemplateFile("templates/toolbar.pt") |
38
|
|
|
|
39
|
|
|
def base_render(self): |
40
|
|
|
return super(ToolbarViewletManager, self).render() |
41
|
|
|
|
42
|
|
|
def render(self): |
43
|
|
|
return self.custom_template() |
44
|
|
|
|
45
|
|
|
@property |
46
|
|
|
@memoize |
47
|
|
|
def context_state(self): |
48
|
|
|
return getMultiAdapter( |
49
|
|
|
(self.context, self.request), |
50
|
|
|
name='plone_context_state' |
51
|
|
|
) |
52
|
|
|
|
53
|
|
|
@property |
54
|
|
|
@memoize |
55
|
|
|
def portal(self): |
56
|
|
|
return self.portal_state.portal() |
57
|
|
|
|
58
|
|
|
@property |
59
|
|
|
@memoize |
60
|
|
|
def portal_state(self): |
61
|
|
|
return getMultiAdapter( |
62
|
|
|
(self.context, self.request), |
63
|
|
|
name='plone_portal_state' |
64
|
|
|
) |
65
|
|
|
|
66
|
|
|
@memoize |
67
|
|
|
def is_manager(self): |
68
|
|
|
return check_permission("senaite.core: Manage Bika", self.portal) |
69
|
|
|
|
70
|
|
|
def get_personal_bar(self): |
71
|
|
|
viewlet = PersonalBarViewlet( |
72
|
|
|
self.context, |
73
|
|
|
self.request, |
74
|
|
|
self.__parent__, self |
75
|
|
|
) |
76
|
|
|
viewlet.update() |
77
|
|
|
return viewlet |
78
|
|
|
|
79
|
|
|
def get_toolbar_logo(self): |
80
|
|
|
registry = getUtility(IRegistry) |
81
|
|
|
portal_url = self.portal_state.portal_url() |
82
|
|
|
try: |
83
|
|
|
logo = registry["senaite.toolbar_logo"] |
84
|
|
|
except AttributeError: |
85
|
|
|
logo = LOGO |
86
|
|
|
if not logo: |
87
|
|
|
logo = LOGO |
88
|
|
|
return portal_url + logo |
89
|
|
|
|
90
|
|
|
def get_toolbar_styles(self): |
91
|
|
|
registry = getUtility(IRegistry) |
92
|
|
|
try: |
93
|
|
|
styles = registry["senaite.toolbar_logo_styles"] |
94
|
|
|
except AttributeError: |
95
|
|
|
return "height:15px;" |
96
|
|
|
css = map(lambda style: "{}:{};".format(*style), styles.items()) |
97
|
|
|
return " ".join(css) |
98
|
|
|
|
99
|
|
|
def get_lims_setup_url(self): |
100
|
|
|
portal_url = self.portal_state.portal().absolute_url() |
101
|
|
|
return "/".join([portal_url, "@@lims-setup"]) |
102
|
|
|
|
103
|
|
|
def get_global_sections(self): |
104
|
|
|
viewlet = GlobalSectionsViewlet( |
105
|
|
|
self.context, |
106
|
|
|
self.request, |
107
|
|
|
self.__parent__, self |
108
|
|
|
) |
109
|
|
|
viewlet.update() |
110
|
|
|
return viewlet |
111
|
|
|
|
112
|
|
|
def get_language_selector(self): |
113
|
|
|
viewlet = LanguageSelector( |
114
|
|
|
self.context, |
115
|
|
|
self.request, |
116
|
|
|
self.__parent__, self |
117
|
|
|
) |
118
|
|
|
viewlet.update() |
119
|
|
|
return viewlet |
120
|
|
|
|