-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1113 from uktrade/chore/remove-custom-markdown-field
Remove custom markdown field
- Loading branch information
Showing
63 changed files
with
2,474 additions
and
2,652 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,39 @@ | ||
import json | ||
from django import forms | ||
|
||
from django import forms | ||
from django.utils.safestring import mark_safe | ||
from wagtail.utils.widgets import WidgetWithScript | ||
|
||
|
||
class MarkdownTextarea(WidgetWithScript, forms.widgets.Textarea): | ||
def __init__(self, **kwargs): | ||
super(MarkdownTextarea, self).__init__(**kwargs) | ||
|
||
def render_js_init(self, id_, name, value): | ||
return 'simplemdeAttach("{0}");'.format(id_) | ||
|
||
@property | ||
def media(self): | ||
return forms.Media( | ||
css={ | ||
'all': ( | ||
'https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css', # NOQA | ||
) | ||
}, | ||
js=( | ||
'https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js', | ||
'core/js/refresh_codemirror.js', | ||
'wagtailadmin/js/page-chooser-modal.js', | ||
) | ||
) | ||
|
||
|
||
class Select2WidgetMediaMixin: | ||
class Media: | ||
css = { | ||
'all': ( | ||
'core/js/select2/select2.css', | ||
'core/js/select2/select2-wagtailadmin.css' | ||
) | ||
} | ||
css = {'all': ('core/js/select2/select2.css', 'core/js/select2/select2-wagtailadmin.css')} | ||
js = ('core/js/select2/select2.min.js',) | ||
|
||
|
||
class Select2RenderWithOptionsMixin: | ||
|
||
def __init__(self, *args, select2_options={}, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.select2_options = select2_options | ||
|
||
def render(self, name, value, attrs=None, renderer=None): | ||
html = super().render(name, value, attrs, renderer) | ||
extra = mark_safe('\n'.join(( | ||
"<script>$(function () {", | ||
" $('select[name=\"{field_name}\"]').select2({options});".format( | ||
field_name=name, options=json.dumps(self.select2_options) | ||
), | ||
"});</script>" | ||
))) | ||
extra = mark_safe( | ||
'\n'.join( | ||
( | ||
"<script>$(function () {", | ||
" $('select[name=\"{field_name}\"]').select2({options});".format( | ||
field_name=name, options=json.dumps(self.select2_options) | ||
), | ||
"});</script>", | ||
) | ||
) | ||
) | ||
return html + extra | ||
|
||
|
||
class Select2Widget( | ||
Select2WidgetMediaMixin, | ||
Select2RenderWithOptionsMixin, | ||
forms.Select | ||
): | ||
class Select2Widget(Select2WidgetMediaMixin, Select2RenderWithOptionsMixin, forms.Select): | ||
pass | ||
|
||
|
||
class Select2MultipleWidget( | ||
Select2WidgetMediaMixin, | ||
Select2RenderWithOptionsMixin, | ||
forms.SelectMultiple | ||
): | ||
class Select2MultipleWidget(Select2WidgetMediaMixin, Select2RenderWithOptionsMixin, forms.SelectMultiple): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.