1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
|
3
|
|
|
from archetypes.schemaextender.interfaces import IBrowserLayerAwareExtender |
4
|
|
|
from archetypes.schemaextender.interfaces import IOrderableSchemaExtender |
5
|
|
|
from archetypes.schemaextender.interfaces import ISchemaExtender |
6
|
|
|
from archetypes.schemaextender.interfaces import ISchemaModifier |
7
|
|
|
from bika.lims import senaiteMessageFactory as _ |
8
|
|
|
from Products.CMFCore import permissions |
9
|
|
|
from senaite.core.browser.widgets.queryselect import QuerySelectWidget |
10
|
|
|
from senaite.core.catalog import SETUP_CATALOG |
11
|
|
|
from senaite.core.config.fields import AT_LABEL_FIELD |
12
|
|
|
from senaite.core.extender import ExtLabelField |
13
|
|
|
from senaite.core.interfaces import ICanHaveLabels |
14
|
|
|
from senaite.core.interfaces import ISenaiteCore |
15
|
|
|
from zope.component import adapts |
16
|
|
|
from zope.interface import implements |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
class LabelSchemaExtender(object): |
20
|
|
|
"""Extend schema fields for labeled contents |
21
|
|
|
""" |
22
|
|
|
layer = ISenaiteCore |
23
|
|
|
implements( |
24
|
|
|
ISchemaExtender, |
25
|
|
|
IBrowserLayerAwareExtender, |
26
|
|
|
IOrderableSchemaExtender) |
27
|
|
|
adapts(ICanHaveLabels) |
28
|
|
|
|
29
|
|
|
fields = [ |
30
|
|
|
# Labels |
31
|
|
|
ExtLabelField( |
32
|
|
|
AT_LABEL_FIELD, |
33
|
|
|
required=False, |
34
|
|
|
mode="rw", |
35
|
|
|
schemata="Labels", |
36
|
|
|
read_permission=permissions.View, |
37
|
|
|
write_permission=permissions.ModifyPortalContent, |
38
|
|
|
widget=QuerySelectWidget( |
39
|
|
|
label=_("Labels"), |
40
|
|
|
description=_("Attached labels"), |
41
|
|
|
render_own_label=False, |
42
|
|
|
catalog=SETUP_CATALOG, |
43
|
|
|
search_index="Title", |
44
|
|
|
value_key="title", |
45
|
|
|
search_wildcard=True, |
46
|
|
|
multi_valued=True, |
47
|
|
|
allow_user_value=True, |
48
|
|
|
hide_input_after_select=False, |
49
|
|
|
i18n_domain="senaite.core", |
50
|
|
|
query={ |
51
|
|
|
"portal_type": "Label", |
52
|
|
|
"is_active": True, |
53
|
|
|
"sort_on": "title", |
54
|
|
|
}, |
55
|
|
|
columns=[ |
56
|
|
|
{ |
57
|
|
|
"name": "title", |
58
|
|
|
"width": "100", |
59
|
|
|
"align": "left", |
60
|
|
|
"label": _(u"Label"), |
61
|
|
|
}, |
62
|
|
|
], |
63
|
|
|
display_template="<a href='${url}'>${title}</a>", |
64
|
|
|
limit=5, |
65
|
|
|
) |
66
|
|
|
), |
67
|
|
|
] |
68
|
|
|
|
69
|
|
|
def __init__(self, context): |
70
|
|
|
self.context = context |
71
|
|
|
|
72
|
|
|
def getFields(self): |
73
|
|
|
return self.fields |
74
|
|
|
|
75
|
|
|
def getOrder(self, original): |
76
|
|
|
"""Change the order of the extended fields |
77
|
|
|
""" |
78
|
|
|
return original |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
class LabelSchemaModifier(object): |
82
|
|
|
"""Rearrange schema fields |
83
|
|
|
""" |
84
|
|
|
layer = ISenaiteCore |
85
|
|
|
implements( |
86
|
|
|
ISchemaModifier, |
87
|
|
|
IBrowserLayerAwareExtender) |
88
|
|
|
adapts(ICanHaveLabels) |
89
|
|
|
|
90
|
|
|
def __init__(self, context): |
91
|
|
|
self.context = context |
92
|
|
|
|
93
|
|
|
def fiddle(self, schema): |
94
|
|
|
return schema |
95
|
|
|
|