Skip to content

Commit

Permalink
Remove upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe committed Nov 11, 2023
1 parent 449ae21 commit ddb7a57
Showing 1 changed file with 11 additions and 33 deletions.
44 changes: 11 additions & 33 deletions cms/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from rest_framework import viewsets, exceptions, status


from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.exceptions import MethodNotAllowed
from rest_framework.response import Response

from cms.models import InfoBanner, MenuItem, MessageTemplate, Post, Logo
from cms.models import InfoBanner, Logo, MenuItem, MessageTemplate, Post
from cms.permissions import PostPermission
from cms.serializers import (InfoBannerSerializer, MenuItemShortSerializer,
MessageTemplateSerializer, PostSerializer, LogoSerializer)

from base.utils import mime_type
from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
from cms.serializers import (InfoBannerSerializer, LogoSerializer,
MenuItemShortSerializer,
MessageTemplateSerializer, PostSerializer)


class MenuItemViewSet(viewsets.ReadOnlyModelViewSet):
Expand Down Expand Up @@ -55,32 +55,10 @@ class LogoViewSet(viewsets.ModelViewSet):
serializer_class = LogoSerializer
permission_classes = (PostPermission,)

def perform_create(self, serializer):
'''
Vola sa pri vytvarani objektu,
checkuju sa tu permissions, ci user vie vytvorit publication v danom evente
'''
event = serializer.validated_data['event']
if event.can_user_modify(self.request.user):
serializer.save()
else:
raise exceptions.PermissionDenied(
'Nedostatočné práva na vytvorenie tohoto objektu')

@action(methods=['post'], detail=False, url_path='upload')
def upload_logo(self, request):
"""Vytvorí súbor loga"""
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/jpg', 'application/png']:
raise exceptions.ParseError(detail='Nesprávny formát')

default_storage.save(file.name, ContentFile(file.read()))

return Response(status=status.HTTP_201_CREATED)
# TODO: Maybe create upload image endpoint

def create(self, request, *args, **kwargs):
raise MethodNotAllowed('POST')


class InfoBannerViewSet(viewsets.ModelViewSet):
Expand Down

0 comments on commit ddb7a57

Please sign in to comment.