Accept Merge Request #122 修改部分样式;没有登录自动跳转 : (virusdefender-dev -> dev)
Merge Request: 修改部分样式;没有登录自动跳转 Created By: @virusdefender Accepted By: @virusdefender URL: https://coding.net/u/virusdefender/p/qduoj/git/merge/122
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
from utils.shortcuts import error_response, error_page
|
from utils.shortcuts import error_response, error_page
|
||||||
@@ -18,7 +18,7 @@ def login_required(func):
|
|||||||
if request.is_ajax():
|
if request.is_ajax():
|
||||||
return error_response(u"请先登录")
|
return error_response(u"请先登录")
|
||||||
else:
|
else:
|
||||||
return error_page(request, u"请先登录")
|
return HttpResponseRedirect("/login/")
|
||||||
return check
|
return check
|
||||||
|
|
||||||
|
|
||||||
@@ -31,5 +31,5 @@ def admin_required(func):
|
|||||||
if request.is_ajax():
|
if request.is_ajax():
|
||||||
return error_response(u"需要管理员权限")
|
return error_response(u"需要管理员权限")
|
||||||
else:
|
else:
|
||||||
return error_page(request, u"需要管理员权限")
|
return error_page(request, u"需要管理员权限,如果没有登录,请先登录")
|
||||||
return check
|
return check
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from django.conf.urls import include, url
|
from django.conf.urls import include, url
|
||||||
|
from django.views.generic import TemplateView
|
||||||
|
|
||||||
from .tests import (LoginRequiredCBVTestWithArgs, LoginRequiredCBVTestWithoutArgs,
|
from .tests import (LoginRequiredCBVTestWithArgs, LoginRequiredCBVTestWithoutArgs,
|
||||||
AdminRequiredCBVTestWithArgs, AdminRequiredCBVTestWithoutArgs)
|
AdminRequiredCBVTestWithArgs, AdminRequiredCBVTestWithoutArgs)
|
||||||
@@ -15,4 +16,5 @@ urlpatterns = [
|
|||||||
url(r'^admin_required_test/fbv/(?P<problem_id>\d+)/$', "account.tests.admin_required_FBC_test_with_args"),
|
url(r'^admin_required_test/fbv/(?P<problem_id>\d+)/$', "account.tests.admin_required_FBC_test_with_args"),
|
||||||
url(r'^admin_required_test/cbv/1/$', AdminRequiredCBVTestWithoutArgs.as_view()),
|
url(r'^admin_required_test/cbv/1/$', AdminRequiredCBVTestWithoutArgs.as_view()),
|
||||||
url(r'^admin_required_test/cbv/(?P<problem_id>\d+)/$', AdminRequiredCBVTestWithArgs.as_view()),
|
url(r'^admin_required_test/cbv/(?P<problem_id>\d+)/$', AdminRequiredCBVTestWithArgs.as_view()),
|
||||||
|
url(r'^login/$', TemplateView.as_view(template_name="oj/account/login.html"), name="user_login_page"),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ class LoginRequiredDecoratorTest(TestCase):
|
|||||||
def test_fbv_without_args(self):
|
def test_fbv_without_args(self):
|
||||||
# 没登陆
|
# 没登陆
|
||||||
response = self.client.get("/login_required_test/fbv/1/")
|
response = self.client.get("/login_required_test/fbv/1/")
|
||||||
self.assertTemplateUsed(response, "utils/error.html")
|
self.assertRedirects(response, "/login/")
|
||||||
|
|
||||||
# 登陆后
|
# 登陆后
|
||||||
self.client.login(username="test", password="test")
|
self.client.login(username="test", password="test")
|
||||||
@@ -270,7 +270,7 @@ class LoginRequiredDecoratorTest(TestCase):
|
|||||||
def test_fbv_with_args(self):
|
def test_fbv_with_args(self):
|
||||||
# 没登陆
|
# 没登陆
|
||||||
response = self.client.get("/login_required_test/fbv/1024/")
|
response = self.client.get("/login_required_test/fbv/1024/")
|
||||||
self.assertTemplateUsed(response, "utils/error.html")
|
self.assertRedirects(response, "/login/")
|
||||||
|
|
||||||
# 登陆后
|
# 登陆后
|
||||||
self.client.login(username="test", password="test")
|
self.client.login(username="test", password="test")
|
||||||
@@ -353,7 +353,7 @@ class AdminRequiredDecoratorTest(TestCase):
|
|||||||
def test_cbv_without_args(self):
|
def test_cbv_without_args(self):
|
||||||
# 没登陆
|
# 没登陆
|
||||||
response = self.client.get("/admin_required_test/cbv/1/")
|
response = self.client.get("/admin_required_test/cbv/1/")
|
||||||
self.assertTemplateUsed(response, "utils/error.html")
|
self.assertRedirects(response, "/login/")
|
||||||
|
|
||||||
# 登陆后
|
# 登陆后
|
||||||
self.client.login(username="test", password="test")
|
self.client.login(username="test", password="test")
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ def check_user_contest_permission(func):
|
|||||||
if request.is_ajax():
|
if request.is_ajax():
|
||||||
return error_response(u"请先登录")
|
return error_response(u"请先登录")
|
||||||
else:
|
else:
|
||||||
return error_page(request, u"请先登录")
|
return HttpResponseRedirect("/login/")
|
||||||
|
|
||||||
# kwargs 就包含了url 里面的播或参数
|
# kwargs 就包含了url 里面的播或参数
|
||||||
if "contest_id" in kwargs:
|
if "contest_id" in kwargs:
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ from account.decorators import login_required
|
|||||||
from group.models import Group
|
from group.models import Group
|
||||||
from announcement.models import Announcement
|
from announcement.models import Announcement
|
||||||
|
|
||||||
from .models import Contest, ContestProblem
|
from .models import Contest, ContestProblem, ContestSubmission
|
||||||
from .decorators import check_user_contest_permission
|
from .decorators import check_user_contest_permission
|
||||||
from .serializers import (CreateContestSerializer, ContestSerializer, EditContestSerializer,
|
from .serializers import (CreateContestSerializer, ContestSerializer, EditContestSerializer,
|
||||||
CreateContestProblemSerializer, ContestProblemSerializer,
|
CreateContestProblemSerializer, ContestProblemSerializer,
|
||||||
@@ -263,17 +263,25 @@ def contest_page(request, contest_id):
|
|||||||
return render(request, "oj/contest/contest_index.html", {"contest": contest})
|
return render(request, "oj/contest/contest_index.html", {"contest": contest})
|
||||||
|
|
||||||
|
|
||||||
|
@check_user_contest_permission
|
||||||
def contest_problem_page(request, contest_id, contest_problem_id):
|
def contest_problem_page(request, contest_id, contest_problem_id):
|
||||||
try:
|
try:
|
||||||
Contest.objects.get(id=contest_id)
|
contest = Contest.objects.get(id=contest_id)
|
||||||
except Contest.DoesNotExist:
|
except Contest.DoesNotExist:
|
||||||
return error_page(request, u"比赛不存在")
|
return error_page(request, u"比赛不存在")
|
||||||
try:
|
try:
|
||||||
contest_problem = ContestProblem.objects.get(id=contest_problem_id, visible=True)
|
contest_problem = ContestProblem.objects.get(id=contest_problem_id, visible=True)
|
||||||
except ContestProblem.DoesNotExist:
|
except ContestProblem.DoesNotExist:
|
||||||
return error_page(request, u"比赛题目不存在")
|
return error_page(request, u"比赛题目不存在")
|
||||||
|
show_warning = False
|
||||||
|
try:
|
||||||
|
submission = ContestSubmission.objects.get(user=request.user, contest=contest, problem=contest_problem)
|
||||||
|
show_warning = submission.ac
|
||||||
|
except ContestSubmission.DoesNotExist:
|
||||||
|
pass
|
||||||
return render(request, "oj/contest/contest_problem.html", {"contest_problem": contest_problem,
|
return render(request, "oj/contest/contest_problem.html", {"contest_problem": contest_problem,
|
||||||
"samples": json.loads(contest_problem.samples)})
|
"samples": json.loads(contest_problem.samples),
|
||||||
|
"show_warning": show_warning})
|
||||||
|
|
||||||
|
|
||||||
@check_user_contest_permission
|
@check_user_contest_permission
|
||||||
|
|||||||
@@ -14,8 +14,15 @@ require(["jquery", "bsAlert", "csrfToken", "validator"], function ($, bsAlert, c
|
|||||||
//成功登陆
|
//成功登陆
|
||||||
var ref = document.referrer;
|
var ref = document.referrer;
|
||||||
if(ref){
|
if(ref){
|
||||||
if(ref.split("/")[2] == location.hostname){
|
// 注册页和本页的来源的跳转回首页,防止死循环
|
||||||
|
if(ref.indexOf("register") > -1 || ref.indexOf("login") > -1){
|
||||||
|
location.href = "/";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 判断来源,只有同域下才跳转
|
||||||
|
if(ref.split("/")[2].split(":")[0] == location.hostname){
|
||||||
location.href = ref;
|
location.href = ref;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
location.href = "/";
|
location.href = "/";
|
||||||
|
|||||||
@@ -93,8 +93,7 @@ def contest_problem_my_submissions_list_page(request, contest_id, contest_proble
|
|||||||
contest_problem = ContestProblem.objects.get(id=contest_problem_id, visible=True)
|
contest_problem = ContestProblem.objects.get(id=contest_problem_id, visible=True)
|
||||||
except Problem.DoesNotExist:
|
except Problem.DoesNotExist:
|
||||||
return error_page(request, u"比赛问题不存在")
|
return error_page(request, u"比赛问题不存在")
|
||||||
submissions = Submission.objects.filter(user_id=request.user.id, problem_id=contest_problem.id).order_by(
|
submissions = Submission.objects.filter(user_id=request.user.id, problem_id=contest_problem.id).order_by("-create_time"). \
|
||||||
"-create_time"). \
|
|
||||||
values("id", "result", "create_time", "accepted_answer_time", "language")
|
values("id", "result", "create_time", "accepted_answer_time", "language")
|
||||||
return render(request, "oj/contest/my_submissions_list.html",
|
return render(request, "oj/contest/my_submissions_list.html",
|
||||||
{"submissions": submissions, "contest_problem": contest_problem})
|
{"submissions": submissions, "contest_problem": contest_problem})
|
||||||
@@ -160,7 +159,7 @@ def my_submission_list_page(request, page=1):
|
|||||||
|
|
||||||
|
|
||||||
class ContestSubmissionAPIView(APIView):
|
class ContestSubmissionAPIView(APIView):
|
||||||
# @check_user_contest_permission
|
@check_user_contest_permission
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
"""
|
"""
|
||||||
创建比赛的提交
|
创建比赛的提交
|
||||||
|
|||||||
@@ -81,6 +81,7 @@
|
|||||||
<textarea id="code-editor"></textarea>
|
<textarea id="code-editor"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<div id="submit-code">
|
<div id="submit-code">
|
||||||
<button type="button" class="btn btn-primary" id="submit-code-button">
|
<button type="button" class="btn btn-primary" id="submit-code-button">
|
||||||
提交代码
|
提交代码
|
||||||
@@ -88,6 +89,9 @@
|
|||||||
<img src="/static/img/loading.gif" id="loading-gif">
|
<img src="/static/img/loading.gif" id="loading-gif">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
{% if show_warning %}
|
||||||
|
<div class="alert alert-success" role="alert">您已经提交过本题的正确答案了!</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div id="result">
|
<div id="result">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -21,8 +21,6 @@
|
|||||||
<a href="/contest/{{ contest.id }}/rank/">排名</a>
|
<a href="/contest/{{ contest.id }}/rank/">排名</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-lg-9">
|
<div class="col-lg-9">
|
||||||
@@ -40,11 +38,14 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for item in contest_problems %}
|
{% for item in contest_problems %}
|
||||||
<tr>
|
<tr>
|
||||||
<th><span class="glyphicon glyphicon-ok ac-flag"></span></th>
|
<th>
|
||||||
<th scope="row"><a
|
<span class="glyphicon glyphicon-ok ac-flag"></span>
|
||||||
href="/contest/{{ item.contest.id }}/problem/{{ item.id }}/">{{ item.sort_index }}</a>
|
|
||||||
</th>
|
</th>
|
||||||
<td><a href="/contest/{{ item.contest.id }}/problem/{{ item.id }}/">{{ item.title }}</a>
|
<th scope="row">
|
||||||
|
<a href="/contest/{{ item.contest.id }}/problem/{{ item.id }}/" target="_blank">{{ item.sort_index }}</a>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<a href="/contest/{{ item.contest.id }}/problem/{{ item.id }}/" target="_blank">{{ item.title }}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ item|accepted_radio }}</td>
|
<td>{{ item|accepted_radio }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
{% extends "oj_base.html" %}
|
|
||||||
{% block body %}
|
|
||||||
<div class="container main">
|
|
||||||
<ul class="nav nav-tabs nav-tabs-google">
|
|
||||||
<li role="presentation" class="active">
|
|
||||||
<a href="problem.html">题目</a></li>
|
|
||||||
<li role="presentation"><a href="my_solutions_list.html">我的提交</a></li>
|
|
||||||
<li role="presentation"><a href="#">排名</a></li>
|
|
||||||
</ul>
|
|
||||||
<h2 class="text-center">第一次比赛</h2>
|
|
||||||
|
|
||||||
<p class="text-muted text-center"><b>开始时间:</b> 2015-6-8 19:00 <b>结束时间:</b> 2015-9-1 12:00</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -22,15 +22,15 @@
|
|||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>题目</th>
|
<th>题目</th>
|
||||||
<th><a href="/problems/?order_by=difficulty">难度</a></th>
|
<th><a href="/problems/?order_by=difficulty">难度</a></th>
|
||||||
<th><a href="/problems/?order_by=aceptance">通过率</a></th>
|
<th><a href="/problems/?order_by=acceptance">通过率</a></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for item in problems %}
|
{% for item in problems %}
|
||||||
<tr>
|
<tr>
|
||||||
<th><span class="glyphicon glyphicon-ok ac-flag"></span></th>
|
<th><span class="glyphicon glyphicon-ok ac-flag"></span></th>
|
||||||
<th scope="row"><a href="/problem/{{ item.id }}/">{{ item.id }}</a></th>
|
<th scope="row"><a href="/problem/{{ item.id }}/" target="_blank">{{ item.id }}</a></th>
|
||||||
<td><a href="/problem/{{ item.id }}/">{{ item.title }}</a></td>
|
<td><a href="/problem/{{ item.id }}/" target="_blank">{{ item.title }}</a></td>
|
||||||
<td>{{ item.difficulty }}</td>
|
<td>{{ item.difficulty }}</td>
|
||||||
<td>{{ item|accepted_radio }}</td>
|
<td>{{ item|accepted_radio }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user