项目基础模块代码
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import and_
|
||||
|
||||
from app.model.bussiness_model import ProjectLabel as plModel
|
||||
from app.model.schemas.project_label_schemas import ProjectLabel
|
||||
@ -12,7 +13,7 @@ def get_label_list(project_id: int, session: Session):
|
||||
:return:
|
||||
"""
|
||||
label_list = session.query(plModel).filter(plModel.project_id == project_id).all()
|
||||
label_list = [ProjectLabel.from_orm(label) for label in label_list]
|
||||
label_list = [ProjectLabel.from_orm(label).dict() for label in label_list]
|
||||
return label_list
|
||||
|
||||
|
||||
@ -41,11 +42,12 @@ def check_label_name(project_id: int, label_name: str, session: Session, label_i
|
||||
filters = [plModel.project_id == project_id, plModel.label_name == label_name]
|
||||
if label_id is not None:
|
||||
filters.append(plModel.id != label_id)
|
||||
query.filter(*filters)
|
||||
if query.count() > 0:
|
||||
return False
|
||||
else:
|
||||
query = query.filter(and_(*filters))
|
||||
count = query.count()
|
||||
if count > 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def update_label(label: plModel, session: Session):
|
||||
@ -56,17 +58,19 @@ def update_label(label: plModel, session: Session):
|
||||
:return:
|
||||
"""
|
||||
session.query(plModel).filter_by(id=label.id).update({
|
||||
"label_name": label.label_name
|
||||
"label_name": label.label_name,
|
||||
"meta": label.meta
|
||||
})
|
||||
session.commit()
|
||||
|
||||
|
||||
def del_label(id: str, session: Session):
|
||||
def del_label(label_id: str, session: Session):
|
||||
"""
|
||||
根据标签id删除标签
|
||||
:param id: 标签id
|
||||
:param label_id: 标签id
|
||||
:param session:
|
||||
:return:
|
||||
"""
|
||||
row_del = session.query(plModel).filter_by(id=id).delete()
|
||||
row_del = session.query(plModel).filter_by(id=label_id).delete()
|
||||
session.commit()
|
||||
return row_del
|
||||
|
Reference in New Issue
Block a user