mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 08:23:20 +00:00
[前台]添加了小组列表页面,带测试,不全覆盖
This commit is contained in:
parent
85905f91e3
commit
63a858bd06
@ -8,6 +8,8 @@ from rest_framework.test import APITestCase, APIClient
|
|||||||
from account.models import User, REGULAR_USER, ADMIN, SUPER_ADMIN
|
from account.models import User, REGULAR_USER, ADMIN, SUPER_ADMIN
|
||||||
from group.models import Group, UserGroupRelation, JoinGroupRequest
|
from group.models import Group, UserGroupRelation, JoinGroupRequest
|
||||||
|
|
||||||
|
from django.test import TestCase, Client
|
||||||
|
|
||||||
|
|
||||||
class GroupAPITest(APITestCase):
|
class GroupAPITest(APITestCase):
|
||||||
pass
|
pass
|
||||||
@ -254,3 +256,28 @@ class JoinGroupRequestAdminAPITest(APITestCase):
|
|||||||
response = self.client.put(self.url, data=data)
|
response = self.client.put(self.url, data=data)
|
||||||
self.assertEqual(response.data, {"code": 1, "data": u"加入失败,已经在本小组内"})
|
self.assertEqual(response.data, {"code": 1, "data": u"加入失败,已经在本小组内"})
|
||||||
|
|
||||||
|
|
||||||
|
class ProblemListPageTest(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.client = Client()
|
||||||
|
self.url = reverse('group_list_page')
|
||||||
|
self.url = reverse('problem_list_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"))
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
def get_group_list_page_successful_with_keyword(self):
|
||||||
|
self.client.login(username="test", password="testaa")
|
||||||
|
response = self.client.get(self.url+"?keyword=gro")
|
||||||
|
self.assertEqual(response.status_coed, 200)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ from django.db import IntegrityError
|
|||||||
|
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
from utils.shortcuts import error_response, serializer_invalid_response, success_response, paginate
|
from utils.shortcuts import error_response, serializer_invalid_response, success_response, paginate, error_page
|
||||||
from account.models import REGULAR_USER, ADMIN, SUPER_ADMIN
|
from account.models import REGULAR_USER, ADMIN, SUPER_ADMIN
|
||||||
from account.decorators import login_required
|
from account.decorators import login_required
|
||||||
|
|
||||||
@ -13,6 +13,9 @@ from .serializers import (CreateGroupSerializer, EditGroupSerializer,
|
|||||||
CreateJoinGroupRequestSerializer, GroupSerializer,
|
CreateJoinGroupRequestSerializer, GroupSerializer,
|
||||||
GroupMemberSerializer, EditGroupMemberSerializer,
|
GroupMemberSerializer, EditGroupMemberSerializer,
|
||||||
JoinGroupRequestSerializer, PutJoinGroupRequestSerializer)
|
JoinGroupRequestSerializer, PutJoinGroupRequestSerializer)
|
||||||
|
from announcement.models import Announcement
|
||||||
|
from django.core.paginator import Paginator
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
|
|
||||||
class GroupAPIViewBase(object):
|
class GroupAPIViewBase(object):
|
||||||
@ -244,3 +247,39 @@ class JoinGroupRequestAdminAPIView(APIView, GroupAPIViewBase):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
return serializer_invalid_response(serializer)
|
return serializer_invalid_response(serializer)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def group_list_page(request, page=1):
|
||||||
|
# 右侧的公告列表
|
||||||
|
announcements = Announcement.objects.filter(is_global=True, visible=True).order_by("-create_time")
|
||||||
|
|
||||||
|
groups = Group.objects.filter(visible=True, join_group_setting__lte=2)
|
||||||
|
# 搜索的情况
|
||||||
|
keyword = request.GET.get("keyword", None)
|
||||||
|
if keyword:
|
||||||
|
groups = groups.filter(Q(name__contains=keyword) | Q(description__contains=keyword))
|
||||||
|
|
||||||
|
paginator = Paginator(groups, 20)
|
||||||
|
try:
|
||||||
|
current_page = paginator.page(int(page))
|
||||||
|
except Exception:
|
||||||
|
return error_page(request, u"不存在的页码")
|
||||||
|
|
||||||
|
previous_page = next_page = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
previous_page = current_page.previous_page_number()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
next_page = None
|
||||||
|
try:
|
||||||
|
next_page = current_page.next_page_number()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return render(request, "oj/group/group_list.html", {
|
||||||
|
"groups": groups, "announcements": announcements,
|
||||||
|
"contests": current_page, "page": int(page),
|
||||||
|
"previous_page": previous_page, "next_page": next_page,
|
||||||
|
"keyword": keyword, "announcements": announcements,
|
||||||
|
})
|
||||||
|
@ -100,6 +100,9 @@ urlpatterns = [
|
|||||||
url(r'^submissions/$', "submission.views.my_submission_list_page", name="my_submission_list_page"),
|
url(r'^submissions/$', "submission.views.my_submission_list_page", name="my_submission_list_page"),
|
||||||
url(r'^submissions/(?P<page>\d+)/$', "submission.views.my_submission_list_page", name="my_submission_list_page"),
|
url(r'^submissions/(?P<page>\d+)/$', "submission.views.my_submission_list_page", name="my_submission_list_page"),
|
||||||
|
|
||||||
url(r'^contest/(?P<contest_id>\d+)/rank/$', "contest.views.contest_rank_page", name="contest_rank_page")
|
url(r'^contest/(?P<contest_id>\d+)/rank/$', "contest.views.contest_rank_page", name="contest_rank_page"),
|
||||||
|
|
||||||
|
url(r'^groups/$', "group.views.group_list_page", name="group_list_page"),
|
||||||
|
url(r'^groups/(?P<page>\d+)/$', "group.views.group_list_page", name="group_list_page")
|
||||||
|
|
||||||
]
|
]
|
||||||
|
@ -18,21 +18,27 @@
|
|||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>题目</th>
|
<th>名称</th>
|
||||||
<th><a href="/problems/?order_by=difficulty">难度</a></th>
|
<th>加入方式</th>
|
||||||
<th><a href="/problems/?order_by=acceptance">通过率</a></th>
|
<th>创建者</th>
|
||||||
|
<th>创建时间</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for item in problems %}
|
{% for item in groups %}
|
||||||
<tr>
|
<tr>
|
||||||
<th><span class="glyphicon glyphicon-ok ac-flag"></span></th>
|
<th scope="row"><a href="/group/{{ item.id }}/" target="_blank">{{ item.id }}</a></th>
|
||||||
<th scope="row"><a href="/problem/{{ item.id }}/" target="_blank">{{ item.id }}</a></th>
|
<td><a href="/group/{{ item.id }}/" target="_blank">{{ item.name }}</a></td>
|
||||||
<td><a href="/problem/{{ item.id }}/" target="_blank">{{ item.title }}</a></td>
|
<td>
|
||||||
<td>{{ item.difficulty }}</td>
|
{% if item.join_group_setting %}
|
||||||
<td>{{ item|accepted_radio }}</td>
|
需要申请
|
||||||
|
{% else %}
|
||||||
|
无需申请
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>{{ item.admin }}</td>
|
||||||
|
<td>{{ item.create_time }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -41,13 +47,16 @@
|
|||||||
<ul class="pager">
|
<ul class="pager">
|
||||||
{% if previous_page %}
|
{% if previous_page %}
|
||||||
<li class="previous"><a
|
<li class="previous"><a
|
||||||
href="/problems/{{ previous_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}{% if tag %}?tag={{ tag }}{% endif %}">
|
href="/groups/{{ previous_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}">
|
||||||
<span aria-hidden="true">←</span> 上一页</a></li>
|
<span aria-hidden="true">←</span> 上一页</a>
|
||||||
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if next_page %}
|
{% if next_page %}
|
||||||
<li class="next"><a
|
<li class="next">
|
||||||
href="/problems/{{ next_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}{% if tag %}?tag={{ tag }}{% endif %}">下一页 <span
|
<a href="/groups/{{ next_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}">
|
||||||
aria-hidden="true">→</span></a></li>
|
下一页 <span aria-hidden="true">→</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
@ -56,28 +65,7 @@
|
|||||||
|
|
||||||
<div class="col-md-3 col-lg-3">
|
<div class="col-md-3 col-lg-3">
|
||||||
{% include "oj/announcement/_announcement_panel.html" %}
|
{% include "oj/announcement/_announcement_panel.html" %}
|
||||||
<div class="panel panel-info">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<h3 class="panel-title">
|
|
||||||
<span class="glyphicon glyphicon-tag" aria-hidden="true"></span>
|
|
||||||
分类
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
<ul class="list-group">
|
|
||||||
{% for item in tags %}
|
|
||||||
<li class="list-group-item problem-tag" onclick="location.href='/problems/?tag={{ item.name }}'">
|
|
||||||
<span class="badge">{{ item.problem_number }}</span>
|
|
||||||
{{ item.name }}
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block js_block %}
|
|
||||||
<script src="/static/js/app/oj/problem/problem_list.js"></script>
|
|
||||||
{% endblock %}
|
|
Loading…
Reference in New Issue
Block a user