|
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): |
|
|
|
|
|
|
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
|
|
|
|