From de04f0c2e367832e8472ebd883ae52510713e455 Mon Sep 17 00:00:00 2001 From: esp Date: Mon, 31 Aug 2015 20:54:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=89=8D=E5=8F=B0=E5=B0=8F?= =?UTF-8?q?=E7=BB=84=E7=94=B3=E8=AF=B7=E5=92=8C=E7=94=B3=E8=AF=B7=E5=88=97?= =?UTF-8?q?=E8=A1=A8,=E7=9A=84=E4=B8=80=E7=B3=BB=E5=88=97=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2,=E5=B8=A6=E6=B5=8B=E8=AF=95,=E8=BF=99=E4=B8=AA?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E7=B1=BB=E4=BC=BC=E4=B8=8E=E9=A2=98=E7=9B=AE?= =?UTF-8?q?=E5=92=8C=E9=A2=98=E7=9B=AE=E6=8F=90=E4=BA=A4=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=A0=B7=E5=BC=8F=E5=92=8C=E7=BB=93=E6=9E=84(?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E5=85=B3=E7=B3=BB),=E5=86=99?= =?UTF-8?q?=E4=BA=86=E7=AE=80=E7=95=A5=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group/tests.py | 37 +++++++++++++--- oj/urls.py | 3 +- static/src/js/app/oj/group/group.js | 25 +++++++++++ template/src/oj/group/group.html | 40 +++++++++++++++++ template/src/oj/group/my_application.html | 26 +++++++++++ .../src/oj/group/my_application_list.html | 44 +++++++++++++++++++ 6 files changed, 167 insertions(+), 8 deletions(-) create mode 100644 template/src/oj/group/group.html create mode 100644 template/src/oj/group/my_application.html create mode 100644 template/src/oj/group/my_application_list.html diff --git a/group/tests.py b/group/tests.py index 0d56d3b2..208720df 100644 --- a/group/tests.py +++ b/group/tests.py @@ -244,7 +244,7 @@ class JoinGroupRequestAdminAPITest(APITestCase): self.assertEqual(JoinGroupRequest.objects.get(id=self.request.id).status, True) def test_join_group_successfully(self): - data = {"request_id": self.request.id, "status": True} + data = {"request_id": self.request.id, "status": True, "": True} response = self.client.put(self.url, data=data) self.assertEqual(response.data, {"code": 0, "data": u"加入成功"}) UserGroupRelation.objects.get(group=self.group, user=self.user1) @@ -261,15 +261,15 @@ class GroupListPageTest(TestCase): def setUp(self): self.client = Client() self.url = reverse('group_list_page') - self.url = reverse('problem_list_page', kwargs={"page": 1}) + self.url_with_argument = reverse('group_page', kwargs={"page": 1}) self.user = User.objects.create(username="test", admin_type=SUPER_ADMIN) self.user.set_password("testaa") self.user.save() self.group = Group.objects.create(name="group1", - description="description1", - # 0是公开 1是需要申请后加入 2是不允许任何人加入 - join_group_setting = 1, - admin=User.objects.get(username="test")) + description="description1", + # 0是公开 1是需要申请后加入 2是不允许任何人加入 + join_group_setting=1, + admin=User.objects.get(username="test")) def get_group_list_page_successful(self): self.client.login(username="test", password="testaa") @@ -278,6 +278,29 @@ class GroupListPageTest(TestCase): def get_group_list_page_successful_with_keyword(self): self.client.login(username="test", password="testaa") - response = self.client.get(self.url+"?keyword=gro") + response = self.client.get(self.url + "?keyword=gro") self.assertEqual(response.status_coed, 200) + def get_group_list_page_successful_with_page_argument(self): + self.client.login(username="test", password="testaa") + response = self.client.get(self.url_with_argument + "?keyword=gro") + self.assertEqual(response.status_coed, 200) + + +class GroupPageTest(TestCase): + def setUp(self): + self.client = Client() + self.user = User.objects.create(username="test", admin_type=SUPER_ADMIN) + self.user.set_password("testaa") + self.user.save() + self.group = Group.objects.create(name="group1", + description="description1", + # 0是公开 1是需要申请后加入 2是不允许任何人加入 + join_group_setting=1, + admin=User.objects.get(username="test")) + self.url = reverse('group_page', kwargs={"group_id": self.group.id}) + + def get_group_list_page_successful(self): + self.client.login(username="test", password="testaa") + response = self.client.get(self.url) + self.assertEqual(response.status_coed, 200) diff --git a/oj/urls.py b/oj/urls.py index a0f8b670..648c849d 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -105,5 +105,6 @@ urlpatterns = [ url(r'^groups/$', "group.views.group_list_page", name="group_list_page"), url(r'^groups/(?P\d+)/$', "group.views.group_list_page", name="group_list_page"), url(r'^group/(?P\d+)/$', "group.views.group_page", name="group_page"), - + url(r'^group/(?P\d+)/applications/$', "group.views.application_list_page", name="group_application_page"), + url(r'^group/application/(?P\d+)/$', "group.views.application_page", name="group_application") ] diff --git a/static/src/js/app/oj/group/group.js b/static/src/js/app/oj/group/group.js index e69de29b..918b6612 100644 --- a/static/src/js/app/oj/group/group.js +++ b/static/src/js/app/oj/group/group.js @@ -0,0 +1,25 @@ +require(["jquery", "csrfToken", "bsAlert"], function ($, csrfTokenHeader, bsAlert) { + $("#sendApplication").click(function (){ + var message = $("#applyMessage").val(); + console.log(message); + var groupId = window.location.pathname.split("/")[2]; + console.log(groupId); + data = {group_id: groupId,message:message} + $.ajax({ + url: "/api/group_join/", + method: "post", + dataType: "json", + beforeSend: csrfTokenHeader, + data: JSON.stringify(data), + contentType: "application/json", + success: function (data) { + if (data.code) { + bsAlert(data.data); + } + else { + bsAlert("申请已提交!"); + } + } + }) + }) +}) diff --git a/template/src/oj/group/group.html b/template/src/oj/group/group.html new file mode 100644 index 00000000..1686a4cb --- /dev/null +++ b/template/src/oj/group/group.html @@ -0,0 +1,40 @@ +{% extends 'oj_base.html' %} + +{% block body %} +
+ +

{{ group.name }}

+ +

发布时间 : {{ group.create_time }}   + 创建者 : {{ group.admin }} +

+ +
+
+ + +

{{ group.description|safe }}

+
+
+
+
+ {% if group.join_group_setting %} +
+ + + +
+ {% endif %} +
+ +
+
+
+{% endblock %} +{% block js_block %} + +{% endblock %} \ No newline at end of file diff --git a/template/src/oj/group/my_application.html b/template/src/oj/group/my_application.html new file mode 100644 index 00000000..71ba5cb9 --- /dev/null +++ b/template/src/oj/group/my_application.html @@ -0,0 +1,26 @@ +{% extends 'oj_base.html' %} + +{% block body %} + +
+ + +

{{ application.message|safe }}

+ + {% if application.status %} + {% if application.accepted %} +

管理员接受了你的请求

+ {% else %} +

管理员拒绝了你的请求

+ {% endif %} + {% else %} +

待审核

+ {% endif %} +
+{% endblock %} \ No newline at end of file diff --git a/template/src/oj/group/my_application_list.html b/template/src/oj/group/my_application_list.html new file mode 100644 index 00000000..f2b276c6 --- /dev/null +++ b/template/src/oj/group/my_application_list.html @@ -0,0 +1,44 @@ +{% extends 'oj_base.html' %} + +{% block body %} + +
+ + {% if applications %} + + + + + + + + + + {% for item in applications %} + + + + {% if item.status %} + {% if item.accepted %} + + {% else %} + + {% endif %} + {% else %} + + {% endif %} + + {% endfor %} + + +
#提交时间结果
{{ forloop.counter }}{{ item.create_time }}通过拒绝未处理
+ {% else %} +

你还没有申请该小组

+ {% endif %} +
+{% endblock %} \ No newline at end of file