mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-12-29 16:41:56 +00:00
更新announcement后端
This commit is contained in:
parent
117fd6182a
commit
7c11d7046a
@ -1,4 +1,5 @@
|
||||
# coding=utf-8
|
||||
from __future__ import unicode_literals
|
||||
import StringIO
|
||||
import codecs
|
||||
import os
|
||||
|
@ -7,17 +7,12 @@ from utils.models import RichTextField
|
||||
|
||||
|
||||
class Announcement(models.Model):
|
||||
# 标题
|
||||
title = models.CharField(max_length=50)
|
||||
# 公告的内容 HTML 格式
|
||||
# HTML
|
||||
content = RichTextField()
|
||||
# 创建时间
|
||||
create_time = models.DateTimeField(auto_now_add=True)
|
||||
# 这个公告是谁创建的
|
||||
created_by = models.ForeignKey(User)
|
||||
# 最后更新时间
|
||||
last_update_time = models.DateTimeField(auto_now=True)
|
||||
# 是否可见 false的话相当于删除
|
||||
visible = models.BooleanField(default=True)
|
||||
|
||||
class Meta:
|
||||
|
@ -1,4 +1,5 @@
|
||||
# coding=utf-8
|
||||
from __future__ import unicode_literals
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from django.shortcuts import render
|
||||
@ -14,12 +15,12 @@ from .serializers import (CreateAnnouncementSerializer, AnnouncementSerializer,
|
||||
|
||||
def announcement_page(request, announcement_id):
|
||||
"""
|
||||
公告的详情页面
|
||||
announcement detail page
|
||||
"""
|
||||
try:
|
||||
announcement = Announcement.objects.get(id=announcement_id, visible=True)
|
||||
except Announcement.DoesNotExist:
|
||||
return error_page(request, u"公告不存在")
|
||||
return error_page(request, _("Announcement does not exist"))
|
||||
return render(request, "oj/announcement/announcement.html", {"announcement": announcement})
|
||||
|
||||
|
||||
@ -27,25 +28,22 @@ class AnnouncementAdminAPIView(APIView):
|
||||
@super_admin_required
|
||||
def post(self, request):
|
||||
"""
|
||||
公告发布json api接口
|
||||
---
|
||||
request_serializer: CreateAnnouncementSerializer
|
||||
publish announcement
|
||||
"""
|
||||
serializer = CreateAnnouncementSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
data = serializer.data
|
||||
Announcement.objects.create(title=data["title"], content=data["content"], created_by=request.user)
|
||||
return success_response(u"公告发布成功!")
|
||||
announcement = Announcement.objects.create(title=data["title"],
|
||||
content=data["content"],
|
||||
created_by=request.user)
|
||||
return success_response(AnnouncementSerializer(announcement).data)
|
||||
else:
|
||||
return serializer_invalid_response(serializer)
|
||||
|
||||
@super_admin_required
|
||||
def put(self, request):
|
||||
"""
|
||||
公告编辑json api接口
|
||||
---
|
||||
request_serializer: EditAnnouncementSerializer
|
||||
response_serializer: AnnouncementSerializer
|
||||
edit announcement
|
||||
"""
|
||||
serializer = EditAnnouncementSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
@ -53,7 +51,7 @@ class AnnouncementAdminAPIView(APIView):
|
||||
try:
|
||||
announcement = Announcement.objects.get(id=data["id"])
|
||||
except Announcement.DoesNotExist:
|
||||
return error_response(u"公告不存在")
|
||||
return error_response(_("Announcement does not exist"))
|
||||
|
||||
announcement.title = data["title"]
|
||||
announcement.content = data["content"]
|
||||
@ -67,9 +65,7 @@ class AnnouncementAdminAPIView(APIView):
|
||||
@super_admin_required
|
||||
def get(self, request):
|
||||
"""
|
||||
公告分页json api接口
|
||||
---
|
||||
response_serializer: AnnouncementSerializer
|
||||
get announcement list / get one announcement
|
||||
"""
|
||||
announcement_id = request.GET.get("announcement_id")
|
||||
if announcement_id:
|
||||
|
Loading…
Reference in New Issue
Block a user