Accept Merge Request #109 修改首页的样式,修复性能问题 : (virusdefender-dev -> dev)

Merge Request: 修改首页的样式,修复性能问题
Created By: @virusdefender
Accepted By: @virusdefender
URL: https://coding.net/u/virusdefender/p/qduoj/git/merge/109
This commit is contained in:
virusdefender 2015-08-21 20:46:36 +08:00
commit cd14d7525e
7 changed files with 65 additions and 31 deletions

View File

@ -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})

View File

@ -67,4 +67,8 @@ li.list-group-item {
.panel>.list-group{
padding: 0 0;
}
.ac-flag{
color: green;
}

View File

@ -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);

View File

@ -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),
),
]

View File

@ -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)

View File

@ -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})

View File

@ -6,10 +6,10 @@
<div class="col-lg-9">
<div class="row">
<div class="right">
<form class="form-inline" onsubmit="return false;">
<form class="form-inline" method="get">
<div class="form-group-sm">
<input name="keyWord" class="form-control" placeholder="请输入关键词" ms-duplex="key_word">
<input type="submit" value="搜索" class="btn btn-primary" ms-click="getPage(1)">
<input name="keyword" class="form-control" placeholder="请输入关键词">
<input type="submit" value="搜索" class="btn btn-primary">
</div>
</form>
</div>
@ -18,15 +18,17 @@
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th>#</th>
<th>题目</th>
<th>难度</th>
<th>通过率</th>
<th><a href="/problems/?order_by=difficulty">难度</a></th>
<th><a href="/problems/?order_by=aceptance">通过率</a></th>
</tr>
</thead>
<tbody>
{% for item in problems %}
<tr>
<th><span class="glyphicon glyphicon-ok ac-flag"></span></th>
<th scope="row"><a href="/problem/{{ item.id }}/">{{ item.id }}</a></th>
<td><a href="/problem/{{ item.id }}/">{{ item.title }}</a></td>
<td>{{ item.difficulty }}</td>
@ -59,7 +61,11 @@
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
公告
</h3></div>
<div class="panel-body"> Panel content</div>
<div class="panel-body">
{% for item in announcements %}
{{ forloop.counter }}.&nbsp;&nbsp;<a href="/announcement/{{ item.id }}/" target="_blank">{{ item.title }}</a>
{% endfor %}
</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">
@ -69,26 +75,12 @@
</h3>
</div>
<ul class="list-group">
<li class="list-group-item problem-tag">
<span class="badge">14</span>
Cras justo odio
</li>
<li class="list-group-item problem-tag">
<span class="badge">14</span>
Cras justo odio
</li>
<li class="list-group-item problem-tag">
<span class="badge">14</span>
Cras justo odio
</li>
<li class="list-group-item problem-tag">
<span class="badge">14</span>
Cras justo odio
</li>
<li class="list-group-item problem-tag">
<span class="badge">14</span>
Cras justo odio
{% 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>