widget.py
4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import json
import logging
from deform.widget import (
SchemaType,
DateInputWidget as DeformDateInputWidget,
default_resources, ResourceRegistry, default_resource_registry)
from colander import null, Invalid
_logging = logging.getLogger(__name__)
class _FieldStorage(SchemaType):
def deserialize(self, node, cstruct):
if cstruct in (null, None, '', b''):
return null
# weak attempt at duck-typing
if not hasattr(cstruct, 'file'):
raise Invalid(node, "%s is not a FieldStorage instance" % cstruct)
return cstruct
# class DateInputWidget(DeformDateInputWidget):
# """
# Renders a date picker widget.
#
# The default rendering is as a native HTML5 date input widget,
# falling back to pickadate (https://github.com/amsul/pickadate.js.)
#
# Most useful when the schema node is a ``colander.Date`` object.
#
# **Attributes/Arguments**
#
# options
# Dictionary of options for configuring the widget (eg: date format)
#
# template
# The template name used to render the widget. Default:
# ``dateinput``.
#
# readonly_template
# The template name used to render the widget in read-only mode.
# Default: ``readonly/textinput``.
# """
# requirements = {
# "js": (
# "deform:static/scripts/modernizr.custom.input-types-and-atts.js",
# "static/pickadate/lib/picker.js",
# "static/pickadate/lib/picker.date.js",
# "static/pickadate/lib/picker.time.js",
# "static/pickadate/lib/legacy.js",
# ),
# "css": (
# "static/pickadate/lib/themes/default.css",
# "static/pickadate/lib/themes/default.date.css",
# "static/pickadate/lib/themes/default.time.css",
# ),
# }
# default_options = (
# ("format", "yyyy-mm-dd"),
# ("selectMonths", True),
# ("selectYears", True),
# ("formatSubmit", "yyyy-mm-dd"),
# )
# def serialize(self, field, cstruct, **kw):
# if cstruct in (null, None):
# cstruct = ""
# readonly = kw.get("readonly", self.readonly)
# template = readonly and self.readonly_template or self.template
# options = dict(
# kw.get("options") or self.options or self.default_options
# )
# kw.setdefault("options_json", json.dumps(options))
# values = self.get_template_values(field, cstruct, kw)
# return field.renderer(template, **values)
#
# def deserialize(self, field, pstruct):
# logging.debug(f"widget: {field} {pstruct}")
# if pstruct in ("", null):
# return null
# try:
# validated = self._pstruct_schema.deserialize(pstruct)
# except Invalid as exc:
# raise Invalid(field.schema, "Invalid pstruct: %s" % exc)
# return validated["date_submit"] or validated["date"]
# default_resources["pickadate"] = \
# {
# None: {
# "js": (
# "static/pickadate/lib/picker.js",
# "static/pickadate/lib/picker.date.js",
# "static/pickadate/lib/picker.time.js",
# "static/pickadate/lib/legacy.js",
# ),
# "css": (
# "static/pickadate/lib/themes/default.css",
# "static/pickadate/lib/themes/default.date.css",
# "static/pickadate/lib/themes/default.time.css",
# ),
# }
# }
# default_resources = {
# "jquery.form": {None: {"js": "deform:static/scripts/jquery.form-3.09.js"}},
# "jquery.maskedinput": {
# None: {"js": "deform:static/scripts/jquery.maskedinput-1.3.1.min.js"}
# },
# "jquery.maskMoney": {
# None: {"js": "deform:static/scripts/jquery.maskMoney-3.1.1.min.js"}
# },
# "deform": {
# None: {
# "js": (
# "deform:static/scripts/jquery.form-3.09.js",
# "deform:static/scripts/deform.js",
# )
# }
# },
# "typeahead": {
# None: {
# "js": "deform:static/scripts/typeahead.min.js",
# "css": "deform:static/css/typeahead.css",
# }
# },
# "modernizr": {
# None: {
# "js": "deform:static/scripts/modernizr.custom.input-types-and-atts.js" # noQA
# }
# },
# "pickadate": {
# None: {
# "js": (
# "static/pickadate/lib/picker.js",
# "static/pickadate/lib/picker.date.js",
# "static/pickadate/lib/picker.time.js",
# "static/pickadate/lib/legacy.js",
# ),
# "css": (
# "static/pickadate/lib/themes/default.css",
# "static/pickadate/lib/themes/default.date.css",
# "static/pickadate/lib/themes/default.time.css",
# ),
# }
# },
# }
#
# default_resource_registry = ResourceRegistry()