Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not require publication file on patch request #485

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading