kopia lustrzana https://github.com/wagtail/wagtail
Move button select widgets to wagtail.admin.widgets
rodzic
19609ebd4d
commit
35c55091af
|
@ -4,52 +4,9 @@ from django.utils.translation import gettext_lazy as _
|
|||
from django_filters.widgets import SuffixedMultiWidget
|
||||
|
||||
from wagtail.admin.staticfiles import versioned_static
|
||||
from wagtail.admin.widgets import AdminDateInput, BooleanButtonSelect, ButtonSelect
|
||||
from wagtail.core.models import Page, Task, TaskState, Workflow, WorkflowState
|
||||
|
||||
from .widgets import AdminDateInput
|
||||
|
||||
|
||||
class ButtonSelect(forms.Select):
|
||||
"""
|
||||
A select widget for fields with choices. Displays as a list of buttons.
|
||||
"""
|
||||
input_type = 'hidden'
|
||||
template_name = 'wagtailadmin/widgets/button_select.html'
|
||||
option_template_name = 'wagtailadmin/widgets/button_select_option.html'
|
||||
|
||||
|
||||
class BooleanButtonSelect(ButtonSelect):
|
||||
"""
|
||||
A select widget for boolean fields. Displays as three buttons. "All", "Yes" and "No".
|
||||
"""
|
||||
def __init__(self, attrs=None):
|
||||
choices = (
|
||||
('', _("All")),
|
||||
('true', _("Yes")),
|
||||
('false', _("No")),
|
||||
)
|
||||
super().__init__(attrs, choices)
|
||||
|
||||
def format_value(self, value):
|
||||
try:
|
||||
return {
|
||||
True: ['true'], False: ['false'],
|
||||
'true': ['true'], 'false': ['false'],
|
||||
}[value]
|
||||
except KeyError:
|
||||
return ''
|
||||
|
||||
def value_from_datadict(self, data, files, name):
|
||||
value = data.get(name)
|
||||
return {
|
||||
True: True,
|
||||
'True': True,
|
||||
'False': False,
|
||||
False: False,
|
||||
'true': True,
|
||||
'false': False,
|
||||
}.get(value)
|
||||
|
||||
|
||||
class DateRangePickerWidget(SuffixedMultiWidget):
|
||||
"""
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from wagtail.admin.widgets.auto_height_text import * # NOQA
|
||||
from wagtail.admin.widgets.button import * # NOQA
|
||||
from wagtail.admin.widgets.button_select import * # NOQA
|
||||
from wagtail.admin.widgets.chooser import * # NOQA
|
||||
from wagtail.admin.widgets.datetime import * # NOQA
|
||||
from wagtail.admin.widgets.tags import * # NOQA
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class ButtonSelect(forms.Select):
|
||||
"""
|
||||
A select widget for fields with choices. Displays as a list of buttons.
|
||||
"""
|
||||
input_type = 'hidden'
|
||||
template_name = 'wagtailadmin/widgets/button_select.html'
|
||||
option_template_name = 'wagtailadmin/widgets/button_select_option.html'
|
||||
|
||||
|
||||
class BooleanButtonSelect(ButtonSelect):
|
||||
"""
|
||||
A select widget for boolean fields. Displays as three buttons. "All", "Yes" and "No".
|
||||
"""
|
||||
def __init__(self, attrs=None):
|
||||
choices = (
|
||||
('', _("All")),
|
||||
('true', _("Yes")),
|
||||
('false', _("No")),
|
||||
)
|
||||
super().__init__(attrs, choices)
|
||||
|
||||
def format_value(self, value):
|
||||
try:
|
||||
return {
|
||||
True: ['true'], False: ['false'],
|
||||
'true': ['true'], 'false': ['false'],
|
||||
}[value]
|
||||
except KeyError:
|
||||
return ''
|
||||
|
||||
def value_from_datadict(self, data, files, name):
|
||||
value = data.get(name)
|
||||
return {
|
||||
True: True,
|
||||
'True': True,
|
||||
'False': False,
|
||||
False: False,
|
||||
'true': True,
|
||||
'false': False,
|
||||
}.get(value)
|
Ładowanie…
Reference in New Issue