add leadboard and add project url

fix delete function
This commit is contained in:
wrmswindmill 2018-09-29 22:35:13 +08:00
parent a1476164d5
commit f8205cf3ae
4 changed files with 84 additions and 22 deletions

View File

@ -19,7 +19,7 @@ from projects.models import File,Method
from projects.models import Language, Project, FileSummary
from django.template.loader import render_to_string
import base64
import redis
import logging
@ -29,13 +29,42 @@ logging.basicConfig(level=logging.DEBUG,
filename='/test.log',
filemode='w')
def set_init_rank(redis_db):
# 1.获取当前的比赛项目id
# competition_projects=Project.objects.filter(is_competition_project=1)
competition_files = File.objects.filter(is_competition_file=1)
# 2.获取所有的组id
symbol = "gcc-dev-2018"
private_token="hriEn3UwXfJs3PmyXnSG"
url="https://www.educoder.net/api/v1/sources/"+str(symbol)+"/get_team_ids?private_token="+private_token
response = requests.get(url)
team_ids = list(json.loads(response.text)['team_ids'])
for team in team_ids:
# 3.获取当前组对应的组成员
url = "https://www.educoder.net/api/v1/sources/"+str(symbol)+"/get_team_user_ids?team_id="+str(team)+"&private_token="+private_token
response = requests.get(url)
user_ids = json.loads(response.text)['user_ids']
users = User.objects.filter(educoder_userid__in=user_ids)
# add the user into user_team_map
for user in users:
user_team_map[user.id]=team
if len(users)>0:
# 4.获取每个组的分数
score = len(Annotation.objects.filter(user__in=users,file__in=competition_files))
redis_db.zadd("gcc",score,team)
print("init rank success")
redis_db = redis.StrictRedis(host='localhost', port=6379, db=0)
user_team_map ={}
set_init_rank(redis_db)
def get_educoder_group_userlist_by_educoder_userid(userid,file_id):
# 根据file_id查询project再查询到对应的比赛
project = File.objects.get(id=file_id).project
try:
symbol = Competition.objects.get(project=project).symbol
# symbol = Competition.objects.get(project=project).symbol
symbol = "gcc-dev-2018"
private_token="hriEn3UwXfJs3PmyXnSG"
url="https://www.educoder.net/api/v1/sources/"+str(symbol)+"/get_competition_members?user_id="+str(userid)+"&private_token="+private_token
response = requests.get(url)
@ -389,7 +418,14 @@ class AddAnnotationView(View):
# print(anno_content)
if file.project.is_competition_project and not file.is_competition_file:
return HttpResponse('{"status":"success_but_not_correct_file","msg":"注释成功,但请注意您标注的不是比赛模块","anno_content":"'+anno_content+'"}', content_type='application/json')
return HttpResponse('{"status":"success","msg":"注释成功","anno_content":"'+anno_content+'"}', content_type='application/json')
# update LeaderBoard
if request.user.educoder_userid is not None:
team_id = user_team_map[request.user.id]
redis_db.zincrby("gcc",team_id,1)
rank = int(redis_db.zrevrank("gcc",team_id))+1
return HttpResponse(json.dumps({"status": "success", "msg":"注释成功","anno_content":anno_content,"rank":rank}), content_type='application/json')
else:
return HttpResponse(json.dumps({"status": "success", "msg":"注释成功","anno_content":anno_content,}), content_type='application/json')
except Exception as e:
return HttpResponse('{"status":"fail","msg":"参数传递错误,注释失败"}', content_type='application/json')
else:
@ -455,11 +491,19 @@ def get_currentfile_language(file):
class DeleteView(View):
def post(self,request):
try:
remove_anno_icon = False
object_id = request.POST.get("object_id","")
object_type = request.POST.get("object_type","")
if object_type=="Annotation":
annotation = Annotation.objects.get(id=object_id,is_latest=1)
Annotation.objects.filter(linenum=annotation.linenum,file=annotation.file).delete()
linenum = annotation.linenum
file = annotation.file
Annotation.objects.filter(user=request.user,linenum=linenum,file=file).delete()
if request.user.educoder_userid is not None:
team_id = user_team_map[request.user.id]
redis_db.zincrby("gcc",team_id,-1)
if len(Annotation.objects.filter(linenum=linenum,file=file))==0:
remove_anno_icon = True
elif object_type == "Question":
Question.objects.filter(id=object_id).delete()
elif object_type == "QuestionAnswer":
@ -470,8 +514,9 @@ class DeleteView(View):
IssueComment.objects.filter(id=object_id).delete()
elif object_type == 'QuestionAnswerComment':
QuestionAnswerComment.objects.filter(id=object_id).delete()
return HttpResponse('{"status":"success","msg":"删除成功"}', content_type='application/json')
except:
return HttpResponse(json.dumps({"status": "success", "msg":"删除成功","remove_anno_icon":remove_anno_icon}), content_type='application/json')
except Exception as e:
# print(str(e))
return HttpResponse('{"status":"fail","msg":"删除失败"}', content_type='application/json')
@ -1384,6 +1429,7 @@ class RightView(View):
filelinenum = current_file_summary.line_num
create_time = file.create_time
file_num = current_file_summary.file_num
project_url = file.project.github
html_str = render_to_string('projects/filesub/file-right.html', locals())
return html_str
@ -1420,6 +1466,7 @@ class RightView(View):
path = file.path
# 观看数应该放在File_id中
project_url = file.project.github
html_str = render_to_string('projects/filesub/file-right.html', locals())
return html_str

