1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-05 21:45:25 +02:00

feat: mealplan-webhooks (#1403)

* fix type errors on event bus

* webhooks fields required for new implementation

* db migration

* wip: webhook query + tests and stub function

* ignore type checker error

* type and method cleanup

* datetime and time utc validator

* update testing code for utc scheduled time

* fix file cmp function call

* update version_number

* add support for translating "time" objects when restoring backup

* bump recipe-scrapers

* use specific import syntax

* generate frontend types

* utilize names exports

* use utc times

* add task to scheduler

* implement new scheduler functionality

* stub for type annotation

* implement meal-plan data getter

* add experimental banner
This commit is contained in:
Hayden 2022-06-17 13:25:47 -08:00 committed by GitHub
parent b1256f4ad2
commit 5a053cdcd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 428 additions and 93 deletions

View file

@ -9,4 +9,4 @@ from .group_seeder import *
from .group_shopping_list import *
from .group_statistics import *
from .invite_token import *
from .webhook import *
from .webhook import * # type: ignore

View file

@ -1,15 +1,51 @@
import datetime
import enum
from uuid import UUID
from pydantic import UUID4
from isodate import parse_time
from pydantic import UUID4, validator
from pydantic.datetime_parse import parse_datetime
from mealie.schema._mealie import MealieModel
class WebhookType(str, enum.Enum):
mealplan = "mealplan"
class CreateWebhook(MealieModel):
enabled: bool = True
name: str = ""
url: str = ""
time: str = "00:00"
webhook_type: WebhookType = WebhookType.mealplan
scheduled_time: datetime.time
@validator("scheduled_time", pre=True)
@classmethod
def validate_scheduled_time(cls, v):
"""
Validator accepts both datetime and time values from external sources.
DateTime types are parsed and converted to time objects without timezones
type: time is treated as a UTC value
type: datetime is treated as a value with a timezone
"""
parser_funcs = [
lambda x: parse_datetime(x).astimezone(datetime.timezone.utc).time(),
parse_time,
]
if isinstance(v, datetime.time):
return v
for parser_func in parser_funcs:
try:
return parser_func(v)
except ValueError:
continue
raise ValueError(f"Invalid scheduled time: {v}")
class SaveWebhook(CreateWebhook):