налажена логика добавления промптов через диалог с ИИ, отлажена работа с задачами, настроена авторизация в веб интерфейсе.
This commit is contained in:
+43
-16
@@ -8,6 +8,16 @@ def get_db_connection():
|
||||
conn.row_factory = sqlite3.Row
|
||||
return conn
|
||||
|
||||
def normalize_task_id(task_id_input: str) -> str:
|
||||
"""Преобразует 6, '6', 'task-6' в красивый формат TASK-06 или TASK-006"""
|
||||
if not task_id_input:
|
||||
return ""
|
||||
clean_id = str(task_id_input).strip().upper().replace("TASK-", "").replace("TASK", "")
|
||||
if clean_id.isdigit():
|
||||
num = int(clean_id)
|
||||
return f"TASK-{num:02d}" if num < 100 else f"TASK-{num:03d}"
|
||||
return f"TASK-{clean_id}"
|
||||
|
||||
# === ЗАДАЧИ С ФИЛЬТРАЦИЕЙ ПО USER_ID ===
|
||||
|
||||
def db_get_tasks(user_id: int) -> List[Dict[str, Any]]:
|
||||
@@ -40,47 +50,51 @@ def db_add_task(user_id: int, module: str, title: str, priority: str = "MEDIUM",
|
||||
conn.close()
|
||||
return {"status": "success", "task_id": new_task_id, "message": f"Задача {new_task_id} создана"}
|
||||
|
||||
def db_update_task_status(user_id: int, task_id: str, status: str, due_date: Optional[str] = None) -> Dict[str, Any]:
|
||||
def db_update_task_status(user_id: int, task_id: str, status: str = "COMPLETED", due_date: Optional[str] = None) -> Dict[str, Any]:
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
task_id_upper = task_id.upper().strip()
|
||||
formatted_id = normalize_task_id(task_id)
|
||||
|
||||
if due_date:
|
||||
cursor.execute("""
|
||||
UPDATE tasks
|
||||
SET status = ?, due_date = ?
|
||||
WHERE UPPER(task_id) = ? AND user_id = ?
|
||||
""", (status.upper(), due_date, task_id_upper, user_id))
|
||||
WHERE (UPPER(task_id) = ? OR task_id LIKE ?) AND user_id = ?
|
||||
""", (status.upper(), due_date, formatted_id, f"%{task_id.strip()}", user_id))
|
||||
else:
|
||||
cursor.execute("""
|
||||
UPDATE tasks
|
||||
SET status = ?
|
||||
WHERE UPPER(task_id) = ? AND user_id = ?
|
||||
""", (status.upper(), task_id_upper, user_id))
|
||||
WHERE (UPPER(task_id) = ? OR task_id LIKE ?) AND user_id = ?
|
||||
""", (status.upper(), formatted_id, f"%{task_id.strip()}", user_id))
|
||||
|
||||
if cursor.rowcount == 0:
|
||||
conn.close()
|
||||
return {"error": f"Задача {task_id_upper} не найдена или принадлежит другому пользователю"}
|
||||
return {"error": f"Задача {task_id} не найдена или принадлежит другому пользователю"}
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return {"status": "success", "message": f"Статус {task_id_upper} обновлен"}
|
||||
return {"status": "success", "message": f"Статус задачи {formatted_id} обновлен на {status.upper()}"}
|
||||
|
||||
def db_delete_task(user_id: int, task_id: str) -> Dict[str, Any]:
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
task_id_upper = task_id.upper().strip()
|
||||
|
||||
cursor.execute("DELETE FROM tasks WHERE UPPER(task_id) = ? AND user_id = ?", (task_id_upper, user_id))
|
||||
formatted_id = normalize_task_id(task_id)
|
||||
|
||||
cursor.execute("""
|
||||
DELETE FROM tasks
|
||||
WHERE (UPPER(task_id) = ? OR task_id LIKE ?) AND user_id = ?
|
||||
""", (formatted_id, f"%{task_id.strip()}", user_id))
|
||||
|
||||
if cursor.rowcount == 0:
|
||||
conn.close()
|
||||
return {"error": f"Задача {task_id_upper} не найдена или принадлежит другому пользователю"}
|
||||
return {"error": f"Задача {task_id} не найдена"}
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return {"status": "success", "message": f"Задача {task_id_upper} удалена"}
|
||||
return {"status": "success", "message": f"Задача {formatted_id} удалена"}
|
||||
|
||||
# === ОБЩИЕ СИСТЕМНЫЕ РЕСУРСЫ ===
|
||||
|
||||
@@ -95,11 +109,24 @@ def db_get_active_system_prompt() -> str:
|
||||
def db_add_system_prompt(name: str, prompt_text: str) -> Dict[str, Any]:
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("UPDATE system_prompts SET is_active = 0")
|
||||
cursor.execute("INSERT INTO system_prompts (name, prompt_text, is_active) VALUES (?, ?, 1)", (name, prompt_text))
|
||||
|
||||
# Проверяем наличие промпта с таким именем, чтобы не плодить мусор
|
||||
cursor.execute("SELECT id FROM system_prompts WHERE name = ?", (name,))
|
||||
existing = cursor.fetchone()
|
||||
|
||||
if existing:
|
||||
cursor.execute("""
|
||||
UPDATE system_prompts
|
||||
SET prompt_text = ?, updated_at = CURRENT_TIMESTAMP, is_active = 1
|
||||
WHERE name = ?
|
||||
""", (prompt_text, name))
|
||||
else:
|
||||
cursor.execute("UPDATE system_prompts SET is_active = 0")
|
||||
cursor.execute("INSERT INTO system_prompts (name, prompt_text, is_active) VALUES (?, ?, 1)", (name, prompt_text))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return {"status": "success", "message": "Системный промпт обновлен"}
|
||||
return {"status": "success", "message": "Системный промпт успешно обновлен"}
|
||||
|
||||
def db_get_rules() -> List[Dict[str, Any]]:
|
||||
conn = get_db_connection()
|
||||
@@ -107,4 +134,4 @@ def db_get_rules() -> List[Dict[str, Any]]:
|
||||
cursor.execute("SELECT id, rule_text FROM ai_knowledge_base ORDER BY id ASC")
|
||||
rows = cursor.fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
return [dict(r) for r in rows]
|
||||
Reference in New Issue
Block a user