Passed
Push — master ( 9a9b5b...f9d22b )
by Jordi
04:10
created

SenaiteContentMenuProvider.menu()   A

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nop 1
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-2020 by it's authors.
19
# Some rights reserved, see README and LICENSE.
20
21
from plone.app.contentmenu.menu import WorkflowMenu as BaseClass
22
from plone.app.contentmenu.view import ContentMenuProvider
23
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
24
from zope.component import getUtility
25
from zope.browsermenu.interfaces import IBrowserMenu
26
27
28
class SenaiteContentMenuProvider(ContentMenuProvider):
29
    """Provides a proper styled content menu
30
    """
31
    index = ViewPageTemplateFile(
32
        "templates/plone.app.contentmenu.contentmenu.pt")
33
34
    def render(self):
35
        return self.index()
36
37
    # From IContentMenuView
38
39
    def available(self):
40
        return True
41
42
    def menu(self):
43
        menu = getUtility(IBrowserMenu, name="plone_contentmenu")
44
        items = menu.getMenuItems(self.context, self.request)
45
        # always filter out the selection of the default view
46
        items = filter(
47
            lambda a: not a["action"].endswith("/select_default_view"), items)
48
        items.reverse()
49
        return items
50
51
52
class WorkflowMenu(BaseClass):
53
    def getMenuItems(self, context, request):
54
        """Overrides the workflow actions menu displayed top right in the
55
        object's view. Displays the current state of the object, as well as a
56
        list with the actions that can be performed.
57
        The option "Advanced.." is not displayed and the list is populated with
58
        all allowed transitions for the object.
59
        """
60
        actions = super(WorkflowMenu, self).getMenuItems(context, request)
61
        # Remove status history menu item ('Advanced...')
62
        return filter(
63
            lambda a: not a["action"].endswith("/content_status_history"),
64
            actions)
65