diff --git a/apps/operations/views.py b/apps/operations/views.py index 8857c5b..0514283 100644 --- a/apps/operations/views.py +++ b/apps/operations/views.py @@ -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') diff --git a/apps/projects/models.py b/apps/projects/models.py index c71e183..e622078 100644 --- a/apps/projects/models.py +++ b/apps/projects/models.py @@ -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' diff --git a/dump.rdb b/dump.rdb index bb8b24a..3dafebc 100644 Binary files a/dump.rdb and b/dump.rdb differ diff --git a/templates/projects/filesub/annotation.html b/templates/projects/filesub/annotation.html index ec1d5e2..7dc2983 100644 --- a/templates/projects/filesub/annotation.html +++ b/templates/projects/filesub/annotation.html @@ -95,10 +95,16 @@
{{ comment.content }} - {% if comment.user.nick_name == "" %} - {{comment.user.username}} + {% comment %} {% endcomment %} + + {% if is_annoy_comment %} + 用户-{{comment.user.id}} {% else %} - {{ comment.user.nick_name }} + {% if comment.user.nick_name == "" %} + {{comment.user.username}} + {% else %} + {{ comment.user.nick_name }} + {% endif %} {% endif %}
@@ -174,10 +180,15 @@ {% endcomment %}
{{ comment.content }} - {% if comment.user.nick_name == "" %} - {{comment.user.username}} + + {% if is_annoy_comment %} + 用户-{{comment.user.id}} {% else %} - {{ comment.user.nick_name }} + {% if comment.user.nick_name == "" %} + {{comment.user.username}} + {% else %} + {{ comment.user.nick_name }} + {% endif %} {% endif %}
diff --git a/templates/projects/filesub/new-comment.html b/templates/projects/filesub/new-comment.html index 1d46430..975984a 100644 --- a/templates/projects/filesub/new-comment.html +++ b/templates/projects/filesub/new-comment.html @@ -8,7 +8,15 @@ {% endcomment %}
{{ comment.content }} - {{ comment.user.nick_name }} + {% if is_annoy_comment %} + 用户-{{comment.user.id}} + {% else %} + {% if comment.user.nick_name == "" %} + {{comment.user.username}} + {% else %} + {{ comment.user.nick_name }} + {% endif %} + {% endif %}