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

Combined search not working if table contains searchable Date(Time)Fields #131

Open
IceQ1337 opened this issue Sep 19, 2024 · 0 comments
Open

Comments

@IceQ1337
Copy link

IceQ1337 commented Sep 19, 2024

The request to filter the table by multiple search values currently fails if the table contains one or more searchable DateFields or DateTimeFields. This is reproducable with the albums demo table.

During filtering, the list of search values is passed to parse_date(), but that function does not seem to properly account for it and will throw an unavoidable TypeError.

parsed_date = parse_date(search_value)

parsed_date = datetime.datetime.strptime(formatted_date, date_format)

Stacktrace:

Traceback (most recent call last):
  File "/usr/src/app/xxx/views/datatables.py", line 141, in xxx_datatable
    return xxxAjaxDatatableView.as_view()(request)
  File "/root/.cache/pypoetry/virtualenvs/non-package-mode-VA82Wl8V-py3.10/lib/python3.10/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
  File "/root/.cache/pypoetry/virtualenvs/non-package-mode-VA82Wl8V-py3.10/lib/python3.10/site-packages/django/utils/decorators.py", line 48, in _wrapper
    return bound_method(*args, **kwargs)
  File "/root/.cache/pypoetry/virtualenvs/non-package-mode-VA82Wl8V-py3.10/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
    return view_func(request, *args, **kwargs)
  File "/root/.cache/pypoetry/virtualenvs/non-package-mode-VA82Wl8V-py3.10/lib/python3.10/site-packages/ajax_datatable/views.py", line 411, in dispatch
    response = super(AjaxDatatableView, self).dispatch(request, *args, **kwargs)
  File "/root/.cache/pypoetry/virtualenvs/non-package-mode-VA82Wl8V-py3.10/lib/python3.10/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
  File "/root/.cache/pypoetry/virtualenvs/non-package-mode-VA82Wl8V-py3.10/lib/python3.10/site-packages/ajax_datatable/views.py", line 514, in post
    return self.get(request, *args, **kwargs)
  File "/root/.cache/pypoetry/virtualenvs/non-package-mode-VA82Wl8V-py3.10/lib/python3.10/site-packages/ajax_datatable/views.py", line 552, in get
    qs = self.prepare_queryset(params, qs)
  File "/root/.cache/pypoetry/virtualenvs/non-package-mode-VA82Wl8V-py3.10/lib/python3.10/site-packages/ajax_datatable/views.py", line 821, in prepare_queryset
    qs = self.filter_queryset(params, qs)
  File "/root/.cache/pypoetry/virtualenvs/non-package-mode-VA82Wl8V-py3.10/lib/python3.10/site-packages/ajax_datatable/views.py", line 831, in filter_queryset
    qs = self.filter_queryset_all_columns(params['search_value'], qs)
  File "/root/.cache/pypoetry/virtualenvs/non-package-mode-VA82Wl8V-py3.10/lib/python3.10/site-packages/ajax_datatable/views.py", line 897, in filter_queryset_all_columns
    return self._filter_queryset(searchable_columns, search_value, qs, True)
  File "/root/.cache/pypoetry/virtualenvs/non-package-mode-VA82Wl8V-py3.10/lib/python3.10/site-packages/ajax_datatable/views.py", line 880, in _filter_queryset
    column_filter = build_column_filter(column_name, column_obj, column_spec, search_value, global_filtering)
  File "/root/.cache/pypoetry/virtualenvs/non-package-mode-VA82Wl8V-py3.10/lib/python3.10/site-packages/ajax_datatable/filters.py", line 46, in build_column_filter
    parsed_date = parse_date(search_value)
  File "/root/.cache/pypoetry/virtualenvs/non-package-mode-VA82Wl8V-py3.10/lib/python3.10/site-packages/ajax_datatable/utils.py", line 131, in parse_date
    parsed_date = datetime.datetime.strptime(formatted_date, date_format)
TypeError: strptime() argument 1 must be str, not list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant