This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from unb-mds/feature/problems
[feature request] Adicionar app inicial de problemas
- Loading branch information
Showing
20 changed files
with
393 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
from django.urls import path | ||
|
||
from apps.contests.views import DetailView, IndexView, send | ||
from apps.contests.views import DetailView | ||
|
||
app_name = "contests" | ||
|
||
urlpatterns = [ | ||
path("", IndexView.as_view(), name="index"), | ||
path("<int:pk>/", DetailView.as_view(), name="detail"), | ||
path("<int:contest_id>/send/", send, name="send"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.apps import AppConfig | ||
|
||
default_app_config = "apps.problems.ProblemsConfig" | ||
|
||
|
||
class ProblemsConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "apps.problems" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
from django.contrib.admin import ModelAdmin, register | ||
from django.forms import CharField, IntegerField, ModelForm, Textarea | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from apps.problems.models import Problem | ||
|
||
if TYPE_CHECKING: | ||
ProblemAdminBase = ModelAdmin[Problem] | ||
ProblemModelFormBase = ModelForm[Problem] | ||
else: | ||
ProblemAdminBase = ModelAdmin | ||
ProblemModelFormBase = ModelForm | ||
|
||
|
||
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 | ||
fields = "__all__" | ||
|
||
|
||
@register(Problem) | ||
class ProblemAdmin(ProblemAdminBase): | ||
form = ProblemModelForm | ||
|
||
list_display = ("title", "contest", "memory_limit", "time_limit") | ||
list_filter = ("contest", "score") | ||
|
||
fieldsets = [ | ||
(_("General"), {"fields": ("title", "description")}), | ||
(_("Meta"), {"fields": ("contest", "score")}), | ||
(_("Limits"), {"fields": ("memory_limit", "time_limit")}), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Generated by Django 4.2.5 on 2023-10-03 12:48 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [ | ||
("contests", "0002_contest_cancelled"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Problem", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
("title", models.CharField(max_length=256)), | ||
("description", models.CharField(max_length=4096)), | ||
( | ||
"contest", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="problems", | ||
to="contests.contest", | ||
), | ||
), | ||
], | ||
options={ | ||
"ordering": ["-created_at", "-updated_at"], | ||
"abstract": False, | ||
}, | ||
), | ||
] |
20 changes: 20 additions & 0 deletions
20
apps/problems/migrations/0002_alter_problem_options_alter_problem_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 4.2.5 on 2023-10-03 17:07 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("problems", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name="problem", | ||
options={}, | ||
), | ||
migrations.AlterModelTable( | ||
name="problem", | ||
table="problems", | ||
), | ||
] |
27 changes: 27 additions & 0 deletions
27
apps/problems/migrations/0003_problem_memory_limit_problem_score_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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 | ||
|
||
|
||
class Problem(TimestampedModel): | ||
"""Represents a problem in a contest.""" | ||
|
||
title = CharField(max_length=256) | ||
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.urls import path | ||
|
||
from apps.problems.views import DetailView | ||
|
||
app_name = "problems" | ||
|
||
urlpatterns = [ | ||
path("<int:pk>/", DetailView.as_view(), name="detail"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
from django.views import generic | ||
|
||
from apps.problems.models import Problem | ||
|
||
if TYPE_CHECKING: | ||
DetailViewBase = generic.DetailView[Problem] | ||
else: | ||
DetailViewBase = generic.DetailView | ||
|
||
|
||
class DetailView(DetailViewBase): | ||
model = Problem | ||
template_name = "problems/detail.html" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
from django.contrib import admin | ||
from django.urls import include, path | ||
from django.views.generic import TemplateView | ||
|
||
home_view = TemplateView.as_view(template_name="pages/home.html") | ||
register_view = TemplateView.as_view( | ||
template_name="registration/register.html" | ||
) | ||
from apps.contests.views import IndexView | ||
|
||
urlpatterns = [ | ||
# Django views | ||
path("admin/", admin.site.urls), | ||
path("", include("django.contrib.auth.urls")), | ||
# Local views | ||
path("", home_view, name="home"), | ||
path("", IndexView.as_view(), name="home"), | ||
path("contests/", include("apps.contests.urls")), | ||
path("problems/", include("apps.problems.urls")), | ||
] |
Oops, something went wrong.