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

Delete duplicate publication endpoint #471

Merged
merged 1 commit into from
Dec 14, 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
4 changes: 3 additions & 1 deletion competition/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ def generate_name(self, forced=False):
self.name = f'{self.publication_type.code}_{self.order}.pdf'
else:
self.name = self.publication_type.name

self.save()

def __str__(self):
Expand All @@ -761,7 +762,8 @@ def can_user_modify(self, user):

@classmethod
def can_user_create(cls, user: User, data: dict) -> bool:
event = Event.objects.get(pk=data['event'])
event = data['event']

return event.can_user_modify(user)


Expand Down
31 changes: 0 additions & 31 deletions competition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,37 +973,6 @@ def download_publication(self, request, pk=None):
f'filename="{publication.name}"'
return response

@action(methods=['post'], detail=False, url_path='upload', permission_classes=[IsAdminUser])
def upload_publication(self, request: Request):
"""Nahrá súbor publikácie"""
if 'file' not in request.data:
raise exceptions.ParseError(detail='Request neobsahoval súbor')

file = request.data['file']
if mime_type(file) not in ['application/pdf', 'application/zip']:
raise exceptions.ParseError(detail='Nesprávny formát')

event = Event.objects.filter(pk=int(request.data['event'])).first()
publication_type = PublicationType.objects.get(
name=request.data['publication_type'])
order = int(request.data.get('order'))

publication = Publication.objects.filter(
event=event, order=order).first()
if publication is None:
publication = Publication(
name=request.data.get('name'),
file=file,
event=event,
order=order,
publication_type=publication_type
)
publication.generate_name()
publication.save()

publication.file.save(publication.name, file)
return Response(status=status.HTTP_201_CREATED)


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