Skip to content

Commit

Permalink
Merge pull request #243 from ZdruzenieSTROM/Logo-model
Browse files Browse the repository at this point in the history
Logo model
  • Loading branch information
kovacspe authored Nov 11, 2023
2 parents a13010a + 82c5ecd commit f9a14b1
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
"editor.defaultFormatter": "ms-python.autopep8",
"editor.formatOnSave": true,
}

}
11 changes: 10 additions & 1 deletion cms/admin.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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 = (
Expand Down
19 changes: 19 additions & 0 deletions cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions cms/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions cms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
20 changes: 18 additions & 2 deletions cms/views.py
Original file line number Diff line number Diff line change
@@ -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)


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f9a14b1

Please sign in to comment.