diff --git a/.vscode/settings.json b/.vscode/settings.json index 1c7da639..15f340f1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,4 +6,5 @@ "editor.defaultFormatter": "ms-python.autopep8", "editor.formatOnSave": true, } + } diff --git a/cms/admin.py b/cms/admin.py index 2ae1c98e..09d0ff95 100644 --- a/cms/admin.py +++ b/cms/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin -from cms.models import InfoBanner, MenuItem, MessageTemplate, Post, PostLink +from cms.models import (InfoBanner, Logo, MenuItem, MessageTemplate, Post, + PostLink) @admin.register(MenuItem) @@ -16,6 +17,14 @@ class MenuItemAdmin(admin.ModelAdmin): ) +@admin.register(Logo) +class LogoAdmin(admin.ModelAdmin): + list_display = ( + 'name', + 'disabled' + ) + + @admin.register(Post) class PostAdmin(admin.ModelAdmin): list_display = ( diff --git a/cms/models.py b/cms/models.py index 952dd1ab..46cb1360 100644 --- a/cms/models.py +++ b/cms/models.py @@ -4,6 +4,7 @@ from django.db import models from django.utils.timezone import now +from base.models import RestrictedFileField from competition.models import Event, Series from .querysets import VisibilityQuerySet @@ -111,6 +112,24 @@ class Meta: # zobrazované aj možno niekde inde +class Logo(models.Model): + """ + Logo + """ + class Meta: + verbose_name = 'logo' + verbose_name_plural = 'logá' + + ordering = ['name', ] + + name = models.CharField(verbose_name='názov loga', max_length=150) + disabled = models.BooleanField() + image = RestrictedFileField( + content_types=['image/svg+xml', 'image/png'], + upload_to='logo_images/', + verbose_name='Logo') + + class InfoBanner(ModelWithVisibility): class Meta: verbose_name = 'Informácia v pohyblivom baneri' diff --git a/cms/serializers.py b/cms/serializers.py index ae6c28c0..232fa566 100644 --- a/cms/serializers.py +++ b/cms/serializers.py @@ -27,6 +27,12 @@ class Meta: model = models.Post fields = '__all__' +@ts_interface(context='cms') +class LogoSerializer(serializers.ModelSerializer): + class Meta: + model = models.Logo + fields = '__all__' + @ts_interface(context='cms') class InfoBannerSerializer(serializers.ModelSerializer): diff --git a/cms/urls.py b/cms/urls.py index ef6b9f41..68b22e20 100644 --- a/cms/urls.py +++ b/cms/urls.py @@ -11,6 +11,7 @@ router.register(r'menu-item', views.MenuItemViewSet) router.register(r'info-banner', views.InfoBannerViewSet) router.register(r'message-template', views.MessageTemplateViewSet) +router.register(r'logo', views.LogoViewSet) urlpatterns = [ diff --git a/cms/views.py b/cms/views.py index 604640c5..c3e56811 100644 --- a/cms/views.py +++ b/cms/views.py @@ -1,10 +1,14 @@ + + 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 +from cms.models import InfoBanner, Logo, MenuItem, MessageTemplate, Post from cms.permissions import PostPermission -from cms.serializers import (InfoBannerSerializer, MenuItemShortSerializer, +from cms.serializers import (InfoBannerSerializer, LogoSerializer, + MenuItemShortSerializer, MessageTemplateSerializer, PostSerializer) @@ -45,6 +49,18 @@ def visible(self, request): return Response(serializer.data) +class LogoViewSet(viewsets.ModelViewSet): + """Logá""" + queryset = Logo.objects.all() + serializer_class = LogoSerializer + permission_classes = (PostPermission,) + + # TODO: Maybe create upload image endpoint + + def create(self, request, *args, **kwargs): + raise MethodNotAllowed('POST') + + class InfoBannerViewSet(viewsets.ModelViewSet): """Správy v čiernom info banneri""" serializer_class = InfoBannerSerializer