add annoy comment and not editable annotation

This commit is contained in:
wrmswindmill 2018-10-31 09:57:31 +08:00
parent 6b2592755e
commit 02df254afc
5 changed files with 46 additions and 14 deletions

View File

@ -81,7 +81,7 @@ def set_init_rank():
redis_db = redis.StrictRedis(host='localhost', port=6379, db=0)
user_team_map ={}
# update_rank_latest()
#update_rank_latest()
set_init_rank()
@ -238,7 +238,6 @@ class ShowAnnotationView(View):
anno_votes = Vote.objects.filter(user=request.user,vote_type_id__in=annotations,vote_type="annotation")
comment_votes = Vote.objects.filter(user=request.user,vote_type_id__in=anno_comments,vote_type="annotation_comment")
anno_vote_map={}
for anno_vote in anno_votes:
anno_vote_map[anno_vote.vote_type_id]=anno_vote.value
@ -246,15 +245,16 @@ class ShowAnnotationView(View):
for comment_vote in comment_votes:
comment_vote_map[comment_vote.vote_type_id]=comment_vote.value
path = File.objects.get(id=file_id).path
file = File.objects.get(id=file_id)
path = file.path
isdir = (len(FileSummary.objects.filter(project_id=project_id,parent_path=path))>0)
if isdir:
isdir = 1
else:
isdir = 0
# if self_annotation is not None:
# annotations.filter(id=self_annotation.id).delete()
html_str = render_to_string('projects/filesub/annotation.html', {'linenum':line_num,'annos': annotations,"anno_comments":anno_comments,"self_annos":self_annotations,"allow_modify":allow_modify,"anno_vote_map":anno_vote_map,"comment_vote_map":comment_vote_map,"annotation_length":annotation_length,"isdir":isdir})
html_str = render_to_string('projects/filesub/annotation.html', {'is_annoy_comment':file.project.is_annoy_comment,'linenum':line_num,'annos': annotations,"anno_comments":anno_comments,"self_annos":self_annotations,"allow_modify":allow_modify,"anno_vote_map":anno_vote_map,"comment_vote_map":comment_vote_map,"annotation_length":annotation_length,"isdir":isdir})
return HttpResponse(json.dumps({"status": "success","html_str":html_str}), content_type='application/json')
# FIXME
@ -412,6 +412,9 @@ class AddAnnotationView(View):
content = request.POST.get('content', '')
file_id = int(request.POST.get('file_id', ''))
linenum = int(request.POST.get('linenum', ''))
if not File.objects.get(id=file_id).project.is_annotation_editable:
return HttpResponse('{"status":"fail","msg":"此阶段不允许再添加注释了"}', content_type='application/json')
if int(file_id) > 0 and content:
# 看用户是否已经添加过注释
# exist_record = Annotation.objects.filter(file_id=file_id, linenum=linenum, user_id=request.user.id)
@ -567,6 +570,8 @@ class ModifyAnnotationView(View):
file_id = int(request.POST.get('file_id', ''))
linenum = int(request.POST.get('line_num', ''))
anno_id = int(request.POST.get('anno_id', ''))
if not File.objects.get(id=file_id).project.is_annotation_editable:
return HttpResponse('{"status":"fail","msg":"此阶段不允许再添加注释了"}', content_type='application/json')
# 查询到之前的注释根据file_id,line_num,user_id;
# 这是为了支持group修改而做的
# annotation = Annotation.objects.get(file_id=file_id, linenum=linenum, id=anno_id,is_latest=1)
@ -741,6 +746,7 @@ class AddCommentView(View):
if type == 'annotation':
comment = AnnotationComment()
annotation = Annotation.objects.get(id=object_id)
project = annotation.project
comment.annotation_id = annotation.id
elif type == 'issue':
comment = IssueComment()
@ -762,7 +768,12 @@ class AddCommentView(View):
comment.content = content
comment.user = request.user
comment.save()
html_str = render_to_string('projects/filesub/new-comment.html', {'comment': comment})
if project is not None:
html_str = render_to_string('projects/filesub/new-comment.html', {'comment': comment,"is_annoy_comment":project.is_annoy_comment})
else:
html_str = render_to_string('projects/filesub/new-comment.html', {'comment': comment,"is_annoy_comment":False})
return HttpResponse(json.dumps({"status":"success","msg":"评论成功","html_str":html_str}), content_type='application/json')
else:
return HttpResponse('{"status":"fail","msg":"评论失败"}', content_type='application/json')

