diff --git a/services/backend/apps/task/models.py b/services/backend/apps/task/models.py
index 8151452..58d26bc 100644
--- a/services/backend/apps/task/models.py
+++ b/services/backend/apps/task/models.py
@@ -3,6 +3,7 @@ from uuid import uuid4
from django.db import models
from django.db.models import Count, Q
from tinymce.models import HTMLField
+from martor.models import MartorField
from apps.competition.models import Competition
from apps.core.models import BaseModel
@@ -24,7 +25,7 @@ class CompetitionTask(BaseModel):
)
competition = models.ForeignKey(Competition, on_delete=models.CASCADE)
title = models.CharField(verbose_name="заголовок", max_length=50)
- description = HTMLField(verbose_name="описание")
+ description = MartorField(verbose_name="описание")
max_attempts = models.PositiveSmallIntegerField(null=True, blank=True)
type = models.CharField(
choices=CompetitionTaskType, max_length=8, verbose_name="тип проверки"
diff --git a/services/backend/config/settings.py b/services/backend/config/settings.py
index 63bc06a..266990b 100644
--- a/services/backend/config/settings.py
+++ b/services/backend/config/settings.py
@@ -442,6 +442,7 @@ INSTALLED_APPS = [
"ninja",
"minio_storage",
"tinymce",
+ "martor",
# Internal apps
"apps.core",
"apps.user",
@@ -459,15 +460,49 @@ TINYMCE_DEFAULT_CONFIG = {
"menubar": False,
"plugins": "advlist,autolink,lists,link,image,charmap,print,preview,anchor,"
"searchreplace,visualblocks,code,fullscreen,insertdatetime,media,table,paste,"
- "code,help,wordcount",
+ "code,help,wordcount,markdown",
"toolbar": "undo redo | formatselect | "
"bold italic backcolor | alignleft aligncenter "
"alignright alignjustify | bullist numlist outdent indent | "
"removeformat | help",
"skin": "oxide-dark",
"content_css": "dark",
+ "textpattern_patterns": [
+ {"start": "*", "end": "*", "format": "italic"},
+ {"start": "**", "end": "**", "format": "bold"},
+ {"start": "#", "format": "h1"},
+ {"start": "##", "format": "h2"},
+ {"start": "###", "format": "h3"},
+ {"start": "####", "format": "h4"},
+ {"start": "#####", "format": "h5"},
+ {"start": "######", "format": "h6"},
+ {"start": "1. ", "cmd": "InsertOrderedList"},
+ {"start": "* ", "cmd": "InsertUnorderedList"},
+ {"start": "- ", "cmd": "InsertUnorderedList"}
+ ]
}
+# martor
+
+MARTOR_THEME = 'bootstrap'
+
+MARTOR_ENABLE_CONFIGS = {
+ 'emoji': 'true', # to enable/disable emoji icons.
+ 'imgur': 'true', # to enable/disable imgur/custom uploader.
+ 'mention': 'false', # to enable/disable mention
+ 'jquery': 'true', # to include/revoke jquery (require for admin default django)
+ 'living': 'false', # to enable/disable live updates in preview
+ 'spellcheck': 'false', # to enable/disable spellcheck in form textareas
+ 'hljs': 'true', # to enable/disable hljs highlighting in preview
+}
+
+MARTOR_TOOLBAR_BUTTONS = [
+ 'bold', 'italic', 'horizontal', 'heading', 'pre-code',
+ 'blockquote', 'unordered-list', 'ordered-list',
+ 'link', 'emoji',
+ 'direct-mention', 'toggle-maximize', 'help'
+]
+
# GUID
DJANGO_GUID = {
diff --git a/services/backend/config/urls.py b/services/backend/config/urls.py
index 27b279a..4e50a9a 100644
--- a/services/backend/config/urls.py
+++ b/services/backend/config/urls.py
@@ -14,6 +14,8 @@ admin.site.index_title = "DataRush"
urlpatterns = [
# tinymce
path("tinymce/", include("tinymce.urls")),
+ # martor
+ path('martor/', include('martor.urls')),
# Admin urls
path("admin/", admin.site.urls),
# API urls
diff --git a/services/backend/pyproject.toml b/services/backend/pyproject.toml
index 20b218e..d3b2371 100644
--- a/services/backend/pyproject.toml
+++ b/services/backend/pyproject.toml
@@ -19,6 +19,7 @@ dependencies = [
"django-tinymce>=4.1.0",
"gunicorn>=23.0.0",
"httpx>=0.28.1",
+ "martor>=1.6.45",
"pillow>=11.1.0",
"psycopg2-binary>=2.9.10",
"pydantic>=2.10.5",
diff --git a/services/frontend/src/pages/Competition/index.tsx b/services/frontend/src/pages/Competition/index.tsx
index fe37509..2c87809 100644
--- a/services/frontend/src/pages/Competition/index.tsx
+++ b/services/frontend/src/pages/Competition/index.tsx
@@ -64,15 +64,13 @@ const CompetitionPage = () => {
- {competition.image_url && (
-
-

-
- )}
+
+

+
@@ -89,7 +87,7 @@ const CompetitionPage = () => {
onClick={handleStart}
disabled={startMutation.isPending}
>
- {startMutation.isPending ? "Загрузка..." : "Начать"}
+ {startMutation.isPending ? "Загрузка..." : "Приступить к выполнению"}
diff --git a/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx b/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx
index 74d11e4..96e36ef 100644
--- a/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx
+++ b/services/frontend/src/pages/CompetitionSession/components/CompetitionHeader/index.tsx
@@ -1,6 +1,6 @@
import React from 'react';
import { Link } from 'react-router-dom';
-import { Task } from "@/shared/types";
+import { Task } from '@/shared/types/task';
import { getTaskBgColor, getTaskTextColor } from '../../utils/utils';
interface CompetitionHeaderProps {
@@ -28,12 +28,12 @@ const CompetitionHeader: React.FC
= ({
- {task.number}
+ {task.in_competition_position}
))}
diff --git a/services/frontend/src/pages/CompetitionSession/components/TaskContent/index.tsx b/services/frontend/src/pages/CompetitionSession/components/TaskContent/index.tsx
index af3e4f4..a1abc5f 100644
--- a/services/frontend/src/pages/CompetitionSession/components/TaskContent/index.tsx
+++ b/services/frontend/src/pages/CompetitionSession/components/TaskContent/index.tsx
@@ -10,30 +10,6 @@ interface TaskContentProps {
}
const TaskContent: React.FC = ({ task }) => {
- const markdownContent = `
-## Задача на числовую последовательность
-
-Рассмотрим последовательность чисел:
-\`2, 3, 5, 9, 17, 33, 65, 129, ...\`
-
-Каждый член этой последовательности, **начиная с третьего**, равен сумме двух предыдущих членов:
-- $a_1 = 2$
-- $a_2 = 3$
-- $a_n = a_{n-1} + a_{n-2}$ для всех $n ≥ 3$
-
-### Задание:
-Найдите сумму первых 15 членов этой последовательности.
-
-*Примечание:* Для решения задачи вам может быть полезно записать несколько первых членов последовательности:
-1. $a_1 = 2$
-2. $a_2 = 3$
-3. $a_3 = 3 + 2 = 5$
-4. $a_4 = 5 + 3 = 8$
-5. $a_5 = 8 + 5 = 13$
-
-**В ответе укажите целое число.**
- `;
-
return (
@@ -45,7 +21,7 @@ const TaskContent: React.FC = ({ task }) => {
remarkPlugins={[remarkMath]}
rehypePlugins={[rehypeKatex]}
>
- {markdownContent}
+ {task.description}
diff --git a/services/frontend/src/pages/CompetitionSession/index.tsx b/services/frontend/src/pages/CompetitionSession/index.tsx
index f924000..acf4b00 100644
--- a/services/frontend/src/pages/CompetitionSession/index.tsx
+++ b/services/frontend/src/pages/CompetitionSession/index.tsx
@@ -1,45 +1,32 @@
-import { useState, useEffect } from "react";
+import { useState } from "react";
import { useParams, Navigate } from "react-router-dom";
-import { Task, TaskStatus } from "@/shared/types";
-import { mockSolutions } from "@/shared/mocks/mocks"; // Keep mocks for solutions for now
+import { mockSolutions } from "@/shared/mocks/mocks";
import CompetitionHeader from "./components/CompetitionHeader";
import TaskContent from "./components/TaskContent";
import TaskSolution from "./modules/TaskSolution";
import { getCompetitionTasks } from "@/shared/api/session";
import { Loader2 } from "lucide-react";
+import { useQuery } from "@tanstack/react-query";
const CompetitionSession = () => {
const { id, taskId } = useParams<{ id: string; taskId?: string }>();
- const [tasks, setTasks] = useState([]);
const [answer, setAnswer] = useState("");
- const [loading, setLoading] = useState(true);
- const [error, setError] = useState(null);
-
const competitionId = id || "";
- useEffect(() => {
- const fetchTasks = async () => {
- try {
- setLoading(true);
- const fetchedTasks = await getCompetitionTasks(competitionId);
- setTasks(fetchedTasks);
- setError(null);
- } catch (err) {
- console.error("Failed to fetch tasks:", err);
- setError("Не удалось загрузить задания. Пожалуйста, попробуйте позже.");
- } finally {
- setLoading(false);
- }
- };
+ const tasksQuery = useQuery({
+ queryKey: ["competitionTasks", competitionId],
+ queryFn: () => getCompetitionTasks(competitionId),
+ enabled: !!competitionId,
+ // refetchOnWindowFocus: false,
+ });
- if (competitionId) {
- fetchTasks();
- }
- }, [competitionId]);
+ const tasks = tasksQuery.data || [];
+ const isLoading = tasksQuery.isLoading;
+ const error = tasksQuery.error ? "Не удалось загрузить задания. Пожалуйста, попробуйте позже." : null;
const currentTask = tasks.find((t) => t.id === taskId) || null;
- if (!taskId && tasks.length > 0 && !loading) {
+ if (!taskId && tasks.length > 0 && !isLoading) {
return (
{
- {loading ? (
+ {isLoading ? (
Загрузка заданий...
@@ -82,7 +69,7 @@ const CompetitionSession = () => {
{
);
};
-export default CompetitionSession;
+export default CompetitionSession;
\ No newline at end of file
diff --git a/services/frontend/src/shared/types/task.ts b/services/frontend/src/shared/types/task.ts
index 6de248b..9d215d3 100644
--- a/services/frontend/src/shared/types/task.ts
+++ b/services/frontend/src/shared/types/task.ts
@@ -2,7 +2,7 @@ export interface Task {
id: string;
title: string;
description: string;
- type: 'input' | 'file' | 'code';
+ type: TaskType;
in_competition_position: number;
points: number;
}