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