完成首页的公告列表,标签列表等功能。

This commit is contained in:
virusdefender 2015-08-21 17:58:22 +08:00
parent bcde6979c6
commit ae6566b92f
4 changed files with 29 additions and 26 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

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

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