Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
feat(templates/contests): improve the contest details page
Browse files Browse the repository at this point in the history
  • Loading branch information
bitterteriyaki committed Oct 5, 2023
1 parent cb12cac commit 6b27a6c
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 12 deletions.
17 changes: 15 additions & 2 deletions apps/problems/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import TYPE_CHECKING

from django.contrib.admin import ModelAdmin, register
from django.forms import CharField, ModelForm, Textarea
from django.forms import CharField, IntegerField, ModelForm, Textarea
from django.utils.translation import gettext_lazy as _

from apps.problems.models import Problem
Expand All @@ -16,6 +16,14 @@

class ProblemModelForm(ProblemModelFormBase):
description = CharField(widget=Textarea(attrs={"rows": 14, "cols": 80}))
score = IntegerField(min_value=0, required=False)

memory_limit = IntegerField(
min_value=0, required=False, help_text=_("In bytes.")
)
time_limit = IntegerField(
min_value=0, required=False, help_text=_("In seconds.")
)

class Meta:
model = Problem
Expand All @@ -26,6 +34,11 @@ class Meta:
class ProblemAdmin(ProblemAdminBase):
form = ProblemModelForm

list_display = ("title", "contest", "memory_limit", "time_limit")
list_filter = ("contest", "score")

fieldsets = [
(_("Problem"), {"fields": ("title", "description", "contest")}),
(_("General"), {"fields": ("title", "description")}),
(_("Meta"), {"fields": ("contest", "score")}),
(_("Limits"), {"fields": ("memory_limit", "time_limit")}),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.5 on 2023-10-04 22:05

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("problems", "0002_alter_problem_options_alter_problem_table"),
]

operations = [
migrations.AddField(
model_name="problem",
name="memory_limit",
field=models.IntegerField(null=True),
),
migrations.AddField(
model_name="problem",
name="score",
field=models.IntegerField(null=True),
),
migrations.AddField(
model_name="problem",
name="time_limit",
field=models.IntegerField(null=True),
),
]
14 changes: 13 additions & 1 deletion apps/problems/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db.models import CASCADE, CharField, ForeignKey
from django.db.models import CASCADE, CharField, ForeignKey, IntegerField

from apps.contests.enums import ContestStatus
from apps.contests.models import Contest
from core.models import TimestampedModel

Expand All @@ -11,9 +12,20 @@ class Problem(TimestampedModel):
description = CharField(max_length=4096)

contest = ForeignKey(Contest, related_name="problems", on_delete=CASCADE)
score = IntegerField(null=True)

memory_limit = IntegerField(null=True)
time_limit = IntegerField(null=True)

class Meta:
db_table = "problems"

def __str__(self) -> str:
return self.title

@property
def is_accessible(self) -> bool:
return self.contest.status in (
ContestStatus.RUNNING,
ContestStatus.FINISHED,
)
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
</nav>
</header>

<main class="container mt-5" style="max-width: 640px;">
<main class="container mt-5" style="max-width: 720px;">
{% block content %}{% endblock content %}
</main>

Expand Down
61 changes: 53 additions & 8 deletions templates/contests/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,62 @@

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

{% load humanize %}

{% block content %}
<div>
<h1>{{ contest }}</h1>
<h1>
<a href="{% url 'contests:detail' contest.id %}">
{{ contest }}
</a>
</h1>
<hr>
<p>{{ contest.description }}</p>
</div>

<h2>Tasks</h2>

<ul>
{% for problem in contest.problems.all %}
<li><a href="{% url 'problems:detail' problem.id %}">{{ problem }}</a></li>
{% endfor %}
</ul>
<div class="mt-5">
<h2>Tasks</h2>
<hr>
<table class="table table-striped">
<thead>
<tr>
<th class="col">Name</th>
<th class="col">Score</th>
<th class="col">Memory limit</th>
<th class="col">Time limit</th>
</tr>
</thead>
<tbody>
{% for problem in contest.problems.all %}
<tr>
<td>
{% if problem.is_accessible %}
<a href="{% url 'problems:detail' problem.id %}">{{ problem }}</a>
{% else %}
{{ problem }}
{% endif %}
</td>
<td>
{{ problem.score|default:"???" }}
</td>
<td>
{% if problem.memory_limit %}
{{ problem.memory_limit|filesizeformat }}
{% else %}
Unlimited
{% endif %}
</td>
<td>
{% if problem.time_limit %}
{{ problem.time_limit}}
second{{ problem.time_limit|pluralize:"s" }}
{% else %}
Unlimited
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock content %}

0 comments on commit 6b27a6c

Please sign in to comment.