-
Notifications
You must be signed in to change notification settings - Fork 8
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
Logo model #243
Logo model #243
Changes from 3 commits
df80b0a
043f0bc
a5a84c7
61b360e
2efaeb2
812707b
7e24780
1206a27
449ae21
ddb7a57
82c5ecd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
from rest_framework import viewsets | ||
from rest_framework import viewsets, exceptions, status | ||
from rest_framework.decorators import action | ||
from rest_framework.response import Response | ||
|
||
from cms.models import InfoBanner, MenuItem, MessageTemplate, Post | ||
from cms.models import InfoBanner, MenuItem, MessageTemplate, Post, Logo | ||
from cms.permissions import PostPermission | ||
from cms.serializers import (InfoBannerSerializer, MenuItemShortSerializer, | ||
MessageTemplateSerializer, PostSerializer) | ||
MessageTemplateSerializer, PostSerializer, LogoSerializer) | ||
|
||
from django.http import HttpResponse | ||
from base.utils import mime_type | ||
|
||
class MenuItemViewSet(viewsets.ReadOnlyModelViewSet): | ||
"""Položky menu""" | ||
|
@@ -45,6 +47,47 @@ def visible(self, request): | |
return Response(serializer.data) | ||
|
||
|
||
class LogoViewSet(viewsets.ModelViewSet): | ||
"""Publikácie(výsledky, brožúrky, časopisy, ...)""" | ||
queryset = Logo.objects.all() | ||
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=['get'], detail=True, url_path='download') | ||
def download_logo(self, request): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Túto metódu netreba. Stačí ak v response príde link na súbor. Tento súbor sa totiž bude servovať staticky |
||
"""Stiahne logo""" | ||
logo = self.get_object() | ||
response = HttpResponse( | ||
logo.file, content_type=mime_type(logo.file)) | ||
response['Content-Disposition'] = f'attachment; filename="{logo.name}"' | ||
return response | ||
|
||
@action(methods=['post'], detail=False, url_path='upload') | ||
def upload_publication(self, request): | ||
"""Nahrá súbor publikácie""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Toto by sa nemalo volať upload_publication |
||
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') | ||
|
||
return Response(status=status.HTTP_201_CREATED) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tento endpoint iba skontroluje ci tam je file. Ale nevytvori objekt. |
||
|
||
|
||
|
||
class InfoBannerViewSet(viewsets.ModelViewSet): | ||
"""Správy v čiernom info banneri""" | ||
serializer_class = InfoBannerSerializer | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Toto by nemalo byt potrebne pridavat