bx-2052-deal-tab #2
34
app/main.py
34
app/main.py
|
@ -14,18 +14,34 @@ from app.constants import *
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
templates = Jinja2Templates(directory="templates")
|
templates = Jinja2Templates(directory="templates")
|
||||||
try:
|
try:
|
||||||
locale.setlocale(locale.LC_TIME, 'ru_RU')
|
locale.setlocale(locale.LC_TIME, "ru_RU")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
||||||
|
|
||||||
# Создаем кастомный фильтр для форматирования дат
|
# Создаем кастомный фильтр для форматирования дат
|
||||||
def format_datetime(value, format="%d %B %Y, %H:%M:%S"):
|
def format_datetime(value, format="%d %B %Y, %H:%M:%S"):
|
||||||
"""Форматирует дату в человекочитаемый вид."""
|
"""Форматирует дату в человекочитаемый вид."""
|
||||||
date = datetime.fromisoformat(value)
|
date = datetime.fromisoformat(value)
|
||||||
return date.strftime(format)
|
return date.strftime(format)
|
||||||
|
|
||||||
|
statuses = []
|
||||||
|
def get_statuses():
|
||||||
|
get_status_hook = f"{WEBHOOK}/crm.status.list"
|
||||||
|
status_data = requests.get(get_status_hook)
|
||||||
|
status_data_json = status_data.json()
|
||||||
|
global statuses
|
||||||
|
statuses = status_data_json["result"]
|
||||||
|
|
||||||
|
# Создаем кастомный фильтр для форматирования дат
|
||||||
|
def format_status(value):
|
||||||
|
res = [r["NAME"] for r in statuses if r["ID"] == value]
|
||||||
|
return res[0] if len(res) else value
|
||||||
|
|
||||||
|
|
||||||
# Регистрируем фильтр в Jinja2Templates
|
# Регистрируем фильтр в Jinja2Templates
|
||||||
templates.env.filters['format_datetime'] = format_datetime
|
templates.env.filters["format_status"] = format_status
|
||||||
|
templates.env.filters["format_datetime"] = format_datetime
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
|
@ -142,17 +158,25 @@ async def deal_tab(
|
||||||
deal_id = 49
|
deal_id = 49
|
||||||
|
|
||||||
select = [
|
select = [
|
||||||
'ID', 'TITLE', 'RESPONSIBLE_ID', 'CREATED_DATE', 'DEADLINE', 'STAGE_ID', 'GROUP_ID'
|
"ID",
|
||||||
|
"TITLE",
|
||||||
|
"RESPONSIBLE_ID",
|
||||||
|
"CREATED_DATE",
|
||||||
|
"DEADLINE",
|
||||||
|
"STATUS",
|
||||||
|
"GROUP_ID",
|
||||||
]
|
]
|
||||||
get_task_hook = f"{WEBHOOK}/tasks.task.list?{'&'.join([f'select[]={s}' for s in select])}&filter[UF_CRM_TASK]=D_{deal_id}"
|
get_task_hook = f"{WEBHOOK}/tasks.task.list?{'&'.join([f'select[]={s}' for s in select])}&filter[UF_CRM_TASK]=D_{deal_id}"
|
||||||
task_data = requests.get(get_task_hook)
|
task_data = requests.get(get_task_hook)
|
||||||
task_data_json = task_data.json()
|
task_data_json = task_data.json()
|
||||||
|
|
||||||
# logger.info(task_data_json["result"]["tasks"])
|
# logger.info(task_data_json["result"]["tasks"])
|
||||||
parts = WEBHOOK.split("/")
|
parts = WEBHOOK.split("/")
|
||||||
domain = f"https://{parts[2]}"
|
domain = f"https://{parts[2]}"
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
request=request, name="deal_tab.html", context={"tasks": task_data_json["result"]["tasks"], "domain":domain}
|
request=request,
|
||||||
|
name="deal_tab.html",
|
||||||
|
context={"tasks": task_data_json["result"]["tasks"], "domain": domain},
|
||||||
)
|
)
|
||||||
|
|
||||||
return {"status": "success", "result": task_data_json}
|
return {"status": "success", "result": task_data_json}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th>Название</th>
|
<th>Название</th>
|
||||||
<th>Стадия</th>
|
<th>Статус</th>
|
||||||
<th>Исполнитель</th>
|
<th>Исполнитель</th>
|
||||||
<th>Дата создания</th>
|
<th>Дата создания</th>
|
||||||
<th>Крайний срок</th>
|
<th>Крайний срок</th>
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
{{ item.title }}
|
{{ item.title }}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ item.stageId }}</td>
|
<td>{{ item.status | format_status }}</td>
|
||||||
<td>{{ item.responsible.name }}</td>
|
<td>{{ item.responsible.name }}</td>
|
||||||
<td>{{ item.createdDate | format_datetime }}</td>
|
<td>{{ item.createdDate | format_datetime }}</td>
|
||||||
<td>{{ item.deadline | format_datetime}}</td>
|
<td>{{ item.deadline | format_datetime}}</td>
|
||||||
|
|
Loading…
Reference in New Issue