diff --git a/competition/models.py b/competition/models.py index d09ad79..140204d 100644 --- a/competition/models.py +++ b/competition/models.py @@ -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): @@ -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) diff --git a/competition/views.py b/competition/views.py index 233dc89..57e5507 100644 --- a/competition/views.py +++ b/competition/views.py @@ -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 ...)"""