Browse Source

Feature: Add SystemParameter for global config

feature/admin-panel
winkidney 3 years ago
parent
commit
5a16ec4ce1
4 changed files with 28 additions and 4 deletions
  1. +2
    -1
      core/admin.py
  2. +6
    -0
      core/models.py
  3. +10
    -1
      core/serializers.py
  4. +10
    -2
      core/views.py

+ 2
- 1
core/admin.py View File

@@ -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)

+ 6
- 0
core/models.py View File

@@ -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:


+ 10
- 1
core/serializers.py View File

@@ -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()

+ 10
- 2
core/views.py View File

@@ -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")

Loading…
Cancel
Save