Skip to content

Commit

Permalink
Merge branch 'dev' into feature/TS-80-added-contests-list
Browse files Browse the repository at this point in the history
  • Loading branch information
DenVilk authored Dec 14, 2024
2 parents 5563049 + 8297c36 commit de81f5a
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 71 deletions.
7 changes: 7 additions & 0 deletions source/web/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ def status(self):
def __str__(self):
return f"#{self.id} {self.name}"

@property
def ordered_tasks(self):
res = []
for item in self.taskoncontest_set.filter(contest=self):
res.append((item.order, item.task))
return res


class TaskOnContest(BaseModel):
order = models.IntegerField()
Expand Down
4 changes: 4 additions & 0 deletions source/web/main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
TaskListView,
UserLoginView,
ContestListView,
ContestDetailView,
ContestTaskView,
)
from main.theta.handlers.theta_code import code_answer
from main.theta.handlers.theta_quiz import quiz_answer
Expand All @@ -25,5 +27,7 @@
path('tasks/<int:id>/theta_quiz', quiz_answer, name='theta_quiz'),

path('contest/', ContestListView.as_view(), name='contests'),
path('contest/<int:id>/', ContestDetailView.as_view(), name='contest_detail'),
path('contest/<int:id>/<int:task_order>', ContestTaskView.as_view(), name='contest_detail_task'),
path('contest/<int:id>/register', ContestRegisterView.as_view(), name='contest_register'),
]
59 changes: 56 additions & 3 deletions source/web/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ContestRole,
Task,
UserToContest,
TaskOnContest,
)


Expand Down Expand Up @@ -77,18 +78,27 @@ def post(self, request, *args, **kwargs):


class TaskView(TemplateView):
template_name = 'tasks/task_detail.html'

def get_task(self, task_id):
_task = get_object_or_404(Task, pk=task_id)
self.template_name = f'tasks/{_task.task_type.tester_name}.html'
self.task_template_name = f'tasks/{_task.task_type.tester_name}.html'

return _task

def get(self, request, *args, **kwargs):
task = self.get_task(kwargs['id'])
answers = Answer.objects.filter(task=task, user=request.user.profile).order_by('-created_at')

return render(request, self.template_name, {'task': task, 'answers': answers})
return render(
request,
self.template_name,
{
'task': task,
'answers': answers,
'task_template':self.task_template_name,
}
)


class TaskListView(TemplateView):
Expand Down Expand Up @@ -132,4 +142,47 @@ def post(self, request, *args, **kwargs):
role=ContestRole.objects.get(name="Participant")
)
return redirect('contest_detail', kwargs['id'])
return render(request, self.template_name, {'contest': contest})
return render(request, self.template_name, {'contest': contest})


class ContestDetailView(TemplateView):
template_name = 'contests/contest_detail.html'

def get_contest(self, contest_id):
return get_object_or_404(Contest, pk=contest_id)

def get(self, request, *args, **kwargs):
contest = self.get_contest(kwargs['id'])
return render(
request,
self.template_name,
{
'tasks': contest.tasks,
'contest': contest,
}
)


class ContestTaskView(TemplateView):
template_name = 'contests/contest_task.html'

def get(self, request, *args, **kwargs):
task_on_contest = get_object_or_404(
TaskOnContest,
contest__id=kwargs['id'],
order=kwargs['task_order']
)
task = task_on_contest.task
contest = task_on_contest.contest

template_name = f'tasks/{task.task_type.tester_name}.html'

return render(
request,
self.template_name,
{
'task_template': template_name,
'task': task,
'contest': contest,
}
)
11 changes: 11 additions & 0 deletions source/web/templates/contests/contest_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "contests/contest_wrapper.html" %}
{% load i18n %}

{% block title %}
{{contest.name}}
{% endblock %}

{% block contest_content %}
{{contest.name}}</br>
Contest description: ...
{% endblock %}
11 changes: 11 additions & 0 deletions source/web/templates/contests/contest_task.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "contests/contest_wrapper.html" %}
{% load i18n %}

{% block contest_content %}
<div class="container">
<div class="row">
{% include task_template %}
</div>
{% include "tasks/theta_solutions.html" %}
</div>
{% endblock %}
30 changes: 30 additions & 0 deletions source/web/templates/contests/contest_wrapper.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends "wrapper.html" %}

{% block title %}
{% endblock title %}

