Skip to content

Commit

Permalink
Delete duplicate publication endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmihalik committed Dec 14, 2024
1 parent b7ff676 commit 66a4fbf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 32 deletions.
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

0 comments on commit 66a4fbf

Please sign in to comment.