remove redis rank temp

This commit is contained in:
wrmswindmill 2019-07-04 12:07:14 +08:00
parent b9333fc0ae
commit 39ffbe4ec7
7 changed files with 118 additions and 25 deletions

View File

@ -444,26 +444,26 @@ class AddAnnotationView(View):
anno_content = get_currentfile_comment_anno(file,content)
# 更新FileSummary
update_filesummary(file_id,"annotation")
if not file.project.is_competition_project or not file.is_competition_file:
return HttpResponse('{"status":"success_but_not_correct_file","msg":"注释成功,但请注意您标注的不是比赛模块","anno_content":"'+anno_content+'"}', content_type='application/json')
#if not file.project.is_competition_project or not file.is_competition_file:
# return HttpResponse('{"status":"success_but_not_correct_file","msg":"注释成功,但请注意您标注的不是比赛模块","anno_content":"'+anno_content+'"}', content_type='application/json')
# update LeaderBoard
if request.user.educoder_userid is not None:
if str(request.user.id) in user_team_map:
team_id = user_team_map[str(request.user.id)]
else:
team_id = get_educoder_teamdid_by_educoder_userid(request.user.educoder_userid)
if team_id is None:
return HttpResponse(json.dumps({"status": "success", "msg":"注释成功","anno_content":anno_content,}), content_type='application/json')
elif str(request.user.id) not in user_team_map:
user_team_map[str(request.user.id)]=team_id
#if request.user.educoder_userid is not None:
# if str(request.user.id) in user_team_map:
# team_id = user_team_map[str(request.user.id)]
# else:
# team_id = get_educoder_teamdid_by_educoder_userid(request.user.educoder_userid)
# if team_id is None:
# return HttpResponse(json.dumps({"status": "success", "msg":"注释成功","anno_content":anno_content,}), content_type='application/json')
# elif str(request.user.id) not in user_team_map:
# user_team_map[str(request.user.id)]=team_id
# save to file
with open('user_team_data.json', 'w') as outfile:
json.dump(user_team_map, outfile)
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')
# with open('user_team_data.json', 'w') as outfile:
# json.dump(user_team_map, outfile)
# 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:
@ -537,10 +537,10 @@ class DeleteView(View):
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[str(request.user.id)]
if file.is_competition_file:
redis_db.zincrby("gcc",team_id,-1)
# if request.user.educoder_userid is not None:
# team_id = user_team_map[str(request.user.id)]
# if file.is_competition_file:
# 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":

View File

@ -206,6 +206,7 @@ class ProjectInfoView(View):
class ProjectSourceView(View):
def login_educoder(self,educoder_userid,request):
print("educoder_id"+str(educoder_userid))
private_token = "hriEn3UwXfJs3PmyXnSG"
userinfo_url = "http://www.educoder.net/api/v1/sources/"+str(educoder_userid)+"/get_user_info?private_token="+private_token
response = requests.get(userinfo_url)
@ -239,13 +240,14 @@ class ProjectSourceView(View):
def get(self, request, name, path):
educoder_userid = request.GET.get("eid","")
print(educoder_userid)
if educoder_userid!="" and educoder_userid!="2":
self.login_educoder(educoder_userid,request)
name = name.split("?")[0]
path = path.split("?")[0]
project = Project.objects.filter(name=name).first()
print(project.name)
if project.is_open:
# project_tree = projectTreeObj.get_project_tree_by_projectid(project.id)
return render(request, 'projects/source.html', locals())
else:
return HttpResponse("This project is not open now!")

View File

@ -0,0 +1,23 @@
# Generated by Django 2.0.6 on 2018-12-03 21:33
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0006_user_educoder_userid'),
]
operations = [
migrations.AlterField(
model_name='user',
name='address',
field=models.CharField(default='', max_length=100, null=True),
),
migrations.AlterField(
model_name='user',
name='avatar',
field=models.ImageField(default='avatar/users/default.png', null=True, upload_to='avatar/'),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 2.0.6 on 2018-12-03 21:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0007_auto_20181203_2133'),
]
operations = [
migrations.AlterField(
model_name='user',
name='nick_name',
field=models.CharField(default='', max_length=50, null=True, verbose_name='昵称'),
),
]

View File

@ -0,0 +1,28 @@
# Generated by Django 2.0.6 on 2018-12-03 21:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0008_auto_20181203_2138'),
]
operations = [
migrations.AlterField(
model_name='user',
name='address',
field=models.CharField(blank=True, default='', max_length=100, null=True),
),
migrations.AlterField(
model_name='user',
name='avatar',
field=models.ImageField(blank=True, default='avatar/users/default.png', null=True, upload_to='avatar/'),
),
migrations.AlterField(
model_name='user',
name='nick_name',
field=models.CharField(blank=True, default='', max_length=50, null=True, verbose_name='昵称'),
),
]

View File

@ -0,0 +1,23 @@
# Generated by Django 2.0.6 on 2018-12-03 21:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0009_auto_20181203_2146'),
]
operations = [
migrations.AlterField(
model_name='user',
name='educoder_userid',
field=models.IntegerField(blank=True, null=True, verbose_name='educoder的用户id'),
),
migrations.AlterField(
model_name='user',
name='password_codepedia',
field=models.CharField(blank=True, max_length=100, null=True),
),
]

View File

@ -229,7 +229,6 @@ class LoginView(View):
login_url = 'https://www.educoder.net/api/v1/sources/login'
response = requests.post(login_url, params=user_params)
response = json.loads(response.text)
print(response)
status = response['status']
if status == 1:
# 因为用户可能是邮箱也可能是用户名登录所以先获取到educoder用户的用户名
@ -403,4 +402,4 @@ class SendEmailCapter(View):
return HttpResponse(json.dumps({"status": "success"}), content_type='application/json')
except:
return HttpResponse(json.dumps({"status": "fail"}), content_type='application/json')