diff --git a/problem/views.py b/problem/views.py index 4a6e2c6..26a3a5b 100644 --- a/problem/views.py +++ b/problem/views.py @@ -6,13 +6,14 @@ import hashlib import json from django.shortcuts import render -from django.db.models import Q +from django.db.models import Q, Count from django.core.paginator import Paginator from rest_framework.views import APIView from django.conf import settings +from announcement.models import Announcement from utils.shortcuts import (serializer_invalid_response, error_response, success_response, paginate, rand_str, error_page) from .serizalizers import (CreateProblemSerializer, EditProblemSerializer, ProblemSerializer, @@ -251,7 +252,13 @@ def problem_list_page(request, page=1): except Exception: pass + # 右侧的公告列表 + announcements = Announcement.objects.filter(is_global=True, visible=True).order_by("-create_time") + # 右侧标签列表 按照关联的题目的数量排序 排除题目数量为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, + "announcements": announcements, "tags": tags}) diff --git a/static/src/css/oj.css b/static/src/css/oj.css index cc6ac62..e6bd835 100644 --- a/static/src/css/oj.css +++ b/static/src/css/oj.css @@ -67,4 +67,8 @@ li.list-group-item { .panel>.list-group{ padding: 0 0; +} + +.ac-flag{ + color: green; } \ No newline at end of file diff --git a/static/src/js/app/admin/monitor/monitor.js b/static/src/js/app/admin/monitor/monitor.js index 915e574..0747618 100644 --- a/static/src/js/app/admin/monitor/monitor.js +++ b/static/src/js/app/admin/monitor/monitor.js @@ -16,6 +16,8 @@ require(["jquery", "chart"], function ($, Chart) { }; var chart = new Chart($("#waiting-queue-chart").get(0).getContext("2d")).Line(data); + var dataCounter = 0; + function getMonitorData(){ var hash = location.hash; if (hash != "#monitor/monitor"){ @@ -28,13 +30,17 @@ require(["jquery", "chart"], function ($, Chart) { success: function(data){ if(!data.code){ chart.addData([data.data["count"]], data.data["time"]) + dataCounter ++; } } }) } $("#clear-chart-data").click(function(){ - chart.removeData(); + for(var i = 0;i < dataCounter;i++) { + chart.removeData(); + dataCounter = 0; + } }); var intervalId = setInterval(getMonitorData, 3000); diff --git a/submission/migrations/0003_auto_20150821_1654.py b/submission/migrations/0003_auto_20150821_1654.py new file mode 100644 index 0000000..22ab59d --- /dev/null +++ b/submission/migrations/0003_auto_20150821_1654.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('submission', '0002_submission_is_counted'), + ] + + operations = [ + migrations.AlterField( + model_name='submission', + name='problem_id', + field=models.IntegerField(db_index=True), + ), + migrations.AlterField( + model_name='submission', + name='user_id', + field=models.IntegerField(db_index=True), + ), + ] diff --git a/submission/models.py b/submission/models.py index 3442183..2cde917 100644 --- a/submission/models.py +++ b/submission/models.py @@ -6,12 +6,12 @@ from judge.judger.result import result class Submission(models.Model): id = models.CharField(max_length=32, default=rand_str, primary_key=True, db_index=True) - user_id = models.IntegerField() + user_id = models.IntegerField(db_index=True) create_time = models.DateTimeField(auto_now_add=True) result = models.IntegerField(default=result["waiting"]) language = models.IntegerField() code = models.TextField() - problem_id = models.IntegerField() + problem_id = models.IntegerField(db_index=True) # 这个字段可能存储很多数据 比如编译错误、系统错误的时候,存储错误原因字符串 # 正常运行的时候存储 lrun 的判题结果,比如cpu时间内存之类的 info = models.TextField(blank=True, null=True) diff --git a/submission/views.py b/submission/views.py index 1524643..26e8d3a 100644 --- a/submission/views.py +++ b/submission/views.py @@ -84,7 +84,8 @@ def problem_my_submissions_list_page(request, problem_id): problem = Problem.objects.get(id=problem_id, visible=True) except Problem.DoesNotExist: return error_page(request, u"问题不存在") - submissions = Submission.objects.filter(user_id=request.user.id, problem_id=problem.id).order_by("-create_time") + submissions = Submission.objects.filter(user_id=request.user.id, problem_id=problem.id).order_by("-create_time").\ + values("id", "result", "create_time", "accepted_answer_time", "language") return render(request, "oj/problem/my_submissions_list.html", {"submissions": submissions, "problem": problem}) diff --git a/template/oj/problem/problem_list.html b/template/oj/problem/problem_list.html index 2909e20..073cfe7 100644 --- a/template/oj/problem/problem_list.html +++ b/template/oj/problem/problem_list.html @@ -6,10 +6,10 @@
| # | 题目 | -难度 | -通过率 | +难度 | +通过率 | |
|---|---|---|---|---|---|---|
| {{ item.id }} | {{ item.title }} | {{ item.difficulty }} | @@ -59,7 +61,11 @@ 公告 -