Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to HTML time input for Time field #595

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions sqladmin/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"QuerySelectMultipleField",
"SelectField",
"Select2TagsField",
"TimeField",
]


Expand All @@ -39,14 +38,6 @@ class DateTimeField(fields.DateTimeField):
widget = sqladmin_widgets.DateTimePickerWidget()


class TimeField(fields.TimeField):
"""
A text field which stores a `datetime.time` object.
"""

widget = sqladmin_widgets.TimePickerWidget()


class IntervalField(fields.StringField):
"""
A text field which stores a `datetime.timedelta` object.
Expand Down
2 changes: 1 addition & 1 deletion sqladmin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
IntegerField,
StringField,
TextAreaField,
TimeField,
validators,
)
from wtforms.fields.core import UnboundField
Expand All @@ -57,7 +58,6 @@
QuerySelectMultipleField,
Select2TagsField,
SelectField,
TimeField,
)
from sqladmin.helpers import (
choice_type_coerce_factory,
Expand Down
12 changes: 0 additions & 12 deletions sqladmin/statics/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,6 @@ $(':input[data-role="datetimepicker"]:not([readonly])').each(function () {
});
});

// Time picker
$(':input[data-role="timepicker"]:not([readonly])').each(function () {
$(this).flatpickr({
noCalendar: true,
enableTime: true,
allowInput: true,
enableSeconds: true,
time_24hr: true,
dateFormat: "H:i:s",
});
});

// Ajax Refs
$(':input[data-role="select2-ajax"]').each(function () {
$(this).select2({
Expand Down
11 changes: 0 additions & 11 deletions sqladmin/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"DatePickerWidget",
"DateTimePickerWidget",
"Select2TagsWidget",
"TimePickerWidget",
]


Expand All @@ -34,16 +33,6 @@ def __call__(self, field: Field, **kwargs: Any) -> str:
return super().__call__(field, **kwargs)


class TimePickerWidget(widgets.TextInput):
"""
Time picker widget.
"""

def __call__(self, field: Field, **kwargs: Any) -> str:
kwargs.setdefault("data-role", "timepicker")
return super().__call__(field, **kwargs)


class AjaxSelect2Widget(widgets.Select):
def __init__(self, multiple: bool = False):
self.multiple = multiple
Expand Down
18 changes: 0 additions & 18 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
QuerySelectMultipleField,
Select2TagsField,
SelectField,
TimeField,
)
from tests.common import DummyData
from tests.common import sync_engine as engine
Expand Down Expand Up @@ -63,23 +62,6 @@ class F(Form):
assert form.datetime.data == datetime(2021, 12, 22, 12, 30, 0, 0)


def test_time_field() -> None:
class F(Form):
time = TimeField()

form = F()
assert 'data-role="timepicker"' in form.time()

form = F(DummyData(time=["12:30"]))
assert form.time.data == datetime(2021, 12, 22, 12, 30, 0, 0).time()

form = F(DummyData(time=["Invalid"]))
assert form.time.data is None

form = F(DummyData(time=[""]))
assert form.time.data is None


def test_json_field() -> None:
class F(Form):
json = JSONField()
Expand Down