View File

@ -1,3 +1,4 @@
redis
alabaster==0.7.10
amqp==1.4.9
anyjson==0.3.3

View File

@ -248,7 +248,7 @@ function modify_anno(file_id,line_num,anno_id){
if (data.status === "success") {
alert(data.msg)
$("#ItemcommentPanel").remove()
$("."+file_id+line_num).text(data.anno_content)
$("."+file_id+"_"+line_num).text(data.anno_content)
show_annotation(file_id,line_num);
deletelocalStorage("modifyAnno_id");
@ -485,8 +485,10 @@ function delete_anno(file_id,line_num,anno_id){
if (data.status == 'success') {
$("#ItemcommentPanel").remove()
$("."+file_id+line_num).remove()
if(data.remove_anno_icon){
$("#codeopration_anno_"+file_id+"_"+line_num).remove();
show_annotation(file_id,line_num);
}
// show_annotation(file_id,line_num);
layer.msg(data.msg);
}else{
layer.msg(data.msg);
@ -537,18 +539,6 @@ function add_annotation(item,file_id, line_num) {
function submit_annotation(file_id, line_num, content) {
// 因为可能注释或问题没有值的时候不会为该代码块添加html代码所以首先判断
// 然后将注释数+1
var codeopration_anno_div = $("#codeopration_anno_"+file_id+"_" + line_num).html()
var str = '<span id="annonums_' + line_num + '" class="annonums" onclick="show_annotation(' + file_id + ',' + line_num + ')">';
str +='</span>';
$("#codeopration_anno_" + +file_id + "_" + line_num).html(str);
$(".addno-panel").hide();
$(".source-addno-panel").remove();
// show_annotation(file_id,line_num);
//将注释添加到当前行的上一行
var contenthtml ='<div class="linenum"></div>'+'<div class="sourcecode">'+'<div class="mypre newaddmypre hljs-comment ' + file_id+line_num + '">'+"//"+ content+'</div>'+'</div>'+'<div class="linestatus"></div>';
var html = '<div class="newcodeline newcodelinebox">'+contenthtml+'</div>';
var id=file_id+'_'+"L"+line_num;
$("#"+id).before(html);
$.ajax({
cache: false,
type: "POST",
@ -561,7 +551,21 @@ function submit_annotation(file_id, line_num, content) {
},
success: function (data) {
if (data.status == 'success') {
layer.msg('提交成功');
var codeopration_anno_div = $("#codeopration_anno_"+file_id+"_" + line_num).html()
var str = '<span id="annonums_' + line_num + '" class="annonums" onclick="show_annotation(' + file_id + ',' + line_num + ')">';
str +='</span>';
$("#codeopration_anno_" + +file_id + "_" + line_num).html(str);
$(".addno-panel").hide();
$(".source-addno-panel").remove();
// show_annotation(file_id,line_num);
//将注释添加到当前行的上一行
var contenthtml ='<div class="linenum"></div>'+'<div class="sourcecode">'+'<div class="mypre newaddmypre hljs-comment ' + file_id+"_"+line_num + '">'+"//"+ content+'</div>'+'</div>'+'<div class="linestatus"></div>';
var html = '<div class="newcodeline newcodelinebox">'+contenthtml+'</div>';
var id=file_id+'_'+"L"+line_num;
$("#"+id).before(html);
if(data.rank){
layer.msg('标注提交成功,当前小组排名为:'+data.rank);
}
}else{
layer.msg(data.msg);
}

View File

@ -2,12 +2,22 @@
<div class="middle-right-item">
{% if isdir %}
<p class="right-item-title">Module Summary</p>
<p class="clearfix">
<span class="panel-leftfontnew">Project Url:</span>
<span class="panel-right newpanel-right" title="{{project_url}}"><a style="color:white" href="{{project_url}}" target="_blank">{{project_url}}</a></span>
</p>
<p class="clearfix">
<span class="panel-leftfontnew">Module Path:</span>
<span class="panel-right newpanel-right" title="{{path}}">{{path}}</span>
</p>
{% else %}
<p class="right-item-title">File Summary</p>
<p class="clearfix">
<span class="panel-leftfontnew">Project Url:</span>
<span class="panel-right newpanel-right" title="{{project_url}}"><a style="color:white" href="{{project_url}}" target="_blank">{{project_url}}</a></span>
</p>
<p class="clearfix">
<span class="panel-leftfontnew">File Path:</span>
<span class="panel-right newpanel-right" title="{{path}}">{{path}}</span>