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

Commit

Permalink
feat: change app.problems related instances to app.tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
MMcLovin authored and MMcLovin committed Nov 5, 2023
1 parent 404feef commit ecb3cbd
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 96 deletions.
8 changes: 0 additions & 8 deletions apps/problems/__init__.py

This file was deleted.

8 changes: 8 additions & 0 deletions apps/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.apps import AppConfig

default_app_config = "apps.tasks.TasksConfig"


class TasksConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "apps.tasks"
20 changes: 10 additions & 10 deletions apps/problems/admin.py → apps/tasks/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
from django.forms import CharField, IntegerField, ModelForm, Textarea
from django.utils.translation import gettext_lazy as _

from apps.problems.models import Problem
from apps.tasks.models import Task

if TYPE_CHECKING:
ProblemAdminBase = ModelAdmin[Problem]
ProblemModelFormBase = ModelForm[Problem]
TaskAdminBase = ModelAdmin[Task]
TaskModelFormBase = ModelForm[Task]
else:
ProblemAdminBase = ModelAdmin
ProblemModelFormBase = ModelForm
TaskAdminBase = ModelAdmin
TaskModelFormBase = ModelForm


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

Expand All @@ -26,13 +26,13 @@ class ProblemModelForm(ProblemModelFormBase):
)

class Meta:
model = Problem
model = Task
fields = "__all__"


@register(Problem)
class ProblemAdmin(ProblemAdminBase):
form = ProblemModelForm
@register(Task)
class TaskAdmin(TaskAdminBase):
form = TaskModelForm

list_display = ("title", "contest", "memory_limit", "time_limit")
list_filter = ("contest", "score")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name="Problem",
name="Task",
fields=[
(
"id",
Expand All @@ -32,7 +32,7 @@ class Migration(migrations.Migration):
"contest",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="problems",
related_name="tasks",
to="contests.contest",
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

class Migration(migrations.Migration):
dependencies = [
("problems", "0001_initial"),
("tasks", "0001_initial"),
]

operations = [
migrations.AlterModelOptions(
name="problem",
name="task",
options={},
),
migrations.AlterModelTable(
name="problem",
table="problems",
name="task",
table="tasks",
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@

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

operations = [
migrations.AddField(
model_name="problem",
model_name="task",
name="memory_limit",
field=models.IntegerField(null=True),
),
migrations.AddField(
model_name="problem",
model_name="task",
name="score",
field=models.IntegerField(null=True),
),
migrations.AddField(
model_name="problem",
model_name="task",
name="time_limit",
field=models.IntegerField(null=True),
),
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions apps/problems/models.py → apps/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
from core.models import TimestampedModel


class Problem(TimestampedModel):
"""Represents a problem in a contest."""
class Task(TimestampedModel):
"""Represents a task in a contest."""

title = CharField(max_length=256)
description = CharField(max_length=4096)

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

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

class Meta:
db_table = "problems"
db_table = "tasks"

def __str__(self) -> str:
return self.title
Expand Down
4 changes: 2 additions & 2 deletions apps/problems/urls.py → apps/tasks/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.urls import path

from apps.problems.views import DetailView
from apps.tasks.views import DetailView

app_name = "problems"
app_name = "tasks"

urlpatterns = [
path("<int:pk>/", DetailView.as_view(), name="detail"),
Expand Down
8 changes: 4 additions & 4 deletions apps/problems/views.py → apps/tasks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from django.views import generic

from apps.problems.models import Problem
from apps.tasks.models import Task

if TYPE_CHECKING:
DetailViewBase = generic.DetailView[Problem]
DetailViewBase = generic.DetailView[Task]
else:
DetailViewBase = generic.DetailView


class DetailView(DetailViewBase):
model = Problem
template_name = "problems/detail.html"
model = Task
template_name = "tasks/detail.html"
2 changes: 1 addition & 1 deletion server/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
LOCAL_APPS = [
"apps.users",
"apps.contests",
"apps.problems",
"apps.tasks",
]

INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
Expand Down
2 changes: 1 addition & 1 deletion server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
# Local views
path("", IndexView.as_view(), name="home"),
path("contests/", include("apps.contests.urls")),
path("problems/", include("apps.problems.urls")),
path("tasks/", include("apps.tasks.urls")),
]
22 changes: 11 additions & 11 deletions templates/contests/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ <h2>Tasks</h2>
</tr>
</thead>
<tbody>
{% for problem in contest.problems.all %}
{% for task in contest.tasks.all %}
<tr>
<td>
{% if problem.is_accessible %}
<a href="{% url 'problems:detail' problem.id %}">
{{ problem }}
{% if task.is_accessible %}
<a href="{% url 'tasks:detail' task.id %}">
{{ task }}
</a>
{% else %}
{{ problem }}
{{ task }}
{% endif %}
</td>
<td>
{{ problem.score|default:"???" }}
{{ task.score|default:"???" }}
</td>
<td>
{% if problem.memory_limit %}
{{ problem.memory_limit|filesizeformat }}
{% if task.memory_limit %}
{{ task.memory_limit|filesizeformat }}
{% else %}
Unlimited
{% endif %}
</td>
<td>
{% if problem.time_limit %}
{{ problem.time_limit }}
second{{ problem.time_limit|pluralize:"s" }}
{% if task.time_limit %}
{{ task.time_limit }}
second{{ task.time_limit|pluralize:"s" }}
{% else %}
Unlimited
{% endif %}
Expand Down
12 changes: 6 additions & 6 deletions templates/contests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ <h3>Upcoming Contests</h3>
<li>
Duration: {{ contest.start_time|timesince:contest.end_time }}
</li>
{% if contest.problems.all.count > 0 %}
{% if contest.tasks.all.count > 0 %}
<li>
{{ contest.problems.all.count }}
problem{{ contest.problems.all.count|pluralize:"s" }}
{{ contest.tasks.all.count }}
task{{ contest.tasks.all.count|pluralize:"s" }}
</li>
{% endif %}
</ul>
Expand Down Expand Up @@ -97,10 +97,10 @@ <h3>Past Contests</h3>
<li>
Duration: {{ contest.start_time|timesince:contest.end_time }}
</li>
{% if contest.problems.all.count > 0 %}
{% if contest.tasks.all.count > 0 %}
<li>
{{ contest.problems.all.count }}
problem{{ contest.problems.all.count|pluralize:"s" }}
{{ contest.tasks.all.count }}
task{{ contest.tasks.all.count|pluralize:"s" }}
</li>
{% endif %}
</ul>
Expand Down
39 changes: 0 additions & 39 deletions templates/problems/detail.html

This file was deleted.

39 changes: 39 additions & 0 deletions templates/tasks/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% extends "base.html" %}

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

{% block content %}
<div>
<h1>
<a href="{% url 'tasks:detail' task.id %}">
{{ task.title }}
</a>
</h1>
<hr>

<div>
<p>
<b>Score:</b> {{ task.score|default:"???" }}
</p>
<p>
<b>Memory limit:</b>
{% if task.memory_limit %}
{{ task.memory_limit|filesizeformat }}
{% else %}
Unlimited
{% endif %}
</p>
<p>
<b>Time limit:</b>
{% if task.time_limit %}
{{ task.time_limit }}
second{{ task.time_limit|pluralize:"s" }}
{% else %}
Unlimited
{% endif %}
</p>
</div>
<hr>
<p>{{ task.description }}</p>
</div>
{% endblock content %}

0 comments on commit ecb3cbd

Please sign in to comment.