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

Commit

Permalink
refactor(apps/tasks): refactor some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
bitterteriyaki committed Dec 4, 2023
1 parent 54ce49a commit 1313268
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
14 changes: 11 additions & 3 deletions apps/tasks/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
from django.contrib.admin import ModelAdmin, register
from django.contrib.postgres.forms import SimpleArrayField
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.forms import CharField, IntegerField, ModelForm, Textarea
from django.forms.fields import FileField
from django.forms import (
CharField,
FileField,
IntegerField,
ModelForm,
Textarea,
)
from django.http import HttpRequest
from django.utils.translation import gettext_lazy as _

Expand All @@ -20,7 +25,7 @@

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

memory_limit = IntegerField(
Expand Down Expand Up @@ -63,6 +68,9 @@ def save_model(
form: TaskModelForm,
change: bool,
) -> None:
if change and len(request.FILES) == 0:
return super().save_model(request, obj, form, change)

Check warning on line 72 in apps/tasks/admin.py

View check run for this annotation

Codecov / codecov/patch

apps/tasks/admin.py#L72

Added line #L72 was not covered by tests

# request.FILES does not cast to the correct type so we need to
# cast it manually, otherwise Mypy will complain.
input_file = cast(InMemoryUploadedFile, request.FILES["input_file"])
Expand Down
1 change: 1 addition & 0 deletions server/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.humanize",
"django.contrib.postgres",
]

THIRD_PARTY_APPS = [
Expand Down
17 changes: 8 additions & 9 deletions templates/tasks/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,17 @@ <h1>
<h4>Description</h4>
<p>{{ task.description }}</p>

<hr>

<h4>Constraints</h4>
<ul>
{% if task.constraints %}
{% for constraint in task.constraints %}
<li>
{{ constraint }}
</li>
{% endfor %}
{% else %}
<li> None </li>
{% endif %}
{% for constraint in task.constraints %}
<li>{{ constraint }}</li>
{% empty %}
<li>None</li>
{% endfor %}
</ul>

<hr>

<form method="post">
Expand Down

0 comments on commit 1313268

Please sign in to comment.