Compare commits
2
Commits
6cd225f395
...
0cbf543940
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cbf543940 | ||
|
|
b74b0067a6 |
@@ -175,7 +175,16 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
async def list_project_design(self):
|
async def list_project_design(self):
|
||||||
project = await use_collection(COLLECTION).find({'monitor': {"$exists": 0}}).to_list(None)
|
project = await use_collection(COLLECTION).find({
|
||||||
|
'$or': [
|
||||||
|
{'has_monitor': False},
|
||||||
|
{'monitor': {'$exists': 0}},
|
||||||
|
{
|
||||||
|
'has_monitor': True,
|
||||||
|
'monitor.has_design': True
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}).to_list(None)
|
||||||
return project
|
return project
|
||||||
|
|
||||||
async def list_project_monitor(self):
|
async def list_project_monitor(self):
|
||||||
@@ -231,25 +240,69 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
|||||||
|
|
||||||
return projects
|
return projects
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _has_design_sts_filter(te_input) -> bool:
|
||||||
|
if not te_input:
|
||||||
|
return False
|
||||||
|
f_list = getattr(te_input, 'f', None) if not isinstance(te_input, dict) else te_input.get('f')
|
||||||
|
if not f_list:
|
||||||
|
return False
|
||||||
|
for scope in f_list:
|
||||||
|
items = scope.get('items', []) if isinstance(scope, dict) else getattr(scope, 'items', [])
|
||||||
|
if items:
|
||||||
|
for item in items:
|
||||||
|
col = item.get('col') if isinstance(item, dict) else getattr(item, 'col', '')
|
||||||
|
if col == 'design.sts':
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
async def fetch_delete(self, _input: TableEngineRequestType) -> TableEngineExport[T]:
|
async def fetch_delete(self, _input: TableEngineRequestType) -> TableEngineExport[T]:
|
||||||
return await NewTableEngine.mongo(
|
extra_filter = [{'sts': 2}]
|
||||||
|
if self._has_design_sts_filter(_input.te if _input else None):
|
||||||
|
extra_filter.append({
|
||||||
|
'$or': [
|
||||||
|
{'has_monitor': False},
|
||||||
|
{'monitor': {'$exists': False}},
|
||||||
|
{'has_monitor': True, 'monitor.has_design': True}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
result = await NewTableEngine.mongo(
|
||||||
query_class=use_collection(self.COLLECTION),
|
query_class=use_collection(self.COLLECTION),
|
||||||
soft_deleted=True,
|
soft_deleted=True,
|
||||||
model=self.MODEL,
|
model=self.MODEL,
|
||||||
search_cols=['design.title'],
|
search_cols=['design.title'],
|
||||||
extra_filter=[{'sts': 2}],
|
extra_filter=extra_filter,
|
||||||
inputs=_input.te) \
|
inputs=_input.te) \
|
||||||
.to_dict()
|
.to_dict()
|
||||||
|
if result and result.rows:
|
||||||
|
for row in result.rows:
|
||||||
|
if row.monitor and row.monitor.has_design is False:
|
||||||
|
row.design.sts = None
|
||||||
|
return result
|
||||||
|
|
||||||
async def fetch(self, _input: TableEngineRequestType) -> TableEngineExport[T]:
|
async def fetch(self, _input: TableEngineRequestType) -> TableEngineExport[T]:
|
||||||
return await NewTableEngine.mongo(
|
extra_filter = [{'sts': 1}]
|
||||||
|
if self._has_design_sts_filter(_input.te if _input else None):
|
||||||
|
extra_filter.append({
|
||||||
|
'$or': [
|
||||||
|
{'has_monitor': False},
|
||||||
|
{'monitor': {'$exists': False}},
|
||||||
|
{'has_monitor': True, 'monitor.has_design': True}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
result = await NewTableEngine.mongo(
|
||||||
query_class=use_collection(self.COLLECTION),
|
query_class=use_collection(self.COLLECTION),
|
||||||
soft_deleted=True,
|
soft_deleted=True,
|
||||||
model=self.MODEL,
|
model=self.MODEL,
|
||||||
search_cols=['design.title'],
|
search_cols=['design.title'],
|
||||||
extra_filter=[{'sts': 1}],
|
extra_filter=extra_filter,
|
||||||
inputs=_input.te) \
|
inputs=_input.te) \
|
||||||
.to_dict()
|
.to_dict()
|
||||||
|
if result and result.rows:
|
||||||
|
for row in result.rows:
|
||||||
|
if row.monitor and row.monitor.has_design is False:
|
||||||
|
row.design.sts = None
|
||||||
|
return result
|
||||||
|
|
||||||
async def get_all(self):
|
async def get_all(self):
|
||||||
url = 'http://api.khanesaziceco.ir/api/api/project/table'
|
url = 'http://api.khanesaziceco.ir/api/api/project/table'
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ from .utils.Models import TableEngineExport
|
|||||||
|
|
||||||
class NewTableEngine:
|
class NewTableEngine:
|
||||||
def __init__(self, query_class, model, inputs, mode, engine: AbstractEngine, extra_filter,
|
def __init__(self, query_class, model, inputs, mode, engine: AbstractEngine, extra_filter,
|
||||||
default_sort_by, joins, search_cols, options=None, soft_deleted=False, unselect={}, return_query=False):
|
default_sort_by, joins, search_cols, options=None, soft_deleted=False, unselect={}, return_query=False,
|
||||||
|
collation={'locale': 'fa'}):
|
||||||
self.model = model
|
self.model = model
|
||||||
self.query_class = query_class
|
self.query_class = query_class
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
@@ -29,6 +30,7 @@ class NewTableEngine:
|
|||||||
self.search_cols = search_cols
|
self.search_cols = search_cols
|
||||||
self.unselect = unselect
|
self.unselect = unselect
|
||||||
self.return_query = return_query
|
self.return_query = return_query
|
||||||
|
self.collation = collation
|
||||||
self.engine = engine(self)
|
self.engine = engine(self)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -38,10 +40,12 @@ class NewTableEngine:
|
|||||||
mode: WorkingMode = WorkingMode.Development,
|
mode: WorkingMode = WorkingMode.Development,
|
||||||
extra_filter=None,
|
extra_filter=None,
|
||||||
soft_deleted=False,
|
soft_deleted=False,
|
||||||
default_sort_by=None, joins=None, search_cols=[] ,unselect={}, return_query=False):
|
default_sort_by=None, joins=None, search_cols=[] ,unselect={}, return_query=False,
|
||||||
|
collation={'locale': 'fa'}):
|
||||||
return NewTableEngine(query_class, model, inputs, mode, engine=MongoEngine, extra_filter=extra_filter,
|
return NewTableEngine(query_class, model, inputs, mode, engine=MongoEngine, extra_filter=extra_filter,
|
||||||
default_sort_by=default_sort_by, joins=joins, search_cols=search_cols,
|
default_sort_by=default_sort_by, joins=joins, search_cols=search_cols,
|
||||||
soft_deleted=soft_deleted,unselect=unselect, return_query=return_query)
|
soft_deleted=soft_deleted,unselect=unselect, return_query=return_query,
|
||||||
|
collation=collation)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def mssql(query_class, model, inputs, mode: WorkingMode = WorkingMode.Development, extra_filter=None,
|
def mssql(query_class, model, inputs, mode: WorkingMode = WorkingMode.Development, extra_filter=None,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class AbstractEngineClass(abc.ABC):
|
|||||||
self.soft_deleted = table_engine.soft_deleted
|
self.soft_deleted = table_engine.soft_deleted
|
||||||
self.unselect = table_engine.unselect
|
self.unselect = table_engine.unselect
|
||||||
self.return_query = table_engine.return_query
|
self.return_query = table_engine.return_query
|
||||||
|
self.collation = {'locale': 'fa'}
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def exe(self):
|
def exe(self):
|
||||||
|
|||||||
@@ -54,6 +54,10 @@ class MongoEngine(AbstractEngineClass):
|
|||||||
else:
|
else:
|
||||||
tmp = tmp.sort(sort_by)
|
tmp = tmp.sort(sort_by)
|
||||||
|
|
||||||
|
is_natural = isinstance(sort_by, dict) and sort_by.get('key_or_list') == '$natural'
|
||||||
|
if getattr(self, 'collation', None) and not is_natural:
|
||||||
|
tmp = tmp.collation(self.collation)
|
||||||
|
|
||||||
if self.input.e and self.input.e.ot:
|
if self.input.e and self.input.e.ot:
|
||||||
res = await tmp.to_list(None)
|
res = await tmp.to_list(None)
|
||||||
self.input.e.d = await self.generate_output(res)
|
self.input.e.d = await self.generate_output(res)
|
||||||
|
|||||||
Reference in New Issue
Block a user