mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-03-03 20:23:11 -05:00
* 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>
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from settings import USE_MONGO, USE_SQL
|
|
|
|
from db.db_base import BaseDocument
|
|
from db.db_setup import USE_MONGO, USE_SQL
|
|
from db.mongo.settings_models import SiteSettingsDocument, WebhooksDocument
|
|
from db.sql.db_session import create_session
|
|
from db.sql.settings_models import SiteSettingsModel
|
|
|
|
|
|
class _Settings(BaseDocument):
|
|
def __init__(self) -> None:
|
|
|
|
self.primary_key = "name"
|
|
|
|
if USE_SQL:
|
|
self.sql_model = SiteSettingsModel
|
|
self.create_session = create_session
|
|
|
|
self.document = SiteSettingsDocument
|
|
|
|
def save_new(self, main: dict, webhooks: dict) -> str:
|
|
|
|
if USE_MONGO:
|
|
main["webhooks"] = WebhooksDocument(**webhooks)
|
|
new_doc = self.document(**main)
|
|
return new_doc.save()
|
|
|
|
elif USE_SQL:
|
|
session = create_session()
|
|
new_settings = self.sql_model(main.get("name"), webhooks)
|
|
|
|
session.add(new_settings)
|
|
session.commit()
|
|
|
|
return new_settings.dict()
|
|
|
|
def update_mongo(self, name: str, new_data: dict) -> dict:
|
|
if USE_MONGO:
|
|
document = self.document.objects.get(name=name)
|
|
if document:
|
|
document.update(set__webhooks=WebhooksDocument(**new_data["webhooks"]))
|
|
document.save()
|
|
elif USE_SQL:
|
|
return
|