Passed
Push — 2.x ( 4e3b0a...8119a4 )
by Jordi
07:03
created

senaite.core.browser.form.wstemplate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 16
dl 0
loc 42
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A UpdateNumPositions.__call__() 0 12 3
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-2024 by it's authors.
19
# Some rights reserved, see README and LICENSE.
20
21
from bika.lims.browser import BrowserView
22
from senaite.core.interfaces import IWorksheetTemplate
23
from senaite.core.interfaces import IWorksheetTemplates
24
25
26
class UpdateNumPositions(BrowserView):
27
    """Changing number of positions for template layout from add/edit form
28
    """
29
30
    def __call__(self):
31
        url = self.context.absolute_url()
32
        sub_path = ""
33
        num = self.request.form.get("form.widgets.num_of_positions", 0)
34
        if IWorksheetTemplate.providedBy(self.context):
35
            self.context.setNumOfPositions(num)
36
            sub_path = "edit"
37
        elif IWorksheetTemplates.providedBy(self.context):
38
            sub_path = "++add++WorksheetTemplate?num_positions={}".format(num)
39
40
        url = "/".join([url, sub_path])
41
        return self.request.response.redirect(url)
42