From 1675eed67d73a0bf04daa9c0eacf806128ea6828 Mon Sep 17 00:00:00 2001 From: hohoTT <609029365@qq.com> Date: Thu, 6 Aug 2015 19:07:46 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Announcement=E7=9A=84API?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=EF=BC=8C=E5=8D=B3url=E4=B8=AD=E7=9A=84announ?= =?UTF-8?q?cement=5Flist=5Fapi=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=85=AC?= =?UTF-8?q?=E5=91=8A=E7=BC=96=E8=BE=91=E5=8F=8A=E7=9B=B8=E5=BA=94=E7=9A=84?= =?UTF-8?q?API=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/views.py | 1 + announcement/serializers.py | 6 +++++ announcement/tests.py | 44 +++++++++++++++++++++++++++++++++++-- announcement/views.py | 25 ++++++++++++++++++++- 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/account/views.py b/account/views.py index ea13663..7214c8a 100644 --- a/account/views.py +++ b/account/views.py @@ -97,6 +97,7 @@ class UsernameCheckAPIView(APIView): else: return serializer_invalid_response(serializer) + class EmailCheckAPIView(APIView): def post(self, request): """ diff --git a/announcement/serializers.py b/announcement/serializers.py index a195b2e..d6380b0 100644 --- a/announcement/serializers.py +++ b/announcement/serializers.py @@ -22,3 +22,9 @@ class AnnouncementSerializer(serializers.ModelSerializer): class Meta: model = Announcement + +class EditAnnouncementSerializer(serializers.Serializer): + id = serializers.IntegerField() + title = serializers.CharField(max_length=50) + content = serializers.CharField(max_length=10000) + visible = serializers.BooleanField() diff --git a/announcement/tests.py b/announcement/tests.py index f337a9c..a7fd120 100644 --- a/announcement/tests.py +++ b/announcement/tests.py @@ -4,9 +4,10 @@ from django.core.urlresolvers import reverse from rest_framework.test import APITestCase, APIClient from account.models import User +from announcement.models import Announcement -class AnnouncementAPITest(APITestCase): +class AnnouncementAdminAPITest(APITestCase): def setUp(self): self.client = APIClient() self.url = reverse("announcement_admin_api") @@ -14,6 +15,7 @@ class AnnouncementAPITest(APITestCase): user.set_password("test") user.save() + # 以下是发布公告的测试 def test_invalid_format(self): self.client.login(username="test", password="test") data = {"title": "test1"} @@ -24,4 +26,42 @@ class AnnouncementAPITest(APITestCase): self.client.login(username="test", password="test") data = {"title": "title0", "content": "content0"} response = self.client.post(self.url, data=data) - self.assertEqual(response.data, {"code": 0, "data": u"公告发布成功!"}) \ No newline at end of file + self.assertEqual(response.data, {"code": 0, "data": u"公告发布成功!"}) + + def test_post_invalid_data(self): + self.client.login(username="test", password="test") + data = {"title": "test"} + response = self.client.post(self.url, data=data) + self.assertEqual(response.data["code"], 1) + + # 以下是编辑公告的测试 + def test_put_invalid_data(self): + self.client.login(username="test", password="test") + data = {"title": "test0", "content": "test0", "visible": "True"} + response = self.client.put(self.url, data=data) + self.assertEqual(response.data["code"], 1) + + def test_announcement_does_not_exist(self): + announcement = Announcement.objects.create(title="aa", + content="AA", + created_by=User.objects.get(username="test")) + data = {"id": announcement.id + 1, "title": "11", "content": "22", "visible": True} + response = self.client.put(self.url, data=data) + self.assertEqual(response.data, {"code": 1, "data": u"该公告不存在!"}) + + def test_success_edit_announcement(self): + announcement = Announcement.objects.create(title="bb", + content="BB", + created_by=User.objects.get(username="test")) + data = {"id": announcement.id, "title": "11", "content": "22", "visible": True} + response = self.client.put(self.url, data=data) + self.assertEqual(response.data["code"], 0) + + +class AnnouncementAPITest(APITestCase): + def setUp(self): + self.client = APIClient() + self.url = reverse("announcement_list_api") + + def test_success_get_data(self): + self.assertEqual(self.client.get(self.url).data["code"], 0) diff --git a/announcement/views.py b/announcement/views.py index 9649875..bc14889 100644 --- a/announcement/views.py +++ b/announcement/views.py @@ -6,7 +6,8 @@ from utils.shortcuts import serializer_invalid_response, error_response, success from account.models import User from utils.shortcuts import paginate from .models import Announcement -from .serializers import CreateAnnouncementSerializer, AnnouncementSerializer +from .serializers import (CreateAnnouncementSerializer, AnnouncementSerializer, + EditAnnouncementSerializer) class AnnouncementAdminAPIView(APIView): @@ -26,6 +27,28 @@ class AnnouncementAdminAPIView(APIView): else: return serializer_invalid_response(serializer) + def put(self, request): + """ + 公告编辑json api接口 + --- + request_serializer: EditAnnouncementSerializer + response_serializer: AnnouncementSerializer + """ + serializer = EditAnnouncementSerializer(data=request.DATA) + if serializer.is_valid(): + data = serializer.data + try: + announcement = Announcement.objects.get(id=data["id"]) + except Announcement.DoesNotExist: + return error_response(u"该公告不存在!") + announcement.title = data["title"] + announcement.content = data["content"] + announcement.visible = data["visible"] + announcement.save() + return success_response(AnnouncementSerializer(announcement).data) + else: + return serializer_invalid_response(serializer) + class AnnouncementAPIView(APIView): def get(self, request): From ab63ac652fc2ee838ce58e8caa1a6dd8ec3b66f7 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Thu, 6 Aug 2015 23:47:28 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E5=88=86=E7=A6=BB=E5=85=AC=E5=85=B1=20js?= =?UTF-8?q?=EF=BC=9B=E4=BF=AE=E6=94=B9=20footer=20=E6=95=88=E6=9E=9C?= =?UTF-8?q?=EF=BC=8C=E5=9B=BA=E5=AE=9A=E5=9C=A8=E5=BA=95=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/css/admin.css | 24 +++++++----------------- static/src/css/global.css | 15 +++++++++++++++ static/src/css/oj.css | 19 ------------------- 3 files changed, 22 insertions(+), 36 deletions(-) create mode 100644 static/src/css/global.css diff --git a/static/src/css/admin.css b/static/src/css/admin.css index 75fc901..e54f0e3 100644 --- a/static/src/css/admin.css +++ b/static/src/css/admin.css @@ -1,25 +1,15 @@ +@import url("global.css"); @import url("bootstrap/bootstrap.min.css"); @import url("bootstrap/todc-bootstrap.min.css"); @import url("codeMirror/codemirror.css"); @import url("simditor/simditor.css"); @import url("webuploader/webuploader.css"); @import url("datetime_picker/bootstrap-datetimepicker.css"); -html, body { - height: 100%; -} -img { - max-width: 100%; - height: auto; -} - -.footer { - padding-top: 30px; - padding-bottom: 30px; - float: bottom; - bottom: 0; -} - -label { - font-size: 16px; +#loading-gif{ + width: 40px; + height: 40px; + margin: auto; + position: absolute; + top: 0; left: 0; bottom: 0; right: 0; } \ No newline at end of file diff --git a/static/src/css/global.css b/static/src/css/global.css new file mode 100644 index 0000000..edc04a7 --- /dev/null +++ b/static/src/css/global.css @@ -0,0 +1,15 @@ +img { + max-width: 100%; + height: auto; +} + +.footer { + left: 0; + right: 0; + position: absolute; + bottom: 30px; +} + +label { + font-size: 16px; +} \ No newline at end of file diff --git a/static/src/css/oj.css b/static/src/css/oj.css index fcf80dd..5e1bfc5 100644 --- a/static/src/css/oj.css +++ b/static/src/css/oj.css @@ -1,25 +1,7 @@ @import url("bootstrap/bootstrap.min.css"); @import url("bootstrap/todc-bootstrap.min.css"); @import url("codeMirror/codemirror.css"); -html, body { - height: 100%; -} -img { - max-width: 100%; - height: auto; -} - -.footer { - padding-top: 30px; - padding-bottom: 30px; - float: bottom; - bottom: 0; -} - -label { - font-size: 16px; -} #language-selector { width: 130px; @@ -47,7 +29,6 @@ label { font-size: 15px; } -/* index css */ .jumbotron { text-align: center; background-color: transparent; From d6a36fe20ce722b89e06d8e81337626b557c4a89 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Thu, 6 Aug 2015 23:47:54 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E6=95=88=E6=9E=9C=E5=92=8C=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E7=9A=84=20js=20=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/app/admin/admin.js | 6 +++++- template/admin/admin.html | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/static/src/js/app/admin/admin.js b/static/src/js/app/admin/admin.js index d3e30ac..b44f575 100644 --- a/static/src/js/app/admin/admin.js +++ b/static/src/js/app/admin/admin.js @@ -20,12 +20,16 @@ define("admin", ["jquery", "avalon"], function($, avalon){ if(hash){ li_inactive(".list-group-item"); li_active("#li-" + hash); + $("#loading-gif").show(); vm.template_url = "template/index/" + hash + ".html"; } }; var vm = avalon.define({ $id: "admin", - template_url: "template/index/index.html" + template_url: "template/index/index.html", + hide_loading: function(){ + $("#loading-gif").hide(); + } }); }); \ No newline at end of file diff --git a/template/admin/admin.html b/template/admin/admin.html index c712084..6ec5a4e 100644 --- a/template/admin/admin.html +++ b/template/admin/admin.html @@ -81,9 +81,9 @@ - + -
+
From a66b755aa3327acd024db892e2e616be707646f1 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Fri, 7 Aug 2015 17:11:20 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20footer=20=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=BD=8D=E7=BD=AE=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/css/global.css | 16 ++++++++++++++-- static/src/css/oj.css | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/static/src/css/global.css b/static/src/css/global.css index edc04a7..c55a0bb 100644 --- a/static/src/css/global.css +++ b/static/src/css/global.css @@ -1,3 +1,16 @@ +html{ + height: 100%; +} + +body{ + height:100%; /*使内容高度和body一样*/ + margin-bottom:-80px;/*向上缩减80像素,不至于footer超出屏幕可视范围*/ +} + +.main{ + padding-bottom: 120px; +} + img { max-width: 100%; height: auto; @@ -6,8 +19,7 @@ img { .footer { left: 0; right: 0; - position: absolute; - bottom: 30px; + height: 80px } label { diff --git a/static/src/css/oj.css b/static/src/css/oj.css index 5e1bfc5..cc6ac62 100644 --- a/static/src/css/oj.css +++ b/static/src/css/oj.css @@ -1,3 +1,4 @@ +@import url("global.css"); @import url("bootstrap/bootstrap.min.css"); @import url("bootstrap/todc-bootstrap.min.css"); @import url("codeMirror/codemirror.css"); From 2475407597b9f9078a319f286c9c64beacb55914 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Fri, 7 Aug 2015 17:12:08 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=89=8D=E5=8F=B0=E7=BD=91=E9=A1=B5?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E7=9A=84=20class=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20footer=20=E6=98=BE=E7=A4=BA=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/oj/account/change_password.html | 2 +- template/oj/account/login.html | 2 +- template/oj/account/register.html | 2 +- template/oj/contest/problems.html | 2 +- template/oj/problem/problem.html | 2 +- template/oj/problem/problem_list.html | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/template/oj/account/change_password.html b/template/oj/account/change_password.html index 65de447..dd0d84e 100644 --- a/template/oj/account/change_password.html +++ b/template/oj/account/change_password.html @@ -1,6 +1,6 @@ {% extends "oj_base.html" %} {% block body %} -
+

修改密码

diff --git a/template/oj/account/login.html b/template/oj/account/login.html index e9ddbf2..fb4249b 100644 --- a/template/oj/account/login.html +++ b/template/oj/account/login.html @@ -1,6 +1,6 @@ {% extends "oj_base.html" %} {% block body %} -
+

用户登录

diff --git a/template/oj/account/register.html b/template/oj/account/register.html index 34dc9a4..02d66c8 100644 --- a/template/oj/account/register.html +++ b/template/oj/account/register.html @@ -1,6 +1,6 @@ {% extends "oj_base.html" %} {% block body %} -
+

用户注册

diff --git a/template/oj/contest/problems.html b/template/oj/contest/problems.html index 88dd9d2..450415f 100644 --- a/template/oj/contest/problems.html +++ b/template/oj/contest/problems.html @@ -1,6 +1,6 @@ {% extends "oj_base.html" %} {% block body %} -
+