From ecb3cbd9ccbf3c00524f49d7210f2a7a9893980d Mon Sep 17 00:00:00 2001 From: MMcLovin Date: Sat, 4 Nov 2023 22:17:27 -0300 Subject: [PATCH] feat: change app.problems related instances to app.tasks --- apps/problems/__init__.py | 8 ---- apps/tasks/__init__.py | 8 ++++ apps/{problems => tasks}/admin.py | 20 +++++----- .../migrations/0001_initial.py | 4 +- ...ter_problem_options_alter_problem_table.py | 8 ++-- ...lem_memory_limit_problem_score_and_more.py | 8 ++-- .../migrations/__init__.py | 0 apps/{problems => tasks}/models.py | 8 ++-- apps/{problems => tasks}/urls.py | 4 +- apps/{problems => tasks}/views.py | 8 ++-- server/settings/base.py | 2 +- server/urls.py | 2 +- templates/contests/detail.html | 22 +++++------ templates/contests/index.html | 12 +++--- templates/problems/detail.html | 39 ------------------- templates/tasks/detail.html | 39 +++++++++++++++++++ 16 files changed, 96 insertions(+), 96 deletions(-) delete mode 100644 apps/problems/__init__.py create mode 100644 apps/tasks/__init__.py rename apps/{problems => tasks}/admin.py (72%) rename apps/{problems => tasks}/migrations/0001_initial.py (94%) rename apps/{problems => tasks}/migrations/0002_alter_problem_options_alter_problem_table.py (70%) rename apps/{problems => tasks}/migrations/0003_problem_memory_limit_problem_score_and_more.py (75%) rename apps/{problems => tasks}/migrations/__init__.py (100%) rename apps/{problems => tasks}/models.py (77%) rename apps/{problems => tasks}/urls.py (62%) rename apps/{problems => tasks}/views.py (52%) delete mode 100644 templates/problems/detail.html create mode 100644 templates/tasks/detail.html diff --git a/apps/problems/__init__.py b/apps/problems/__init__.py deleted file mode 100644 index 4dc04c0..0000000 --- a/apps/problems/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -from django.apps import AppConfig - -default_app_config = "apps.problems.ProblemsConfig" - - -class ProblemsConfig(AppConfig): - default_auto_field = "django.db.models.BigAutoField" - name = "apps.problems" diff --git a/apps/tasks/__init__.py b/apps/tasks/__init__.py new file mode 100644 index 0000000..47162ff --- /dev/null +++ b/apps/tasks/__init__.py @@ -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" diff --git a/apps/problems/admin.py b/apps/tasks/admin.py similarity index 72% rename from apps/problems/admin.py rename to apps/tasks/admin.py index 77e46f9..7ceebb7 100644 --- a/apps/problems/admin.py +++ b/apps/tasks/admin.py @@ -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) @@ -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") diff --git a/apps/problems/migrations/0001_initial.py b/apps/tasks/migrations/0001_initial.py similarity index 94% rename from apps/problems/migrations/0001_initial.py rename to apps/tasks/migrations/0001_initial.py index 46dde8f..63f3c23 100644 --- a/apps/problems/migrations/0001_initial.py +++ b/apps/tasks/migrations/0001_initial.py @@ -13,7 +13,7 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name="Problem", + name="Task", fields=[ ( "id", @@ -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", ), ), diff --git a/apps/problems/migrations/0002_alter_problem_options_alter_problem_table.py b/apps/tasks/migrations/0002_alter_problem_options_alter_problem_table.py similarity index 70% rename from apps/problems/migrations/0002_alter_problem_options_alter_problem_table.py rename to apps/tasks/migrations/0002_alter_problem_options_alter_problem_table.py index 036ca10..0828a87 100644 --- a/apps/problems/migrations/0002_alter_problem_options_alter_problem_table.py +++ b/apps/tasks/migrations/0002_alter_problem_options_alter_problem_table.py @@ -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", ), ] diff --git a/apps/problems/migrations/0003_problem_memory_limit_problem_score_and_more.py b/apps/tasks/migrations/0003_problem_memory_limit_problem_score_and_more.py similarity index 75% rename from apps/problems/migrations/0003_problem_memory_limit_problem_score_and_more.py rename to apps/tasks/migrations/0003_problem_memory_limit_problem_score_and_more.py index c0e1bb9..3b48c1c 100644 --- a/apps/problems/migrations/0003_problem_memory_limit_problem_score_and_more.py +++ b/apps/tasks/migrations/0003_problem_memory_limit_problem_score_and_more.py @@ -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), ), diff --git a/apps/problems/migrations/__init__.py b/apps/tasks/migrations/__init__.py similarity index 100% rename from apps/problems/migrations/__init__.py rename to apps/tasks/migrations/__init__.py diff --git a/apps/problems/models.py b/apps/tasks/models.py similarity index 77% rename from apps/problems/models.py rename to apps/tasks/models.py index 54b53c2..3443d00 100644 --- a/apps/problems/models.py +++ b/apps/tasks/models.py @@ -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 diff --git a/apps/problems/urls.py b/apps/tasks/urls.py similarity index 62% rename from apps/problems/urls.py rename to apps/tasks/urls.py index 0ada153..168b68d 100644 --- a/apps/problems/urls.py +++ b/apps/tasks/urls.py @@ -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("/", DetailView.as_view(), name="detail"), diff --git a/apps/problems/views.py b/apps/tasks/views.py similarity index 52% rename from apps/problems/views.py rename to apps/tasks/views.py index ebaff9b..355fe1c 100644 --- a/apps/problems/views.py +++ b/apps/tasks/views.py @@ -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" diff --git a/server/settings/base.py b/server/settings/base.py index d6dacd4..1b74449 100644 --- a/server/settings/base.py +++ b/server/settings/base.py @@ -79,7 +79,7 @@ LOCAL_APPS = [ "apps.users", "apps.contests", - "apps.problems", + "apps.tasks", ] INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS diff --git a/server/urls.py b/server/urls.py index 58d3041..16ff87c 100644 --- a/server/urls.py +++ b/server/urls.py @@ -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")), ] diff --git a/templates/contests/detail.html b/templates/contests/detail.html index 9ded3e8..5c03c49 100644 --- a/templates/contests/detail.html +++ b/templates/contests/detail.html @@ -28,31 +28,31 @@

