Skip to content

Commit

Permalink
Fix filtereing by multiple fields (#10832)
Browse files Browse the repository at this point in the history
* Fix filtereing by multiple fields

* remove comments

* update changelog

* flake
  • Loading branch information
p0psicles committed Jul 19, 2022
1 parent 135a704 commit efc784a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Fixed borders in tables where diplay: flex is used on a table cell. ([10813](https://github.com/pymedusa/Medusa/pull/10813))
- Fix keys for caching recommended shows in recommended.dbm. ([10827](https://github.com/pymedusa/Medusa/pull/10827))
- Fix using download handler with deluge / deluged. ([10828](https://github.com/pymedusa/Medusa/pull/10828))
- History page: Fix filtering by multiple fields ([10832](https://github.com/pymedusa/Medusa/pull/10832))

## 1.0.5 (06-07-2022)

Expand Down
29 changes: 22 additions & 7 deletions medusa/server/api/v2/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
from __future__ import unicode_literals

import json
import logging
from os.path import basename

from medusa import db
from medusa.common import DOWNLOADED, FAILED, SNATCHED, SUBTITLED, statusStrings
from medusa.indexers.utils import indexer_id_to_name
from medusa.logger.adapters.style import BraceAdapter
from medusa.providers import get_provider_class
from medusa.providers.generic_provider import GenericProvider
from medusa.schedulers.download_handler import ClientStatus
from medusa.server.api.v2.base import BaseRequestHandler
from medusa.tv.series import Series, SeriesIdentifier


log = BraceAdapter(logging.getLogger(__name__))
log.logger.addHandler(logging.NullHandler())


class HistoryHandler(BaseRequestHandler):
"""History request handler."""

Expand Down Expand Up @@ -60,6 +66,7 @@ def get(self, series_slug, path_param):
return self._ok(data=results[0])

where = []
where_with_ops = []

if series_slug is not None:
series_identifier = SeriesIdentifier.from_slug(series_slug)
Expand Down Expand Up @@ -102,24 +109,32 @@ def get(self, series_slug, path_param):
where += [filter_field]
params += [filter_value]

if where:
sql_base += ' WHERE ' + ' AND '.join(f'{item} = ?' for item in where)

# Add size query (with operator)
if size_operator and size:
sql_base += f' {"AND" if where else "WHERE"} size {size_operator} ?'
params.append(int(size) * 1024 * 1024)
try:
size = int(size) * 1024 * 1024
where_with_ops += [f' size {size_operator} ? ']
params.append(size)
except ValueError:
log.info('Could not parse {size} into a valid number', {'size': size})

# Add provider with like %provider%
if provider:
sql_base += f' {"AND" if where else "WHERE"} provider LIKE ?'
where_with_ops += [' provider LIKE ? ']
params.append(f'%%{provider}%%')

# Search resource with like %resource%
if resource:
sql_base += f' {"AND" if where else "WHERE"} resource LIKE ?'
where_with_ops += [' resource LIKE ? ']
params.append(f'%%{resource}%%')

if where:
sql_base += ' WHERE ' + ' AND '.join(f'{item} = ?' for item in where)

if where_with_ops:
sql_base += ' WHERE ' if not where else ' AND '
sql_base += ' AND '.join(where_with_ops)

if sort is not None and len(sort) == 1: # Only support one sort column right now.
field = sort[0].get('field').lower()
order = sort[0].get('type')
Expand Down
1 change: 1 addition & 0 deletions themes-default/slim/src/components/history-detailed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ export default {
// Check for valid syntax, and pass along.
size = size.currentTarget.value;
if (!size) {
this.remoteHistory.filter.columnFilters.size = size;
this.loadItemsDebounced();
return;
}
Expand Down
Loading

0 comments on commit efc784a

Please sign in to comment.