Completed
Push — master ( 65c723...b6585a )
by Jordi
76:39 queued 72:29
created

bika.lims.browser.dynamic_analysisspec   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 19.18 %

Importance

Changes 0
Metric Value
wmc 8
eloc 51
dl 14
loc 73
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A DynamicAnalysisSpecView.update() 0 2 1
A DynamicAnalysisSpecView.__init__() 0 31 3
A DynamicAnalysisSpecView.before_render() 0 2 1
A DynamicAnalysisSpecView.make_empty_item() 14 14 1
A DynamicAnalysisSpecView.folderitems() 0 5 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
# -*- coding: utf-8 -*-
2
3
import collections
4
5
from bika.lims import _
6
from bika.lims import api
7
from senaite.core.listing.view import ListingView
8
9
10
class DynamicAnalysisSpecView(ListingView):
11
    """A listing view that shows the contents of the Excel
12
    """
13
    def __init__(self, context, request):
14
        super(DynamicAnalysisSpecView, self).__init__(context, request)
15
16
        self.pagesize = 50
17
        self.context_actions = {}
18
        self.title = api.get_title(self.context)
19
        self.description = api.get_description(self.context)
20
        self.show_search = False
21
        self.show_column_toggles = False
22
23
        if self.context.specs_file:
24
            filename = self.context.specs_file.filename
25
            self.description = _("Contents of the file {}".format(filename))
26
27
        self.specs = self.context.get_specs()
28
        self.total = len(self.specs)
29
30
        self.columns = collections.OrderedDict()
31
        for title in self.context.get_header():
32
            self.columns[title] = {
33
                "title": title,
34
                "toggle": True}
35
36
        self.review_states = [
37
            {
38
                "id": "default",
39
                "title": _("All"),
40
                "contentFilter": {},
41
                "transitions": [],
42
                "custom_transitions": [],
43
                "columns": self.columns.keys()
44
            }
45
        ]
46
47
    def update(self):
48
        super(DynamicAnalysisSpecView, self).update()
49
50
    def before_render(self):
51
        super(DynamicAnalysisSpecView, self).before_render()
52
53 View Code Duplication
    def make_empty_item(self, **kw):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
54
        """Create a new empty item
55
        """
56
        item = {
57
            "uid": None,
58
            "before": {},
59
            "after": {},
60
            "replace": {},
61
            "allow_edit": [],
62
            "disabled": False,
63
            "state_class": "state-active",
64
        }
65
        item.update(**kw)
66
        return item
67
68
    def folderitems(self):
69
        items = []
70
        for record in self.specs:
71
            items.append(self.make_empty_item(**record))
72
        return items
73