mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-28 21:15:26 -05:00
feat: additional recipe sort behavior (#1858)
* changed default sort direction for certain attrs * added workaround for filtering out null datetimes * filtered out null-valued results for certain sorts * removed unecessary parse * used minyear instead of 1900
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import re
|
||||
from enum import Enum
|
||||
from typing import Any, TypeVar, cast
|
||||
@@ -96,13 +97,20 @@ class QueryFilter:
|
||||
value: Any = component.value
|
||||
|
||||
if isinstance(attr.type, (sqltypes.Date, sqltypes.DateTime)):
|
||||
try:
|
||||
value = date_parser.parse(component.value)
|
||||
# TODO: add support for IS NULL and IS NOT NULL
|
||||
# in the meantime, this will work for the specific usecase of non-null dates/datetimes
|
||||
if value in ["none", "null"] and component.relational_operator == RelationalOperator.NOTEQ:
|
||||
component.relational_operator = RelationalOperator.GTE
|
||||
value = datetime.datetime(datetime.MINYEAR, 1, 1)
|
||||
|
||||
except ParserError as e:
|
||||
raise ValueError(
|
||||
f"invalid query string: unknown date or datetime format '{component.value}'"
|
||||
) from e
|
||||
else:
|
||||
try:
|
||||
value = date_parser.parse(component.value)
|
||||
|
||||
except ParserError as e:
|
||||
raise ValueError(
|
||||
f"invalid query string: unknown date or datetime format '{component.value}'"
|
||||
) from e
|
||||
|
||||
if isinstance(attr.type, sqltypes.Boolean):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user