{% block content %}
<div class="container">
<div class="row">
<div class="col-md-8">
{% block contest_content %}
{% endblock contest_content %}
</div>
<div class="col-md-4">
{% if contest.tasks %}
<ul>
<li>
<a href="{% url 'contest_detail' contest.pk %}">{{ contest.name }}</a>
</li>
{% for order, task in contest.ordered_tasks %}
<li>
<a href="{% url 'contest_detail_task' contest.pk order %}">#{{order}} {{task.name}}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
</div>

{% endblock content %}
11 changes: 11 additions & 0 deletions source/web/templates/tasks/task_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "wrapper.html" %}
{% load i18n %}

{% block content %}
<div class="container">
<div class="row">
{% include task_template %}
</div>
{% include "tasks/theta_solutions.html" %}
</div>
{% endblock %}
60 changes: 24 additions & 36 deletions source/web/templates/tasks/theta_code.html
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
{% extends "wrapper.html" %}
{% load i18n %}

{% block title %}
{{task.name}}
{% endblock %}

{% block content %}
<div class="container">
<div class="row">
<h3>{% trans "TaskStatement" %}</h3>
<p>{{task.statement}}</p>
<h3>{% trans "TaskInputFormat" %}</h3>
<p>{{task.input}}</p>
<h3>{% trans "TaskOutputFormat" %}</h3>
<p>{{task.output}}</p>
<form method="POST" action="{% url 'theta_code' task.id %}">
{% csrf_token %}
<div class="mb-3">
<label for="answer" class="form-label">Code</label>
<textarea class="form-control" id="answer" rows="3" name="answer"></textarea>
</div>
<select name="compiler" id="compiler">
{% if contest %}
{% for compiler in contest.compilers.all %}
<option value="{{compiler.id}}">{{compiler.name}}</option>
{% endfor %}
{% else %}
{% for compiler in task.default_compilers %}
<option value="{{compiler.id}}">{{compiler.name}}</option>
{% endfor %}
{% endif %}
</select>
<button type="submit">Send answer</button>
</form>
{% include "tasks/theta_solutions.html" %}
<h3>{% trans "TaskStatement" %}</h3>
<p>{{task.statement}}</p>
<h3>{% trans "TaskInputFormat" %}</h3>
<p>{{task.input}}</p>
<h3>{% trans "TaskOutputFormat" %}</h3>
<p>{{task.output}}</p>
<form method="POST" action="{% url 'theta_code' task.id %}">
{% csrf_token %}
<div class="mb-3">
<label for="answer" class="form-label">Code</label>
<textarea class="form-control" id="answer" rows="3" name="answer"></textarea>
</div>
</div>
{% endblock %}
<select name="compiler" id="compiler">
{% if contest %}
{% for compiler in contest.compilers.all %}
<option value="{{compiler.id}}">{{compiler.name}}</option>
{% endfor %}
{% else %}
{% for compiler in task.default_compilers %}
<option value="{{compiler.id}}">{{compiler.name}}</option>
{% endfor %}
{% endif %}
</select>
<button type="submit">Send answer</button>
</form>
52 changes: 20 additions & 32 deletions source/web/templates/tasks/theta_quiz.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
{% extends "wrapper.html" %}
{% load i18n %}

{% block title %}
{{task.name}}
{% endblock %}

{% block content %}
<div class="container">
<div class="row">
<h3>{% trans "TaskStatement" %}</h3>
<p>{{task.statement}}</p>
<form method="POST" action="{% url 'theta_quiz' task.id %}">
{% csrf_token %}
{% for option in task.answer_options.all %}
<input
class="form-check-input"
type="radio"
id="{{option.id}}"
name="answer"
value="{{option.id}}"
/>
<label class="form-check-label" for="{{option.id}}">
{{option.text}}
</label>
<br>
{% endfor %}
<button type="submit">Send answer</button>
</form>
{% include "tasks/theta_solutions.html" %}
</div>
</div>
{% endblock %}
{% load i18n %}
<h3>{% trans "TaskStatement" %}</h3>
<p>{{task.statement}}</p>
<form method="POST" action="{% url 'theta_quiz' task.id %}">
{% csrf_token %}
{% for option in task.answer_options.all %}
<input
class="form-check-input"
type="radio"
id="{{option.id}}"
name="answer"
value="{{option.id}}"
/>
<label class="form-check-label" for="{{option.id}}">
{{option.text}}
</label>
<br>
{% endfor %}
<button type="submit">Send answer</button>
</form>

0 comments on commit de81f5a

Please sign in to comment.