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

Commit

Permalink
Merge branch 'main' into feature/others-users-page
Browse files Browse the repository at this point in the history
  • Loading branch information
HladczukLe committed Nov 26, 2023
2 parents 4bad051 + 17120f0 commit af183f9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
32 changes: 32 additions & 0 deletions apps/submissions/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import TYPE_CHECKING

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

from apps.submissions.models import Submission

if TYPE_CHECKING:
SubmissionAdminBase = ModelAdmin[Submission]
SubmissionModelFormBase = ModelForm[Submission]
else:
SubmissionAdminBase = ModelAdmin
SubmissionModelFormBase = ModelForm


class SubmissionModelForm(SubmissionModelFormBase):
code = CharField(widget=Textarea(attrs={"rows": 20, "cols": 80}))

class Meta:
model = Submission
fields = "__all__"


@register(Submission)
class SubmissionAdmin(SubmissionAdminBase):
form = SubmissionModelForm

list_display = ("__str__", "author", "task")
list_filter = ("author", "task", "created_at")

fieldsets = [(_("Details"), {"fields": ("author", "task", "code")})]
21 changes: 21 additions & 0 deletions apps/submissions/tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from datetime import timedelta

from django.contrib.admin.sites import AdminSite
from django.core.exceptions import ValidationError
from django.test import TestCase
from django.utils import timezone
from django.utils.translation import gettext as _

from apps.contests.models import Contest
from apps.submissions.admin import SubmissionAdmin
from apps.submissions.models import Submission
from apps.tasks.models import Task
from apps.users.models import User
Expand Down Expand Up @@ -71,3 +74,21 @@ def test_submission_code_min_length_validator(self) -> None:
submission.full_clean()

self.assertEqual(context.exception.messages, expected)


class SubmissionAdminTest(TestCase):
def setUp(self) -> None:
self.site = AdminSite()
self.submission_admin = SubmissionAdmin(Submission, self.site)

def test_list_display(self) -> None:
expected = ("__str__", "author", "task")
self.assertEqual(self.submission_admin.list_display, expected)

def test_list_filter(self) -> None:
expected = ("author", "task", "created_at")
self.assertEqual(self.submission_admin.list_filter, expected)

def test_fieldsets(self) -> None:
expected = [(_("Details"), {"fields": ("author", "task", "code")})]
self.assertEqual(self.submission_admin.fieldsets, expected)

0 comments on commit af183f9

Please sign in to comment.