Skip to content

Commit

Permalink
Do not require publication file on patch request (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmihalik authored Dec 15, 2024
1 parent 20f7be6 commit 567bef6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.17 on 2024-12-15 11:12

import base.models
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("competition", "0002_initial"),
]

operations = [
migrations.AlterModelOptions(
name="series",
options={
"ordering": ["semester", "order"],
"verbose_name": "séria",
"verbose_name_plural": "série",
},
),
migrations.AlterField(
model_name="publication",
name="file",
field=base.models.RestrictedFileField(
blank=True, upload_to="publications/%Y/", verbose_name="súbor"
),
),
]
4 changes: 3 additions & 1 deletion competition/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,9 @@ class Meta:
file = RestrictedFileField(
upload_to='publications/%Y/',
content_types=['application/pdf', 'application/zip'],
verbose_name='súbor')
verbose_name='súbor',
blank=True,
)

order = models.PositiveSmallIntegerField(
verbose_name='poradie', null=True, blank=True)
Expand Down
15 changes: 15 additions & 0 deletions competition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,12 +957,27 @@ def perform_create(self, serializer):
Vola sa pri vytvarani objektu,
checkuju sa tu permissions, ci user vie vytvorit publication v danom evente
'''
self._ensure_file_attached(serializer)

if Publication.can_user_create(self.request.user, serializer.validated_data):
serializer.save()
else:
raise exceptions.PermissionDenied(
'Nedostatočné práva na vytvorenie tohoto objektu')

def perform_update(self, serializer):
if not serializer.partial:
self._ensure_file_attached(serializer)

return super().perform_update(serializer)

@staticmethod
def _ensure_file_attached(serializer: PublicationSerializer):
if 'file' not in serializer.validated_data:
raise exceptions.ValidationError(
'Publikácia musí mať pripojený súbor'
)


class GradeViewSet(viewsets.ReadOnlyModelViewSet):
"""Ročníky riešiteľov (Z9,S1 ...)"""
Expand Down

0 comments on commit 567bef6

Please sign in to comment.