Add support for 'group' and 'having' keys in smart filters (#1286)

* Add support for 'group' and 'having' keys in
SmartFilterMixin

- fixes #1285

* Add `group` and `having` fields to `additionalFields` list in `FilteringType` class

- This should allow passing the parsed filters back into `search()`.

Co-Authored-By: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com>

---------

Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com>
This commit is contained in:
Dr.Blank 2023-11-13 13:29:59 -05:00 committed by GitHub
parent 556b4b3da4
commit 4924320715
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -2727,7 +2727,9 @@ class FilteringType(PlexObject):
('id', 'integer', 'Rating Key'),
('index', 'integer', f'{self.type.capitalize()} Number'),
('lastRatedAt', 'date', f'{self.type.capitalize()} Last Rated'),
('updatedAt', 'date', 'Date Updated')
('updatedAt', 'date', 'Date Updated'),
('group', 'string', 'SQL Group By Statement'),
('having', 'string', 'SQL Having Clause')
]
if self.type == 'movie':
@ -2778,11 +2780,14 @@ class FilteringType(PlexObject):
manualFields = []
for field, fieldType, fieldTitle in additionalFields:
if field not in {'group', 'having'}:
field = f"{prefix}{field}"
fieldXML = (
f'<Field key="{prefix}{field}" '
f'<Field key="{field}" '
f'title="{fieldTitle}" '
f'type="{fieldType}"/>'
)
manualFields.append(self._manuallyLoadXML(fieldXML, FilteringField))
return manualFields

View file

@ -116,11 +116,14 @@ class SmartFilterMixin:
filtersDict = {}
special_keys = {"type", "sort"}
integer_keys = {"includeGuids", "limit"}
reserved_keys = special_keys | integer_keys
as_is_keys = {"group", "having"}
reserved_keys = special_keys | integer_keys | as_is_keys
while feed:
key, value = feed.popleft()
if key in integer_keys:
filtersDict[key] = int(value)
elif key in as_is_keys:
filtersDict[key] = value
elif key == "type":
filtersDict["libtype"] = utils.reverseSearchType(value)
elif key == "sort":