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
|
|
|
import collections |
22
|
|
|
|
23
|
|
|
import six |
24
|
|
|
|
25
|
|
|
from bika.lims import _ |
26
|
|
|
from bika.lims import api |
27
|
|
|
from senaite.app.listing.view import ListingView |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
class DynamicAnalysisSpecView(ListingView): |
31
|
|
|
"""A listing view that shows the contents of the Excel |
32
|
|
|
""" |
33
|
|
|
def __init__(self, context, request): |
34
|
|
|
super(DynamicAnalysisSpecView, self).__init__(context, request) |
35
|
|
|
|
36
|
|
|
self.pagesize = 50 |
37
|
|
|
self.context_actions = {} |
38
|
|
|
self.title = api.get_title(self.context) |
39
|
|
|
self.description = api.get_description(self.context) |
40
|
|
|
self.show_search = False |
41
|
|
|
self.show_column_toggles = False |
42
|
|
|
|
43
|
|
|
if self.context.specs_file: |
44
|
|
|
filename = self.context.specs_file.filename |
45
|
|
|
self.description = _("Contents of the file {}".format(filename)) |
46
|
|
|
|
47
|
|
|
self.specs = self.context.get_specs() |
48
|
|
|
self.total = len(self.specs) |
49
|
|
|
|
50
|
|
|
self.columns = collections.OrderedDict() |
51
|
|
|
for title in self.context.get_header(): |
52
|
|
|
self.columns[title] = { |
53
|
|
|
"title": title, |
54
|
|
|
"toggle": True} |
55
|
|
|
|
56
|
|
|
self.review_states = [ |
57
|
|
|
{ |
58
|
|
|
"id": "default", |
59
|
|
|
"title": _("All"), |
60
|
|
|
"contentFilter": {}, |
61
|
|
|
"transitions": [], |
62
|
|
|
"custom_transitions": [], |
63
|
|
|
"columns": self.columns.keys() |
64
|
|
|
} |
65
|
|
|
] |
66
|
|
|
|
67
|
|
|
def update(self): |
68
|
|
|
super(DynamicAnalysisSpecView, self).update() |
69
|
|
|
|
70
|
|
|
def before_render(self): |
71
|
|
|
super(DynamicAnalysisSpecView, self).before_render() |
72
|
|
|
|
73
|
|
|
def make_empty_item(self, record): |
74
|
|
|
"""Create a new empty item |
75
|
|
|
""" |
76
|
|
|
item = { |
77
|
|
|
"uid": None, |
78
|
|
|
"before": {}, |
79
|
|
|
"after": {}, |
80
|
|
|
"replace": {}, |
81
|
|
|
"allow_edit": [], |
82
|
|
|
"disabled": False, |
83
|
|
|
"state_class": "state-active", |
84
|
|
|
} |
85
|
|
|
for k, v in record.items(): |
86
|
|
|
# ensure keyword dictionary keys contains only strings |
87
|
|
|
if not self.is_string(k): |
88
|
|
|
continue |
89
|
|
|
item[k] = v |
90
|
|
|
return item |
91
|
|
|
|
92
|
|
|
def is_string(self, value): |
93
|
|
|
return isinstance(value, six.string_types) |
94
|
|
|
|
95
|
|
|
def folderitems(self): |
96
|
|
|
items = [] |
97
|
|
|
for record in self.specs: |
98
|
|
|
items.append(self.make_empty_item(record)) |
99
|
|
|
return items |
100
|
|
|
|