mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 22:43:34 -07:00
set group for signups
This commit is contained in:
parent
e3f5421679
commit
d99685cfdf
2 changed files with 18 additions and 16 deletions
|
@ -40,9 +40,12 @@ class BaseDocument:
|
||||||
Returns:
|
Returns:
|
||||||
list[SqlAlchemyBase]: Returns a list of ORM objects
|
list[SqlAlchemyBase]: Returns a list of ORM objects
|
||||||
"""
|
"""
|
||||||
results = session.query(self.sql_model).options(load_only(*fields)).limit(limit).all()
|
return (
|
||||||
|
session.query(self.sql_model)
|
||||||
return results
|
.options(load_only(*fields))
|
||||||
|
.limit(limit)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
|
||||||
def get_all_primary_keys(self, session: Session) -> List[str]:
|
def get_all_primary_keys(self, session: Session) -> List[str]:
|
||||||
"""Queries the database of the selected model and returns a list
|
"""Queries the database of the selected model and returns a list
|
||||||
|
@ -69,12 +72,14 @@ class BaseDocument:
|
||||||
Returns:
|
Returns:
|
||||||
Union[Session, SqlAlchemyBase]: Will return both the session and found model
|
Union[Session, SqlAlchemyBase]: Will return both the session and found model
|
||||||
"""
|
"""
|
||||||
if match_key == None:
|
if match_key is None:
|
||||||
match_key = self.primary_key
|
match_key = self.primary_key
|
||||||
|
|
||||||
result = session.query(self.sql_model).filter_by(**{match_key: match_value}).one()
|
return (
|
||||||
|
session.query(self.sql_model)
|
||||||
return result
|
.filter_by(**{match_key: match_value})
|
||||||
|
.one()
|
||||||
|
)
|
||||||
|
|
||||||
def get(self, session: Session, match_value: str, match_key: str = None, limit=1) -> BaseModel or List[BaseModel]:
|
def get(self, session: Session, match_value: str, match_key: str = None, limit=1) -> BaseModel or List[BaseModel]:
|
||||||
"""Retrieves an entry from the database by matching a key/value pair. If no
|
"""Retrieves an entry from the database by matching a key/value pair. If no
|
||||||
|
@ -89,7 +94,7 @@ class BaseDocument:
|
||||||
Returns:
|
Returns:
|
||||||
dict or list[dict]:
|
dict or list[dict]:
|
||||||
"""
|
"""
|
||||||
if match_key == None:
|
if match_key is None:
|
||||||
match_key = self.primary_key
|
match_key = self.primary_key
|
||||||
|
|
||||||
result = session.query(self.sql_model).filter_by(**{match_key: match_value}).limit(limit).all()
|
result = session.query(self.sql_model).filter_by(**{match_key: match_value}).limit(limit).all()
|
||||||
|
@ -118,8 +123,7 @@ class BaseDocument:
|
||||||
if self.orm_mode:
|
if self.orm_mode:
|
||||||
return self.schema.from_orm(new_document)
|
return self.schema.from_orm(new_document)
|
||||||
|
|
||||||
return_data = new_document.dict()
|
return new_document.dict()
|
||||||
return return_data
|
|
||||||
|
|
||||||
def update(self, session: Session, match_value: str, new_data: str) -> BaseModel:
|
def update(self, session: Session, match_value: str, new_data: str) -> BaseModel:
|
||||||
"""Update a database entry.
|
"""Update a database entry.
|
||||||
|
|
|
@ -57,13 +57,11 @@ class Group(SqlAlchemyBase, BaseMixins):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_ref(session: Session, name: str):
|
def get_ref(session: Session, name: str):
|
||||||
item = session.query(Group).filter(Group.name == name).one()
|
item = session.query(Group).filter(Group.name == name).one_or_none()
|
||||||
if item:
|
if item is None:
|
||||||
|
item = session.query(Group).filter(Group.id == 1).one()
|
||||||
return item
|
return item
|
||||||
|
|
||||||
else:
|
|
||||||
return session.query(Group).filter(Group.id == 1).one()
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_if_not_exist(session, name: str = DEFAULT_GROUP):
|
def create_if_not_exist(session, name: str = DEFAULT_GROUP):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue