From 0683d0914b16df41be2e70be06866523b0263494 Mon Sep 17 00:00:00 2001
From: "sxw@401"
Date: Tue, 15 Sep 2015 15:38:09 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E7=94=A8pre=E6=A0=87=E7=AD=BE=E5=8C=85?=
=?UTF-8?q?=E8=A3=B9=E7=BC=96=E8=AF=91=E5=8F=82=E6=95=B0[CI=20SKIP]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
template/src/utils/help.html | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/template/src/utils/help.html b/template/src/utils/help.html
index c03b354..2284da3 100644
--- a/template/src/utils/help.html
+++ b/template/src/utils/help.html
@@ -33,12 +33,12 @@
编译参数
gcc -DONLINE_JUDGE -O2 -w -std=c99 {src_path} -lm -o {exe_path}main
C++
- g++ -DONLINE_JUDGE -O2 -w -std=c++11 {src_path} -lm -o {exe_path}main
+ g++ -DONLINE_JUDGE -O2 -w -std=c++11 {src_path} -lm -o {exe_path}main
Java
- javac {src_path} -d {exe_path}
- java -cp {exe_path} Main
+ javac {src_path} -d {exe_path}
+ java -cp {exe_path} Main
From 01215a71ad101e586230936f5c279c6c70e81004 Mon Sep 17 00:00:00 2001
From: "sxw@401"
Date: Tue, 15 Sep 2015 16:41:13 +0800
Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E9=A2=98?=
=?UTF-8?q?=E7=9B=AE=E5=88=97=E8=A1=A8=E6=AF=8F=E4=B8=AA=E9=A2=98=E7=9B=AE?=
=?UTF-8?q?=E5=89=8D=E8=BE=B9=E7=8A=B6=E6=80=81=E6=8C=87=E7=A4=BA=E6=A0=87?=
=?UTF-8?q?=E5=BF=97=EF=BC=9Aac=20/=E6=B2=A1=E6=9C=89/=E6=AD=A3=E5=9C=A8?=
=?UTF-8?q?=E8=BF=9B=E8=A1=8C=EF=BC=8C=E5=9B=A0=E4=B8=BA=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E6=98=AF=E5=AD=98=E5=9C=A8=E7=94=A8=E6=88=B7=E8=A1=A8=E9=87=8C?=
=?UTF-8?q?=E7=9A=84=E6=89=80=E4=BB=A5=E7=BC=93=E5=AD=98=E7=9A=84=E6=97=B6?=
=?UTF-8?q?=E5=80=99=E5=8F=AF=E4=BB=A5=E5=81=9A=E5=88=B0=E4=B8=8E=E9=A2=98?=
=?UTF-8?q?=E7=9B=AE=E6=95=B0=E6=8D=AE=E5=88=86=E5=BC=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../migrations/0002_user_problems_status.py | 19 +++++++++++++++++++
account/models.py | 3 +++
mq/scripts/info.py | 16 ++++++++++++++++
problem/views.py | 7 ++++++-
submission/views.py | 9 ++++++++-
template/src/oj/problem/problem_list.html | 2 +-
utils/templatetags/problem.py | 9 +++++++++
7 files changed, 62 insertions(+), 3 deletions(-)
create mode 100644 account/migrations/0002_user_problems_status.py
diff --git a/account/migrations/0002_user_problems_status.py b/account/migrations/0002_user_problems_status.py
new file mode 100644
index 0000000..58c8a31
--- /dev/null
+++ b/account/migrations/0002_user_problems_status.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('account', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='user',
+ name='problems_status',
+ field=models.TextField(blank=True),
+ ),
+ ]
diff --git a/account/models.py b/account/models.py
index df25329..754e178 100644
--- a/account/models.py
+++ b/account/models.py
@@ -30,6 +30,9 @@ class User(AbstractBaseUser):
create_time = models.DateTimeField(auto_now_add=True)
# 0代表不是管理员 1是普通管理员 2是超级管理员
admin_type = models.IntegerField(default=0)
+ # JSON字典用来表示该用户的问题的解决状态 1为ac,2为正在进行
+ problems_status = models.TextField(blank=True)
+
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = []
diff --git a/mq/scripts/info.py b/mq/scripts/info.py
index 01ef6b2..41a2127 100644
--- a/mq/scripts/info.py
+++ b/mq/scripts/info.py
@@ -2,6 +2,7 @@
import logging
import redis
+import json
from judge.judger_controller.settings import redis_config
from judge.judger.result import result
@@ -9,6 +10,7 @@ from submission.models import Submission
from problem.models import Problem
from contest.models import ContestProblem, Contest, ContestSubmission
from account.models import User
+
logger = logging.getLogger("app_info")
@@ -35,6 +37,20 @@ class MessageQueue(object):
problem.save()
except Problem.DoesNotExist:
logger.warning("Submission problem does not exist, submission_id: " + submission_id)
+ # 更新该用户的解题状态
+ try:
+ user = User.objects.get(pk=submission.user_id)
+ except User.DoesNotExist:
+ logger.warning("Submission user does not exist, submission_id: " + submission_id)
+ continue
+ if user.problems_status:
+ problems_status = json.loads(user.problems_status)
+ else:
+ problems_status = {}
+ problems_status[str(problem.id)] = 1
+ user.problems_status = json.dumps(problems_status)
+ user.save()
+
# 普通题目的话,到这里就结束了
continue
diff --git a/problem/views.py b/problem/views.py
index c66b90e..18d7adf 100644
--- a/problem/views.py
+++ b/problem/views.py
@@ -282,11 +282,16 @@ def problem_list_page(request, page=1):
except Exception:
pass
+ if request.user.is_authenticated() and request.user.problems_status:
+ problems_status = json.loads(request.user.problems_status)
+ else:
+ problems_status = {}
+ print problems_status
# 右侧标签列表 按照关联的题目的数量排序 排除题目数量为0的
tags = ProblemTag.objects.annotate(problem_number=Count("problem")).filter(problem_number__gt=0).order_by("-problem_number")
return render(request, "oj/problem/problem_list.html",
{"problems": current_page, "page": int(page),
"previous_page": previous_page, "next_page": next_page,
- "keyword": keyword, "tag": tag_text,
+ "keyword": keyword, "tag": tag_text,"problems_status": problems_status,
"tags": tags, "difficulty_order": difficulty_order})
diff --git a/submission/views.py b/submission/views.py
index 45e1875..baa81d4 100644
--- a/submission/views.py
+++ b/submission/views.py
@@ -46,7 +46,14 @@ class SubmissionAPIView(APIView):
judge.delay(submission.id, problem.time_limit, problem.memory_limit, problem.test_case_id)
except Exception:
return error_response(u"提交判题任务失败")
-
+ # 修改用户解题状态
+ if request.user.problems_status:
+ problems_status = json.loads(request.user.problems_status)
+ else:
+ problems_status = {}
+ problems_status[str(data["problem_id"])] = 2
+ request.user.problems_status = json.dumps(problems_status)
+ request.user.save()
# 增加redis 中判题队列长度的计数器
r = redis.Redis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"])
r.incr("judge_queue_length")
diff --git a/template/src/oj/problem/problem_list.html b/template/src/oj/problem/problem_list.html
index 7a9b1dc..1a1cd13 100644
--- a/template/src/oj/problem/problem_list.html
+++ b/template/src/oj/problem/problem_list.html
@@ -28,7 +28,7 @@
{% for item in problems %}
- |
+ |
{{ item.id }} |
{{ item.title }} |
diff --git a/utils/templatetags/problem.py b/utils/templatetags/problem.py
index 412c91d..31d290d 100644
--- a/utils/templatetags/problem.py
+++ b/utils/templatetags/problem.py
@@ -8,7 +8,16 @@ def get_problem_accepted_radio(problem):
return "0%"
+def get_problem_status(problems_status, problem_id):
+
+ if str(problem_id) in problems_status:
+ if problems_status[str(problem_id)] == 1:
+ return "glyphicon glyphicon-ok ac-flag"
+ return "glyphicon glyphicon-minus dealing-flag"
+ return ""
+
from django import template
register = template.Library()
register.filter("accepted_radio", get_problem_accepted_radio)
+register.simple_tag(get_problem_status, name="get_problem_status")
From 21b18b8e972d275d973bee1ecae4c2ebe0f4e28c Mon Sep 17 00:00:00 2001
From: "sxw@401"
Date: Tue, 15 Sep 2015 20:23:23 +0800
Subject: [PATCH 3/3] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?=
=?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problem/views.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/problem/views.py b/problem/views.py
index 18d7adf..84ca58d 100644
--- a/problem/views.py
+++ b/problem/views.py
@@ -286,7 +286,6 @@ def problem_list_page(request, page=1):
problems_status = json.loads(request.user.problems_status)
else:
problems_status = {}
- print problems_status
# 右侧标签列表 按照关联的题目的数量排序 排除题目数量为0的
tags = ProblemTag.objects.annotate(problem_number=Count("problem")).filter(problem_number__gt=0).order_by("-problem_number")
|