From 72d062d1462e11f1b208725ccb6a380fcdcd8835 Mon Sep 17 00:00:00 2001 From: LiYang Date: Tue, 2 Aug 2016 20:50:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=85=AC=E5=91=8A=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- announcement/views.py | 13 ++++--- .../announcement/createAnnouncement.vue | 19 ++++++++--- .../announcement/editAnnouncement.vue | 34 ++++++++++++++++--- .../admin/src/components/utils/simditor.vue | 3 -- frontend/admin/src/locales.js | 3 +- 5 files changed, 52 insertions(+), 20 deletions(-) diff --git a/announcement/views.py b/announcement/views.py index 17a9fe17..a44bc55b 100644 --- a/announcement/views.py +++ b/announcement/views.py @@ -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) diff --git a/frontend/admin/src/components/announcement/createAnnouncement.vue b/frontend/admin/src/components/announcement/createAnnouncement.vue index b4972d49..e843670f 100644 --- a/frontend/admin/src/components/announcement/createAnnouncement.vue +++ b/frontend/admin/src/components/announcement/createAnnouncement.vue @@ -6,7 +6,7 @@
- +
@@ -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 } diff --git a/frontend/admin/src/components/announcement/editAnnouncement.vue b/frontend/admin/src/components/announcement/editAnnouncement.vue index d4a1f900..aad827d3 100644 --- a/frontend/admin/src/components/announcement/editAnnouncement.vue +++ b/frontend/admin/src/components/announcement/editAnnouncement.vue @@ -7,13 +7,17 @@
- +
- +
+
+ + +
@@ -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: { diff --git a/frontend/admin/src/components/utils/simditor.vue b/frontend/admin/src/components/utils/simditor.vue index b395b2cd..eabf030f 100644 --- a/frontend/admin/src/components/utils/simditor.vue +++ b/frontend/admin/src/components/utils/simditor.vue @@ -14,9 +14,6 @@ props: { editorid: { required: true - }, - content: { - required: true } }, methods: { diff --git a/frontend/admin/src/locales.js b/frontend/admin/src/locales.js index 06cac74d..da3a01d9 100644 --- a/frontend/admin/src/locales.js +++ b/frontend/admin/src/locales.js @@ -48,8 +48,7 @@ export default { announcementList: "公告列表", editAnnouncement: "编辑公告", createAnnouncement: "创建公告", - - + contentCanNotBeEmpty: "内容不能为空" },