1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# |
3
|
|
|
# This file is part of SENAITE.HEALTH. |
4
|
|
|
# |
5
|
|
|
# SENAITE.HEALTH is free software: you can redistribute it and/or modify it |
6
|
|
|
# under the terms of the GNU General Public License as published by the Free |
7
|
|
|
# Software 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-2019 by it's authors. |
19
|
|
|
# Some rights reserved, see README and LICENSE. |
20
|
|
|
|
21
|
|
|
"""Generic field extensions""" |
22
|
|
|
|
23
|
|
|
from Products.Archetypes.public import * |
24
|
|
|
from archetypes.schemaextender.field import ExtensionField |
25
|
|
|
from Products.ATExtensions.ateapi import RecordField, RecordsField |
26
|
|
|
from Products.ATExtensions.ateapi import DateTimeField |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
class field_getter: |
30
|
|
|
"Used to mimic the Archetypes automatically generated accessor" |
31
|
|
|
|
32
|
|
|
def __init__(self, context, fieldname): |
33
|
|
|
self.context = context |
34
|
|
|
self.fieldname = fieldname |
35
|
|
|
|
36
|
|
|
def __call__(self): |
37
|
|
|
return self.context.Schema()[self.fieldname].getAccessor(self.context)() |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
class field_setter: |
41
|
|
|
"Used to mimic the Archetypes automatically generated mutator" |
42
|
|
|
|
43
|
|
|
def __init__(self, context, fieldname): |
44
|
|
|
self.context = context |
45
|
|
|
self.fieldname = fieldname |
46
|
|
|
|
47
|
|
|
def __call__(self, value): |
48
|
|
|
return self.context.Schema()[self.fieldname].getMutator(self.context)(value) |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
class ExtBooleanField(ExtensionField, BooleanField): |
|
|
|
|
52
|
|
|
"Field extender" |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
class ExtComputedField(ExtensionField, ComputedField): |
|
|
|
|
56
|
|
|
"Field extender" |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
class ExtDateTimeField(ExtensionField, DateTimeField): |
60
|
|
|
"Field extender" |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
class ExtIntegerField(ExtensionField, IntegerField): |
|
|
|
|
64
|
|
|
"Field extender" |
65
|
|
|
|
66
|
|
|
class ExtLinesField(ExtensionField, LinesField): |
|
|
|
|
67
|
|
|
"Field extender" |
68
|
|
|
|
69
|
|
|
class ExtRecordField(ExtensionField, RecordField): |
70
|
|
|
"Field extender" |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
class ExtRecordsField(ExtensionField, RecordsField): |
74
|
|
|
"Field extender" |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
class ExtReferenceField(ExtensionField, ReferenceField): |
|
|
|
|
78
|
|
|
"Field extender" |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
class ExtStringField(ExtensionField, StringField): |
|
|
|
|
82
|
|
|
"Field extender" |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
class ExtTextField(ExtensionField, TextField): |
|
|
|
|
86
|
|
|
"Field extender" |
87
|
|
|
|