mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -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:
|
||||
list[SqlAlchemyBase]: Returns a list of ORM objects
|
||||
"""
|
||||
results = session.query(self.sql_model).options(load_only(*fields)).limit(limit).all()
|
||||
|
||||
return results
|
||||
return (
|
||||
session.query(self.sql_model)
|
||||
.options(load_only(*fields))
|
||||
.limit(limit)
|
||||
.all()
|
||||
)
|
||||
|
||||
def get_all_primary_keys(self, session: Session) -> List[str]:
|
||||
"""Queries the database of the selected model and returns a list
|
||||
|
@ -69,12 +72,14 @@ class BaseDocument:
|
|||
Returns:
|
||||
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
|
||||
|
||||
result = session.query(self.sql_model).filter_by(**{match_key: match_value}).one()
|
||||
|
||||
return result
|
||||
return (
|
||||
session.query(self.sql_model)
|
||||
.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]:
|
||||
"""Retrieves an entry from the database by matching a key/value pair. If no
|
||||
|
@ -89,7 +94,7 @@ class BaseDocument:
|
|||
Returns:
|
||||
dict or list[dict]:
|
||||
"""
|
||||
if match_key == None:
|
||||
if match_key is None:
|
||||
match_key = self.primary_key
|
||||
|
||||
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:
|
||||
return self.schema.from_orm(new_document)
|
||||
|
||||
return_data = new_document.dict()
|
||||
return return_data
|
||||
return new_document.dict()
|
||||
|
||||
def update(self, session: Session, match_value: str, new_data: str) -> BaseModel:
|
||||
"""Update a database entry.
|
||||
|
|
|
@ -57,12 +57,10 @@ class Group(SqlAlchemyBase, BaseMixins):
|
|||
|
||||
@staticmethod
|
||||
def get_ref(session: Session, name: str):
|
||||
item = session.query(Group).filter(Group.name == name).one()
|
||||
if item:
|
||||
return item
|
||||
|
||||
else:
|
||||
return session.query(Group).filter(Group.id == 1).one()
|
||||
item = session.query(Group).filter(Group.name == name).one_or_none()
|
||||
if item is None:
|
||||
item = session.query(Group).filter(Group.id == 1).one()
|
||||
return item
|
||||
|
||||
@staticmethod
|
||||
def create_if_not_exist(session, name: str = DEFAULT_GROUP):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue