mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-16 01:13:47 +00:00
完善公告管理
This commit is contained in:
parent
e98437b02e
commit
72d062d146
@ -2,12 +2,11 @@
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from django.shortcuts import render
|
||||
from django.utils.translation import ugettext as _
|
||||
from utils.shortcuts import serializer_invalid_response, error_response, success_response
|
||||
|
||||
from utils.shortcuts import paginate, error_page
|
||||
from account.models import SUPER_ADMIN, ADMIN
|
||||
from account.decorators import super_admin_required
|
||||
from group.models import Group
|
||||
from .models import Announcement
|
||||
from .serializers import (CreateAnnouncementSerializer, AnnouncementSerializer,
|
||||
EditAnnouncementSerializer)
|
||||
@ -72,8 +71,12 @@ class AnnouncementAdminAPIView(APIView):
|
||||
---
|
||||
response_serializer: AnnouncementSerializer
|
||||
"""
|
||||
announcement_id = request.GET.get("announcement_id")
|
||||
if announcement_id:
|
||||
try:
|
||||
announcement = Announcement.objects.get(id=announcement_id)
|
||||
return success_response(AnnouncementSerializer(announcement).data)
|
||||
except Announcement.DoesNotExist:
|
||||
return error_response(_("Announcement does not exist"))
|
||||
announcement = Announcement.objects.all().order_by("-create_time")
|
||||
visible = request.GET.get("visible", None)
|
||||
if visible:
|
||||
announcement = announcement.filter(visible=(visible == "true"))
|
||||
return paginate(request, announcement, AnnouncementSerializer)
|
||||
|
@ -6,7 +6,7 @@
|
||||
<div class="row">
|
||||
<div class="form-group col-md-12">
|
||||
<label>{{ $t("adminUtils.title") }}</label>
|
||||
<input type="text" class="form-control">
|
||||
<input type="text" class="form-control" v-model="title" required>
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label>{{ $t("adminUtils.content") }}</label>
|
||||
@ -24,15 +24,24 @@
|
||||
|
||||
export default({
|
||||
data() {
|
||||
return {}
|
||||
return {
|
||||
title: ""
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
submit() {
|
||||
|
||||
var content = this.$refs.editor.getContent();
|
||||
if (!content) {
|
||||
alert(this.$t("announcement.contentCanNotBeEmpty"));
|
||||
return;
|
||||
}
|
||||
this.request({
|
||||
url: "/api/admin/announcement/",
|
||||
method: "post",
|
||||
data: {title: this.title, content: content}
|
||||
})
|
||||
}
|
||||
},
|
||||
route: {
|
||||
},
|
||||
components: {
|
||||
simditor
|
||||
}
|
||||
|
@ -7,13 +7,17 @@
|
||||
<div class="row">
|
||||
<div class="form-group col-md-12">
|
||||
<label>{{ $t("adminUtils.title") }}</label>
|
||||
<input type="text" class="form-control">
|
||||
<input type="text" class="form-control" v-model="announcement.title" required>
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label>{{ $t("adminUtils.content") }}</label>
|
||||
<simditor editorid="editAnnouncement" :content="content" v-ref:editor></simditor>
|
||||
<simditor editorid="editAnnouncement" v-ref:editor></simditor>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ $t("adminUtils.isVisible") }}</label>
|
||||
<input type="checkbox" class="form-control" v-model="announcement.visible">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="submit" class="btn btn-success" value='{{ $t("adminUtils.saveChanges") }}'>
|
||||
</div>
|
||||
@ -27,13 +31,33 @@
|
||||
export default({
|
||||
data() {
|
||||
return {
|
||||
announcement: {},
|
||||
content: ""
|
||||
announcement: {}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
submit() {
|
||||
|
||||
this.request({
|
||||
url: "/api/admin/announcement/",
|
||||
method: "put",
|
||||
data: {
|
||||
id: this.$route.params.announcementId,
|
||||
title: this.announcement.title,
|
||||
content: this.$refs.editor.getContent(),
|
||||
visible: this.announcement.visible
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
route: {
|
||||
data() {
|
||||
this.request({
|
||||
url: "/api/admin/announcement/?announcement_id=" + this.$route.params.announcementId,
|
||||
method: "get",
|
||||
success: (data)=> {
|
||||
this.announcement = data.data;
|
||||
this.$refs.editor.setContent(data.data.content);
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
components: {
|
||||
|
@ -14,9 +14,6 @@
|
||||
props: {
|
||||
editorid: {
|
||||
required: true
|
||||
},
|
||||
content: {
|
||||
required: true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -48,8 +48,7 @@ export default {
|
||||
announcementList: "公告列表",
|
||||
editAnnouncement: "编辑公告",
|
||||
createAnnouncement: "创建公告",
|
||||
|
||||
|
||||
contentCanNotBeEmpty: "内容不能为空"
|
||||
|
||||
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user