diff --git a/core/admin.py b/core/admin.py index d6ab11f..9fe2b22 100644 --- a/core/admin.py +++ b/core/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .models import Pin, Board +from .models import Pin, Board, SystemParameter class PinAdmin(admin.ModelAdmin): @@ -9,3 +9,4 @@ class PinAdmin(admin.ModelAdmin): admin.site.register(Pin, PinAdmin) admin.site.register(Board) +admin.site.register(SystemParameter) diff --git a/core/models.py b/core/models.py index 8a70dc8..3603cc7 100644 --- a/core/models.py +++ b/core/models.py @@ -99,6 +99,12 @@ class Pin(models.Model): return '%s - %s' % (self.submitter, self.published) +class SystemParameter(models.Model): + name = models.CharField(max_length=32, blank=False) + key = models.CharField(max_length=64, blank=False, unique=True, db_index=True) + value = models.TextField(max_length=4096, blank=True) + + @receiver(models.signals.post_delete, sender=Pin) def delete_pin_images(sender, instance, **kwargs): try: diff --git a/core/serializers.py b/core/serializers.py index 7e5ca67..aae9898 100644 --- a/core/serializers.py +++ b/core/serializers.py @@ -4,7 +4,7 @@ from rest_framework import serializers from rest_framework.exceptions import ValidationError from taggit.models import Tag -from core.models import Image, Board +from core.models import Image, Board, SystemParameter from core.models import Pin from django_images.models import Thumbnail from users.serializers import UserSerializer @@ -260,3 +260,12 @@ class TagAutoCompleteSerializer(serializers.ModelSerializer): class Meta: model = Tag fields = ('name', ) + + +class SystemParameterSerializer(serializers.ModelSerializer): + + class Meta: + model = SystemParameter + fields = ("name", "key", "value") + + value = serializers.JSONField() diff --git a/core/views.py b/core/views.py index df4a7d7..3235ec3 100644 --- a/core/views.py +++ b/core/views.py @@ -7,8 +7,8 @@ from rest_framework.viewsets import GenericViewSet from taggit.models import Tag from core import serializers as api -from core.models import Image, Pin, Board -from core.permissions import IsOwnerOrReadOnly, OwnerOnlyIfPrivate +from core.models import Image, Pin, Board, SystemParameter +from core.permissions import IsOwnerOrReadOnly, OwnerOnlyIfPrivate, SuperUserOnly from core.serializers import filter_private_pin, filter_private_board @@ -77,9 +77,17 @@ class TagAutoCompleteViewSet(mixins.ListModelMixin, viewsets.GenericViewSet): ) +class SystemParameterViewSet(viewsets.ModelViewSet): + queryset = SystemParameter.objects.all() + serializer_class = api.SystemParameterSerializer + pagination_class = None + permission_classes = [SuperUserOnly, ] + + drf_router = routers.DefaultRouter() drf_router.register(r'pins', PinViewSet, basename="pin") drf_router.register(r'images', ImageViewSet) drf_router.register(r'boards', BoardViewSet, basename="board") drf_router.register(r'tags-auto-complete', TagAutoCompleteViewSet) drf_router.register(r'boards-auto-complete', BoardAutoCompleteViewSet, basename="board") +drf_router.register(r'system-parameters', SystemParameterViewSet, basename="system-parameter")