From 02df254afc8707c63088ae66e91f4499b59249a4 Mon Sep 17 00:00:00 2001 From: wrmswindmill Date: Wed, 31 Oct 2018 09:57:31 +0800 Subject: [PATCH] add annoy comment and not editable annotation --- apps/operations/views.py | 25 ++++++++++++++------ apps/projects/models.py | 2 ++ dump.rdb | Bin 3960 -> 7127 bytes templates/projects/filesub/annotation.html | 23 +++++++++++++----- templates/projects/filesub/new-comment.html | 10 +++++++- 5 files changed, 46 insertions(+), 14 deletions(-) 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 bb8b24a77e86489baa5871c5254f83d455b6a2ef..3dafebc47787820afed77f9d3b0971b2bfd47e14 100644 GIT binary patch literal 7127 zcmc)OYjD)%702z z2r(cC2IMNpU1WsnK6t@)Xd5jk&a^akEJj6|@q!u{+7r%`{jM`{80d@U)o0F}=RE(- zZf0|S!~66eFd`fdcd583J9XluoOZdX*>yU#54Z2op`xBuk|)i`iAqK7lo^vUQ;+qm z_u<18b!XQIux2wh#mTwhzr&SBLh-+oc-z=_C%_|MNip4!;Raq}?vQ@)t#ceX4TrF;y4g0!C z+;OXxDPOT;&ncr;O?*aN$g1a7iR);`WTm(r#;kmCMYXP6T(Uyk5vvYeF0PjyOIRxI zP2={Z^#ED%|oGk7wV?*43N7WZp-(Km#|J>;u*h`ZNU>xv7*A-+MYwfz-=z8Aisyoa0btIAT}s~qp2SJ@eU z;*SM^`xt%%OW{A@hwuY<3cd&5g(dJ0@J;vzd>y_9e-B@UFT;ayKimg*!0m7w+zL0t z7ho}b9&Uio!F6ygTn&q0AzTHYg3DkYTnrb%xiA+_hgmQaX23K!5l(<(;3zl@4u%6^ zKiC)chP_}9*d2C-9bsE|H@pkBfvw@sVM`c-O<@ywD{KsZ3U7uDU_DqD-Uw^Knoz&K z{Exc;zk>gU=iwLd9Q+)X!B5~>_z^6He}kvt2k<@kF8m`r4v)dt;cM_HJPZ%Oy>JiQ z4PSyg;frt^+z5-|TDS%l!9utS7QmG-AFhB)VIF)O{ua)GvtSO)hSOm>OoJ&f879GT za12a@Bj9j23_bw+!+x+Y>;rqlZtyF?bXn zfrsHixCicr+u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=m(3z0`PipI+zb$2j+s; zfLDW8fD^&-;JM5P+;JNG75oMK5&QxC4*VAU1{?-YgI|E3f}emNgG1m);2`)O_%1jA zo&fv7W8hKnF!&1i68Hl6Jh%sZ7VHCi!ENAHa5K0G>;}8Qc5n?C2J6AQz{Ow+GRj#3z+; zp)H79;ZdDU^%DQ41Bso)by>QkgtzEG(GFP~nx5KD{FBZO32ieage!EQu7~)09qTHf|U0cAhE^l=Ogtq(woy7O*VacesYW=dIr)ip6M|?(^5ZVHcbr3(P>F`=& z`%j4pgZd1v-P`fQt;7d(HZJSFR-Y^$Cca(MKojv6O-cBrras}%HV`6y)Ls_!3WF2o z>i|i2Sf&?~bcZsXO+H8*we$gbn|6ipDy0(!?F8u=c{-b1Mr_|0F=52g26-1sC$z8k zWIgeRqxX028;&Oc)cQbLj4a_F~-8hT*tC4>I=Y&0$mZCTbzqa%y;`fa+ ziKo~VMRI~&F+)C{mKG8xEEVoH7NBnxP;$Lq?E6c{%9OA?;>YZ=T;j~vzp&QM5}vk! zDa11@6>hLc$RS?oF*#K)lW>lOQr#|SahYY5n#V`%Sm$^&ZENfm>;GOg@<-x}_p1MJ sgBp8Rx_B!ZO%)nV{~3Gf`Ij}F3+l~3+G+l-$oz5H {{ 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 %}