yafowil.widget.autocomplete 1.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- yafowil/widget/autocomplete/__init__.py +69 -0
- yafowil/widget/autocomplete/example.py +127 -0
- yafowil/widget/autocomplete/resources/jquery.ui.autocomplete.bootstrap.css +16 -0
- yafowil/widget/autocomplete/resources/jquery.ui.autocomplete.css +16 -0
- yafowil/widget/autocomplete/resources/jquery.ui.autocomplete.js +610 -0
- yafowil/widget/autocomplete/resources/jquery.ui.autocomplete.min.js +4 -0
- yafowil/widget/autocomplete/resources/jquery.ui.autocomplete.plone5.css +16 -0
- yafowil/widget/autocomplete/resources/jquery.ui.menu.bootstrap.css +127 -0
- yafowil/widget/autocomplete/resources/jquery.ui.menu.css +79 -0
- yafowil/widget/autocomplete/resources/jquery.ui.menu.js +621 -0
- yafowil/widget/autocomplete/resources/jquery.ui.menu.min.js +4 -0
- yafowil/widget/autocomplete/resources/jquery.ui.menu.plone5.css +127 -0
- yafowil/widget/autocomplete/resources/widget.css +3 -0
- yafowil/widget/autocomplete/resources/widget.js +97 -0
- yafowil/widget/autocomplete/tests.py +129 -0
- yafowil/widget/autocomplete/widget.py +80 -0
- yafowil.widget.autocomplete-1.8-py3.9-nspkg.pth +2 -0
- yafowil_widget_autocomplete-1.8.dist-info/METADATA +194 -0
- yafowil_widget_autocomplete-1.8.dist-info/RECORD +24 -0
- yafowil_widget_autocomplete-1.8.dist-info/WHEEL +5 -0
- yafowil_widget_autocomplete-1.8.dist-info/entry_points.txt +3 -0
- yafowil_widget_autocomplete-1.8.dist-info/licenses/LICENSE.rst +27 -0
- yafowil_widget_autocomplete-1.8.dist-info/namespace_packages.txt +2 -0
- yafowil_widget_autocomplete-1.8.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from yafowil.base import factory
|
|
2
|
+
from yafowil.utils import entry_point
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
resourcedir = os.path.join(os.path.dirname(__file__), 'resources')
|
|
7
|
+
js = [{
|
|
8
|
+
'group': 'yafowil.widget.autocomplete.dependencies',
|
|
9
|
+
'resource': 'jquery.ui.menu.min.js',
|
|
10
|
+
'order': 20,
|
|
11
|
+
}, {
|
|
12
|
+
'group': 'yafowil.widget.autocomplete.dependencies',
|
|
13
|
+
'resource': 'jquery.ui.autocomplete.min.js',
|
|
14
|
+
'order': 20,
|
|
15
|
+
}, {
|
|
16
|
+
'group': 'yafowil.widget.autocomplete.common',
|
|
17
|
+
'resource': 'widget.js',
|
|
18
|
+
'order': 21,
|
|
19
|
+
}]
|
|
20
|
+
default_css = [{
|
|
21
|
+
'group': 'yafowil.widget.autocomplete.dependencies',
|
|
22
|
+
'resource': 'jquery.ui.menu.css',
|
|
23
|
+
'order': 20,
|
|
24
|
+
}, {
|
|
25
|
+
'group': 'yafowil.widget.autocomplete.dependencies',
|
|
26
|
+
'resource': 'jquery.ui.autocomplete.css',
|
|
27
|
+
'order': 20,
|
|
28
|
+
}, {
|
|
29
|
+
'group': 'yafowil.widget.autocomplete.common',
|
|
30
|
+
'resource': 'widget.css',
|
|
31
|
+
'order': 21,
|
|
32
|
+
}]
|
|
33
|
+
bootstrap_css = [{
|
|
34
|
+
'group': 'yafowil.widget.autocomplete.dependencies',
|
|
35
|
+
'resource': 'jquery.ui.menu.bootstrap.css',
|
|
36
|
+
'order': 20,
|
|
37
|
+
}, {
|
|
38
|
+
'group': 'yafowil.widget.autocomplete.dependencies',
|
|
39
|
+
'resource': 'jquery.ui.autocomplete.bootstrap.css',
|
|
40
|
+
'order': 20,
|
|
41
|
+
}, {
|
|
42
|
+
'group': 'yafowil.widget.autocomplete.common',
|
|
43
|
+
'resource': 'widget.css',
|
|
44
|
+
'order': 21,
|
|
45
|
+
}]
|
|
46
|
+
plone5_css = [{
|
|
47
|
+
'group': 'yafowil.widget.autocomplete.dependencies',
|
|
48
|
+
'resource': 'jquery.ui.menu.plone5.css',
|
|
49
|
+
'order': 20,
|
|
50
|
+
}, {
|
|
51
|
+
'group': 'yafowil.widget.autocomplete.dependencies',
|
|
52
|
+
'resource': 'jquery.ui.autocomplete.plone5.css',
|
|
53
|
+
'order': 20,
|
|
54
|
+
}, {
|
|
55
|
+
'group': 'yafowil.widget.autocomplete.common',
|
|
56
|
+
'resource': 'widget.css',
|
|
57
|
+
'order': 21,
|
|
58
|
+
}]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@entry_point(order=10)
|
|
62
|
+
def register():
|
|
63
|
+
from yafowil.widget.autocomplete import widget # noqa
|
|
64
|
+
factory.register_theme('default', 'yafowil.widget.autocomplete',
|
|
65
|
+
resourcedir, js=js, css=default_css)
|
|
66
|
+
factory.register_theme('bootstrap', 'yafowil.widget.autocomplete',
|
|
67
|
+
resourcedir, js=js, css=bootstrap_css)
|
|
68
|
+
factory.register_theme('plone5', 'yafowil.widget.autocomplete',
|
|
69
|
+
resourcedir, js=js, css=plone5_css)
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
from yafowil.base import factory
|
|
2
|
+
from yafowil.compat import IS_PY2
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
if IS_PY2:
|
|
7
|
+
from urlparse import urlparse
|
|
8
|
+
from urlparse import parse_qs
|
|
9
|
+
else:
|
|
10
|
+
from urllib.parse import urlparse
|
|
11
|
+
from urllib.parse import parse_qs
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
lipsum = """Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
|
|
15
|
+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
|
|
16
|
+
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
|
|
17
|
+
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
|
|
18
|
+
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
|
|
19
|
+
sunt in culpa qui officia deserunt mollit anim id est laborum."""
|
|
20
|
+
lipsum = sorted(set(lipsum.lower().replace('.', '').replace(',', '').split()))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def json_response(url):
|
|
24
|
+
purl = urlparse(url)
|
|
25
|
+
qs = parse_qs(purl.query)
|
|
26
|
+
data = json_data(qs.get('term', [''])[0])
|
|
27
|
+
return {
|
|
28
|
+
'body': json.dumps(data),
|
|
29
|
+
'header': [('Content-Type', 'application/json')]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def json_data(term):
|
|
34
|
+
data = lipsum
|
|
35
|
+
if term:
|
|
36
|
+
data = [_ for _ in data if _.startswith(term)]
|
|
37
|
+
return data
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
DOC_STATIC = """\
|
|
41
|
+
Autocomplete with static vocabulary
|
|
42
|
+
-----------------------------------
|
|
43
|
+
|
|
44
|
+
Autocomplete can make use of a static vocabulary source. Here words of blind
|
|
45
|
+
text Lorem Ipsum are used. First the static list of words is generated
|
|
46
|
+
|
|
47
|
+
.. code-block:: python
|
|
48
|
+
|
|
49
|
+
lipsum = '''Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
|
|
50
|
+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
|
|
51
|
+
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
|
|
52
|
+
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit
|
|
53
|
+
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
|
|
54
|
+
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
|
|
55
|
+
est laborum.'''
|
|
56
|
+
lipsum = sorted(set(lipsum.lower().replace('.', '').replace(',', '').split()))
|
|
57
|
+
|
|
58
|
+
Next, the field is defined as
|
|
59
|
+
|
|
60
|
+
.. code-block:: python
|
|
61
|
+
|
|
62
|
+
field = factory('#field:autocomplete', props={
|
|
63
|
+
'label': 'Enter some text (local, lorem ipsum)',
|
|
64
|
+
'value': '',
|
|
65
|
+
'source': lipsum,
|
|
66
|
+
})
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
DOC_JSON = """\
|
|
70
|
+
Autocomplete with dynamic json vocabulary
|
|
71
|
+
-----------------------------------------
|
|
72
|
+
|
|
73
|
+
Instead of static lists autocomplete may ask the server for a list of words
|
|
74
|
+
matching a given term. The source is a string and as such interpreted as a
|
|
75
|
+
absolute or relative url
|
|
76
|
+
|
|
77
|
+
.. code-block:: python
|
|
78
|
+
|
|
79
|
+
field = factory('#field:autocomplete', props={
|
|
80
|
+
'label': 'Enter some text (remote listdir)',
|
|
81
|
+
'value': '',
|
|
82
|
+
'source': 'yafowil.widget.autocomplete.json',
|
|
83
|
+
'minLength': 1,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
The server answers with a JSON response, here the example does it using WSGI
|
|
87
|
+
and ``webob`` way. This code needs modification depending on the framework
|
|
88
|
+
used
|
|
89
|
+
|
|
90
|
+
.. code-block:: python
|
|
91
|
+
|
|
92
|
+
def json_response(environ, start_response):
|
|
93
|
+
data = lipsum
|
|
94
|
+
if environ['QUERY_STRING'].startswith('term='):
|
|
95
|
+
qsts = environ['QUERY_STRING'][5:]
|
|
96
|
+
data = [_ for _ in data if _.startswith(qsts)]
|
|
97
|
+
response = Response(content_type='application/json',
|
|
98
|
+
body=json.dumps(data))
|
|
99
|
+
return response(environ, start_response)
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def get_example():
|
|
104
|
+
static_ac = factory('#field:autocomplete', name='static', props={
|
|
105
|
+
'label': 'Enter some text (local, lorem ipsum)',
|
|
106
|
+
'value': '',
|
|
107
|
+
'source': lipsum,
|
|
108
|
+
})
|
|
109
|
+
json_ac = factory('#field:autocomplete', name='json', props={
|
|
110
|
+
'label': 'Enter some text (remote listdir)',
|
|
111
|
+
'value': '',
|
|
112
|
+
'source': 'yafowil.widget.autocomplete.json',
|
|
113
|
+
'minLength': 1,
|
|
114
|
+
})
|
|
115
|
+
routes = {
|
|
116
|
+
'yafowil.widget.autocomplete.json': json_response,
|
|
117
|
+
}
|
|
118
|
+
return [{
|
|
119
|
+
'widget': static_ac,
|
|
120
|
+
'doc': DOC_STATIC,
|
|
121
|
+
'title': 'Static autocomplete',
|
|
122
|
+
}, {
|
|
123
|
+
'widget': json_ac,
|
|
124
|
+
'routes': routes,
|
|
125
|
+
'doc': DOC_JSON,
|
|
126
|
+
'title': 'JSON data autocomplete',
|
|
127
|
+
}]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* jQuery UI Autocomplete 1.10.3
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2013, AUTHORS.txt (http://jqueryui.com/about)
|
|
5
|
+
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
6
|
+
* http://jquery.org/license
|
|
7
|
+
*
|
|
8
|
+
* http://jqueryui.com/autocomplete/
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
.ui-autocomplete {
|
|
12
|
+
position: absolute;
|
|
13
|
+
top: 0;
|
|
14
|
+
left: 0;
|
|
15
|
+
cursor: default;
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* jQuery UI Autocomplete 1.10.3
|
|
3
|
+
* http://jqueryui.com
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2013 jQuery Foundation and other contributors
|
|
6
|
+
* Released under the MIT license.
|
|
7
|
+
* http://jquery.org/license
|
|
8
|
+
*
|
|
9
|
+
* http://docs.jquery.com/UI/Autocomplete#theming
|
|
10
|
+
*/
|
|
11
|
+
.ui-autocomplete {
|
|
12
|
+
position: absolute;
|
|
13
|
+
top: 0;
|
|
14
|
+
left: 0;
|
|
15
|
+
cursor: default;
|
|
16
|
+
}
|