diff --git a/announcement/serializers.py b/announcement/serializers.py index dde620ef..22531d0e 100644 --- a/announcement/serializers.py +++ b/announcement/serializers.py @@ -25,6 +25,11 @@ class EditAnnouncementSerializer(serializers.Serializer): 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): created_by = UsernameSerializer() diff --git a/announcement/views/admin.py b/announcement/views/admin.py index bb2827ea..c54fe02e 100644 --- a/announcement/views/admin.py +++ b/announcement/views/admin.py @@ -3,7 +3,7 @@ from utils.api import APIView, validate_serializer from announcement.models import (Announcement, AboutUs) from announcement.serializers import (AnnouncementSerializer, CreateAnnouncementSerializer, EditAnnouncementSerializer, - AboutUsSerializer, EditAboutUsSerializer) + AboutUsSerializer, EditAboutUsSerializer, CreateAboutUsSerializer) class AnnouncementAdminAPI(APIView): @@ -63,6 +63,18 @@ class AnnouncementAdminAPI(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) @super_admin_required def put(self, request): @@ -71,7 +83,7 @@ class AboutUsAdminAPI(APIView): """ data = request.data try: - aboutus = AboutUs.objects.get(content=data.pop("title")) + aboutus = AboutUs.objects.get(title=data.pop("title")) except AboutUs.DoesNotExist: return self.error("AboutUs does not exist") @@ -89,7 +101,7 @@ class AboutUsAdminAPI(APIView): aboutus_id = request.GET.get("title") if aboutus_id: try: - aboutus = AboutUs.objects.get(content=aboutus_id) + aboutus = AboutUs.objects.get(title=aboutus_id) return self.success(AboutUsSerializer(aboutus).data) except AboutUs.DoesNotExist: return self.error("AboutUs does not exist")