mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-01-30 20:43:12 -05:00
* Changed uvicorn port to 80 * Changed port in docker-compose to match dockerfile * Readded environment variables in docker-compose * production image rework * Use opengraph metadata to make basic recipe cards when full recipe metadata is not available * fixed instrucitons on parse * add last_recipe * automated testing * roadmap update * Sqlite (#75) * file structure * auto-test * take 2 * refactor ap scheduler and startup process * fixed scraper error * database abstraction * database abstraction * port recipes over to new schema * meal migration * start settings migration * finale mongo port * backup improvements * migration imports to new DB structure * unused import cleanup * docs strings * settings and theme import logic * cleanup * fixed tinydb error * requirements * fuzzy search * remove scratch file * sqlalchemy models * improved search ui * recipe models almost done * sql modal population * del scratch * rewrite database model mixins * mostly grabage * recipe updates * working sqllite * remove old files and reorganize * final cleanup Co-authored-by: Hayden <hay-kot@pm.me> * Backup card (#78) * backup / import dialog * upgrade to new tag method * New import card * rename settings.py to app_config.py * migrate to poetry for development * fix failing test Co-authored-by: Hayden <hay-kot@pm.me> * added mkdocs to docker-compose * Translations (#72) * Translations + danish * changed back proxy target to use ENV * Resolved more merge conflicts * Removed test in translation * Documentation of translations * Updated translations * removed old packages Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com> * fail to start bug fixes * feature: prep/cook/total time slots (#80) Co-authored-by: Hayden <hay-kot@pm.me> * missing bind attributes * Bug fixes (#81) * fix: url remains after succesful import * docs: changelog + update todos * arm image * arm compose * compose updates * update poetry * arm support Co-authored-by: Hayden <hay-kot@pm.me> * dockerfile hotfix * dockerfile hotfix * Version Release Final Touches (#84) * Remove slim * bug: opacity issues * bug: startup failure with no database * ci/cd on dev branch * formatting * v0.1.0 documentation Co-authored-by: Hayden <hay-kot@pm.me> * db init hotfix * bug: fix crash in mongo * fix mongo bug * fixed version notifier * finale changelog Co-authored-by: kentora <=> Co-authored-by: Hayden <hay-kot@pm.me> Co-authored-by: Richard Mitic <richard.h.mitic@gmail.com> Co-authored-by: kentora <kentora@kentora.dk>
116 lines
2.8 KiB
Python
116 lines
2.8 KiB
Python
from datetime import date, timedelta
|
|
from pathlib import Path
|
|
from typing import List, Optional
|
|
|
|
from db.database import db
|
|
from pydantic import BaseModel
|
|
|
|
from services.recipe_services import Recipe
|
|
|
|
CWD = Path(__file__).parent
|
|
THIS_WEEK = CWD.parent.joinpath("data", "meal_plan", "this_week.json")
|
|
NEXT_WEEK = CWD.parent.joinpath("data", "meal_plan", "next_week.json")
|
|
WEEKDAYS = [
|
|
"monday",
|
|
"tuesday",
|
|
"wednesday",
|
|
"thursday",
|
|
"friday",
|
|
"saturday",
|
|
"sunday",
|
|
]
|
|
|
|
|
|
class Meal(BaseModel):
|
|
slug: Optional[str]
|
|
name: Optional[str]
|
|
date: date
|
|
dateText: str
|
|
image: Optional[str]
|
|
description: Optional[str]
|
|
|
|
|
|
class MealData(BaseModel):
|
|
slug: str
|
|
dateText: str
|
|
|
|
|
|
class MealPlan(BaseModel):
|
|
uid: Optional[str]
|
|
startDate: date
|
|
endDate: date
|
|
meals: List[Meal]
|
|
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"startDate": date.today(),
|
|
"endDate": date.today(),
|
|
"meals": [
|
|
{"slug": "Packed Mac and Cheese", "date": date.today()},
|
|
{"slug": "Eggs and Toast", "date": date.today()},
|
|
],
|
|
}
|
|
}
|
|
|
|
def process_meals(self):
|
|
meals = []
|
|
for x, meal in enumerate(self.meals):
|
|
|
|
try:
|
|
recipe = Recipe.get_by_slug(meal.slug)
|
|
|
|
meal_data = {
|
|
"slug": recipe.slug,
|
|
"name": recipe.name,
|
|
"date": self.startDate + timedelta(days=x),
|
|
"dateText": meal.dateText,
|
|
"image": recipe.image,
|
|
"description": recipe.description,
|
|
}
|
|
except:
|
|
meal_data = {
|
|
"date": self.startDate + timedelta(days=x),
|
|
"dateText": meal.dateText,
|
|
}
|
|
|
|
meals.append(Meal(**meal_data))
|
|
|
|
self.meals = meals
|
|
|
|
def save_to_db(self):
|
|
db.meals.save_new(self.dict())
|
|
|
|
@staticmethod
|
|
def get_all() -> List:
|
|
|
|
all_meals = [MealPlan(**x) for x in db.meals.get_all(order_by="startDate")]
|
|
|
|
return all_meals
|
|
|
|
def update(self, uid):
|
|
db.meals.update(uid, self.dict())
|
|
|
|
@staticmethod
|
|
def delete(uid):
|
|
db.meals.delete(uid)
|
|
|
|
@staticmethod
|
|
def today() -> str:
|
|
""" Returns the meal slug for Today """
|
|
meal_plan = db.meals.get_all(limit=1, order_by="startDate")
|
|
|
|
meal_docs = [Meal(**meal) for meal in meal_plan["meals"]]
|
|
|
|
for meal in meal_docs:
|
|
if meal.date == date.today():
|
|
return meal.slug
|
|
|
|
return "No Meal Today"
|
|
|
|
@staticmethod
|
|
def this_week():
|
|
meal_plan = db.meals.get_all(limit=1, order_by="startDate")
|
|
|
|
return meal_plan
|