Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cbf543940 | ||
|
|
b74b0067a6 |
@@ -175,7 +175,16 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
return True
|
||||
|
||||
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
|
||||
|
||||
async def list_project_monitor(self):
|
||||
@@ -231,25 +240,69 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
|
||||
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]:
|
||||
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),
|
||||
soft_deleted=True,
|
||||
model=self.MODEL,
|
||||
search_cols=['design.title'],
|
||||
extra_filter=[{'sts': 2}],
|
||||
extra_filter=extra_filter,
|
||||
inputs=_input.te) \
|
||||
.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]:
|
||||
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),
|
||||
soft_deleted=True,
|
||||
model=self.MODEL,
|
||||
search_cols=['design.title'],
|
||||
extra_filter=[{'sts': 1}],
|
||||
extra_filter=extra_filter,
|
||||
inputs=_input.te) \
|
||||
.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):
|
||||
url = 'http://api.khanesaziceco.ir/api/api/project/table'
|
||||
|
||||
@@ -10,7 +10,8 @@ from .utils.Models import TableEngineExport
|
||||
|
||||
class NewTableEngine:
|
||||
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.query_class = query_class
|
||||
self.mode = mode
|
||||
@@ -29,6 +30,7 @@ class NewTableEngine:
|
||||
self.search_cols = search_cols
|
||||
self.unselect = unselect
|
||||
self.return_query = return_query
|
||||
self.collation = collation
|
||||
self.engine = engine(self)
|
||||
|
||||
@staticmethod
|
||||
@@ -38,10 +40,12 @@ class NewTableEngine:
|
||||
mode: WorkingMode = WorkingMode.Development,
|
||||
extra_filter=None,
|
||||
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,
|
||||
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
|
||||
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.unselect = table_engine.unselect
|
||||
self.return_query = table_engine.return_query
|
||||
self.collation = {'locale': 'fa'}
|
||||
|
||||
@abc.abstractmethod
|
||||
def exe(self):
|
||||
|
||||
@@ -54,6 +54,10 @@ class MongoEngine(AbstractEngineClass):
|
||||
else:
|
||||
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:
|
||||
res = await tmp.to_list(None)
|
||||
self.input.e.d = await self.generate_output(res)
|
||||
|
||||
Reference in New Issue
Block a user