View File

@ -39,6 +39,8 @@ class Project(models.Model):
update_time = models.DateTimeField(auto_now=True)
is_competition_project = models.BooleanField(default=False, verbose_name='是否是竞赛项目')
is_open = models.BooleanField(default=False, verbose_name='是否是竞赛项目')
is_annotation_editable = models.BooleanField(default=True, verbose_name='是否可新增或修改注释')
is_annoy_comment = models.BooleanField(default=False, verbose_name='是否匿名评论')
class Meta:
db_table = 'Source_Project'

BIN
dump.rdb

Binary file not shown.

View File

@ -95,10 +95,16 @@
<div class="comment-item fl">
<span class="color-grey-des mr10 colorgray inlineBlock fl ellipsis" title="{{ comment.content }}">{{ comment.content }}</span>
{% if comment.user.nick_name == "" %}
<span class="color-grey-des inlineBlock fr inlineBlockfont">{{comment.user.username}}</span>
{% comment %} <textarea id="modify_anno_textarea" class="fl break_word color-grey-des colorblack inlineBlock wi216" oninput="Input_modifyAnno(this,{{self_anno.file_id}},{{self_anno.linenum}},{{self_anno.id}})" style="border:none" readonly>{{ self_anno.content }}</textarea> {% endcomment %}
{% if is_annoy_comment %}
<span class="color-grey-des inlineBlock marbox fr mt11">用户-{{comment.user.id}}</span>
{% else %}
<span class="color-grey-des inlineBlock fr inlineBlockfont">{{ comment.user.nick_name }}</span>
{% if comment.user.nick_name == "" %}
<span class="color-grey-des inlineBlock marbox fr mt11">{{comment.user.username}}</span>
{% else %}
<span class="color-grey-des inlineBlock fr inlineBlockfont">{{ comment.user.nick_name }}</span>
{% endif %}
{% endif %}
<div class="clear"></div>
</div>
@ -174,10 +180,15 @@
{% endcomment %}
<div class="fl comment-item">
<span class="color-grey-des mr10 colorgray inlineBlock fl ellipsis" title="{{ comment.content }}">{{ comment.content }}</span>
{% if comment.user.nick_name == "" %}
<span class="color-grey-des inlineBlock marbox fr mt11">{{comment.user.username}}</span>
{% if is_annoy_comment %}
<span class="color-grey-des inlineBlock marbox fr mt11">用户-{{comment.user.id}}</span>
{% else %}
<span class="color-grey-des inlineBlock fr inlineBlockfont">{{ comment.user.nick_name }}</span>
{% if comment.user.nick_name == "" %}
<span class="color-grey-des inlineBlock marbox fr mt11">{{comment.user.username}}</span>
{% else %}
<span class="color-grey-des inlineBlock fr inlineBlockfont">{{ comment.user.nick_name }}</span>
{% endif %}
{% endif %}
<div class="clear"></div>
</div>

View File

@ -8,7 +8,15 @@
{% endcomment %}
<div class="fl comment-item">
<span class="color-grey-des mr10 colorgray inlineBlock fl ellipsis" title="{{ comment.content }}">{{ comment.content }}</span>
<span class="color-grey-des inlineBlock fr inlineBlockfont">{{ comment.user.nick_name }}</span>
{% if is_annoy_comment %}
<span class="color-grey-des inlineBlock fr inlineBlockfont">用户-{{comment.user.id}}</span>
{% else %}
{% if comment.user.nick_name == "" %}
<span class="color-grey-des inlineBlock fr inlineBlockfont">{{comment.user.username}}</span>
{% else %}
<span class="color-grey-des inlineBlock fr inlineBlockfont">{{ comment.user.nick_name }}</span>
{% endif %}
{% endif %}
<div class="clear"></div>
</div>
</div>