Coverage for apis_core/apis_entities/fields.py: 56%
41 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:51 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:51 +0000
1from dal.autocomplete import ListSelect2 as DALListSelect2
2from dal.autocomplete import ModelSelect2 as DALModelSelect2
3from dal.autocomplete import ModelSelect2Multiple as DALModelSelect2Multiple
4from dal.autocomplete import Select2 as DALSelect2
5from dal.autocomplete import Select2Multiple as DALSelect2Multiple
6from dal.autocomplete import TagSelect2 as DALTagSelect2
7from dal_select2.widgets import Select2WidgetMixin as DALSelect2WidgetMixin
8from django import forms
11# "Rewrite" select2 widgets from Django Autocomplete Light so
12# that they don't use Django's admin-provided jQuery, which
13# causes errors with jQuery provided by us.
14class Select2WidgetMixin(DALSelect2WidgetMixin):
15 @property
16 def media(self):
17 m = super().media
18 js = list(m._js)
19 css = list(m._css["screen"])
20 js_remove_list = [
21 "admin/js/vendor/jquery/jquery.js",
22 "admin/js/vendor/jquery/jquery.min.js",
23 "autocomplete_light/jquery.post-setup.js",
24 "admin/js/vendor/select2/select2.full.js",
25 "admin/js/vendor/select2/select2.full.min.js",
26 "admin/js/vendor/select2/i18n/en.js",
27 ]
28 css_remove_list = [
29 "admin/css/vendor/select2/select2.css",
30 "admin/css/vendor/select2/select2.min.css",
31 "admin/css/autocomplete.css",
32 ]
33 for e in js_remove_list:
34 try:
35 js.remove(e)
36 except ValueError:
37 pass
38 for e in css_remove_list:
39 try:
40 css.remove(e)
41 except ValueError:
42 pass
44 js.append(
45 "https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.full.min.js"
46 )
47 css.insert(
48 0,
49 "https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/css/select2.min.css",
50 )
51 return forms.Media(css={"screen": css}, js=js)
54class Select2(Select2WidgetMixin, DALSelect2):
55 pass
58class TagSelect2(Select2WidgetMixin, DALTagSelect2):
59 pass
62class Select2Multiple(Select2WidgetMixin, DALSelect2Multiple):
63 pass
66class ListSelect2(Select2WidgetMixin, DALListSelect2):
67 pass
70class ModelSelect2(Select2WidgetMixin, DALModelSelect2):
71 pass
74class ModelSelect2Multiple(Select2WidgetMixin, DALModelSelect2Multiple):
75 pass