Tasks

- {% for problem in contest.problems.all %} + {% for task in contest.tasks.all %} - {% if problem.is_accessible %} - - {{ problem }} + {% if task.is_accessible %} + + {{ task }} {% else %} - {{ problem }} + {{ task }} {% endif %} - {{ problem.score|default:"???" }} + {{ task.score|default:"???" }} - {% if problem.memory_limit %} - {{ problem.memory_limit|filesizeformat }} + {% if task.memory_limit %} + {{ task.memory_limit|filesizeformat }} {% else %} Unlimited {% endif %} - {% 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 %} diff --git a/templates/contests/index.html b/templates/contests/index.html index 7e1ef71..2f3a37f 100644 --- a/templates/contests/index.html +++ b/templates/contests/index.html @@ -44,10 +44,10 @@

Upcoming Contests

  • Duration: {{ contest.start_time|timesince:contest.end_time }}
  • - {% if contest.problems.all.count > 0 %} + {% if contest.tasks.all.count > 0 %}
  • - {{ contest.problems.all.count }} - problem{{ contest.problems.all.count|pluralize:"s" }} + {{ contest.tasks.all.count }} + task{{ contest.tasks.all.count|pluralize:"s" }}
  • {% endif %} @@ -97,10 +97,10 @@

    Past Contests

  • Duration: {{ contest.start_time|timesince:contest.end_time }}
  • - {% if contest.problems.all.count > 0 %} + {% if contest.tasks.all.count > 0 %}
  • - {{ contest.problems.all.count }} - problem{{ contest.problems.all.count|pluralize:"s" }} + {{ contest.tasks.all.count }} + task{{ contest.tasks.all.count|pluralize:"s" }}
  • {% endif %} diff --git a/templates/problems/detail.html b/templates/problems/detail.html deleted file mode 100644 index 0966121..0000000 --- a/templates/problems/detail.html +++ /dev/null @@ -1,39 +0,0 @@ -{% extends "base.html" %} - -{% block title %}{{ problem.title }}{% endblock title %} - -{% block content %} -
    -

    - - {{ problem.title }} - -

    -
    - -
    -

    - Score: {{ problem.score|default:"???" }} -

    -

    - Memory limit: - {% if problem.memory_limit %} - {{ problem.memory_limit|filesizeformat }} - {% else %} - Unlimited - {% endif %} -

    -

    - Time limit: - {% if problem.time_limit %} - {{ problem.time_limit }} - second{{ problem.time_limit|pluralize:"s" }} - {% else %} - Unlimited - {% endif %} -

    -
    -
    -

    {{ problem.description }}

    -
    -{% endblock content %} diff --git a/templates/tasks/detail.html b/templates/tasks/detail.html new file mode 100644 index 0000000..9ab07fc --- /dev/null +++ b/templates/tasks/detail.html @@ -0,0 +1,39 @@ +{% extends "base.html" %} + +{% block title %}{{ task.title }}{% endblock title %} + +{% block content %} +
    +

    + + {{ task.title }} + +

    +
    + +
    +

    + Score: {{ task.score|default:"???" }} +

    +

    + Memory limit: + {% if task.memory_limit %} + {{ task.memory_limit|filesizeformat }} + {% else %} + Unlimited + {% endif %} +

    +

    + Time limit: + {% if task.time_limit %} + {{ task.time_limit }} + second{{ task.time_limit|pluralize:"s" }} + {% else %} + Unlimited + {% endif %} +

    +
    +
    +

    {{ task.description }}

    +
    +{% endblock content %}