添加关于我们(未完成)

This commit is contained in:
Harry-zklcdc 2019-04-28 21:24:45 +08:00
parent 1128f62bb1
commit 0e1dc73c6a
2 changed files with 20 additions and 3 deletions

View File

@ -25,6 +25,11 @@ class EditAnnouncementSerializer(serializers.Serializer):
visible = serializers.BooleanField() visible = serializers.BooleanField()
class CreateAboutUsSerializer(serializers.Serializer):
title = serializers.CharField(max_length=64)
content = serializers.CharField(max_length=1024 * 1024 * 8)
class AboutUsSerializer(serializers.ModelSerializer): class AboutUsSerializer(serializers.ModelSerializer):
created_by = UsernameSerializer() created_by = UsernameSerializer()

View File

@ -3,7 +3,7 @@ from utils.api import APIView, validate_serializer
from announcement.models import (Announcement, AboutUs) from announcement.models import (Announcement, AboutUs)
from announcement.serializers import (AnnouncementSerializer, CreateAnnouncementSerializer, EditAnnouncementSerializer, from announcement.serializers import (AnnouncementSerializer, CreateAnnouncementSerializer, EditAnnouncementSerializer,
AboutUsSerializer, EditAboutUsSerializer) AboutUsSerializer, EditAboutUsSerializer, CreateAboutUsSerializer)
class AnnouncementAdminAPI(APIView): class AnnouncementAdminAPI(APIView):
@ -63,6 +63,18 @@ class AnnouncementAdminAPI(APIView):
class AboutUsAdminAPI(APIView): class AboutUsAdminAPI(APIView):
@validate_serializer(CreateAboutUsSerializer)
@super_admin_required
def post(self, request):
"""
publish aboutus
"""
data = request.data
aboutus = AboutUs.objects.create(title=data["title"],
content=data["content"],
created_by=request.user)
return self.success(AboutUsSerializer(aboutus).data)
@validate_serializer(EditAboutUsSerializer) @validate_serializer(EditAboutUsSerializer)
@super_admin_required @super_admin_required
def put(self, request): def put(self, request):
@ -71,7 +83,7 @@ class AboutUsAdminAPI(APIView):
""" """
data = request.data data = request.data
try: try:
aboutus = AboutUs.objects.get(content=data.pop("title")) aboutus = AboutUs.objects.get(title=data.pop("title"))
except AboutUs.DoesNotExist: except AboutUs.DoesNotExist:
return self.error("AboutUs does not exist") return self.error("AboutUs does not exist")
@ -89,7 +101,7 @@ class AboutUsAdminAPI(APIView):
aboutus_id = request.GET.get("title") aboutus_id = request.GET.get("title")
if aboutus_id: if aboutus_id:
try: try:
aboutus = AboutUs.objects.get(content=aboutus_id) aboutus = AboutUs.objects.get(title=aboutus_id)
return self.success(AboutUsSerializer(aboutus).data) return self.success(AboutUsSerializer(aboutus).data)
except AboutUs.DoesNotExist: except AboutUs.DoesNotExist:
return self.error("AboutUs does not exist") return self.error("AboutUs does not exist")