diff --git a/apps/operations/views.py b/apps/operations/views.py index 8d5b0b8..13c525c 100644 --- a/apps/operations/views.py +++ b/apps/operations/views.py @@ -387,6 +387,8 @@ class AddAnnotationView(View): # 更新FileSummary update_filesummary(file_id,"annotation") # 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') except Exception as e: return HttpResponse('{"status":"fail","msg":"参数传递错误,注释失败"}', content_type='application/json') @@ -457,8 +459,7 @@ class DeleteView(View): object_type = request.POST.get("object_type","") if object_type=="Annotation": annotation = Annotation.objects.get(id=object_id,is_latest=1) - annotation.is_latest = 0 - annotation.save() + Annotation.objects.filter(linenum=annotation.linenum,file=annotation.file).delete() elif object_type == "Question": Question.objects.filter(id=object_id).delete() elif object_type == "QuestionAnswer": diff --git a/apps/projects/migrations/0019_auto_20180929_1047.py b/apps/projects/migrations/0019_auto_20180929_1047.py new file mode 100644 index 0000000..2765c94 --- /dev/null +++ b/apps/projects/migrations/0019_auto_20180929_1047.py @@ -0,0 +1,23 @@ +# Generated by Django 2.0.6 on 2018-09-29 10:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0018_auto_20180904_1055'), + ] + + operations = [ + migrations.AddField( + model_name='file', + name='is_competition_file', + field=models.BooleanField(default=False, verbose_name='是否是竞赛文件'), + ), + migrations.AlterField( + model_name='file', + name='issue_num', + field=models.IntegerField(default=0, verbose_name='问题数量'), + ), + ] diff --git a/apps/projects/migrations/0020_project_is_competition_project.py b/apps/projects/migrations/0020_project_is_competition_project.py new file mode 100644 index 0000000..1df5bed --- /dev/null +++ b/apps/projects/migrations/0020_project_is_competition_project.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.6 on 2018-09-29 11:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0019_auto_20180929_1047'), + ] + + operations = [ + migrations.AddField( + model_name='project', + name='is_competition_project', + field=models.BooleanField(default=False, verbose_name='是否是竞赛项目'), + ), + ] diff --git a/apps/projects/models.py b/apps/projects/models.py index fabef36..1daea94 100644 --- a/apps/projects/models.py +++ b/apps/projects/models.py @@ -37,6 +37,7 @@ class Project(models.Model): state = models.CharField(max_length=3, choices=STATE_CHOICE, default='1') create_time = models.DateTimeField(auto_now_add=True) update_time = models.DateTimeField(auto_now=True) + is_competition_project = models.BooleanField(default=False, verbose_name='是否是竞赛项目') class Meta: db_table = 'Source_Project' @@ -63,6 +64,7 @@ class File(models.Model): ('2', '删除'), ('3', '即将上线'), ] + name = models.CharField(max_length=255, verbose_name='文件名称') path = models.CharField(max_length=512, verbose_name='文件路径') super_path = models.ForeignKey("self", null=True, blank=True, verbose_name='上级目录', on_delete=models.CASCADE) @@ -78,9 +80,9 @@ class File(models.Model): create_time = models.DateTimeField(auto_now_add=True) update_time = models.DateTimeField(auto_now=True) anno_num = models.IntegerField(default=0, verbose_name='注释数量') - issue_num = models.IntegerField(default=0, verbose_name='注释数量') + issue_num = models.IntegerField(default=0, verbose_name='问题数量') has_annotation = models.BooleanField(default=False, verbose_name='是否有标注') - + is_competition_file = models.BooleanField(default=False, verbose_name='是否是竞赛文件') class Meta: db_table = 'Source_File' diff --git a/apps/projects/urls.py b/apps/projects/urls.py index 59cba45..ca6a24c 100644 --- a/apps/projects/urls.py +++ b/apps/projects/urls.py @@ -15,7 +15,7 @@ Including another URLconf """ from django.urls import path -from .views import NewProjectView, ProjectListView, ProjectInfoView, ProjectSourceView, ScannerProjectView,RemoveProjectView,GetProjectJstreeView +from .views import NewProjectView, ProjectListView, ProjectInfoView, ProjectSourceView, ScannerProjectView,RemoveProjectView,GetProjectJstreeView,SetCompetitionProjectView app_name = "projects" urlpatterns = [ @@ -24,6 +24,7 @@ urlpatterns = [ path('remove', RemoveProjectView.as_view(), name='remove_project'), path('scanner_project', ScannerProjectView.as_view(), name="scanner_project"), path('get_project_jstree/',GetProjectJstreeView.as_view(),name="get_project_jstree/"), + path('set_competition_project',SetCompetitionProjectView.as_view(),name="set_competition_project/"), # path('/', ProjectInfoView.as_view(), name='info'), # path('/xref', ProjectSourceView.as_view(), name='source') path('', ProjectSourceView.as_view(), name='source') diff --git a/apps/projects/views.py b/apps/projects/views.py index 8466271..413e09d 100644 --- a/apps/projects/views.py +++ b/apps/projects/views.py @@ -72,6 +72,39 @@ class NewProjectView(View): # logging.info(str(datetime.now()) + '删除完成稍后重新导入') # error_msg = '导入失败,请查看日志发现错误后重新导入' # return render(request, 'projects/new.html', locals()) +class SetCompetitionProjectView(View): + def get(self,request): + try: + project_name = request.GET.get('project_name','') + strategy = int(request.GET.get('strategy','')) + path = request.GET.get('path',None) + project = Project.objects.get(name=project_name) + if not project.is_competition_project: + project.is_competition_project=True + project.save() + if strategy>=0 and strategy<=2: + anno_strategy = AnnotationStrategy.objects.get(project=project) + anno_strategy.choice = strategy + anno_strategy.save() + if path is not None: + self.set_competition_files(path,project) + return HttpResponse("Successful") + except Exception as e: + return HttpResponse(str(e)) + + def set_competition_files(self,path,project): + file = File.objects.get(path=path,project=project) + file.is_competition_file=True + file.save() + file_ids = [file.id] + while len(file_ids)>0: + file_id = file_ids.pop(0) + for file in File.objects.filter(super_path_id=file_id): + file.is_competition_file=True + file.save() + file_ids.append(file.id) + + class RemoveProjectView(View): def get(self, request): diff --git a/static/js/source.js b/static/js/source.js index 9bbad16..58fd3b8 100644 --- a/static/js/source.js +++ b/static/js/source.js @@ -470,6 +470,35 @@ function show_new_question_answer(item, content, username) { $(item).parent().siblings(".responseInput").val(""); } +function delete_anno(file_id,line_num,anno_id){ + $.ajax({ + cache: false, + type: "POST", + url: '/operations/delete/', + data: {'object_id':anno_id,"object_type":"Annotation"}, + dataType: 'json', + async: true, + beforeSend: function (xhr, settings) { + xhr.setRequestHeader("X-CSRFToken", csrftoken); + }, + success: function (data) { + if (data.status == 'success') { + $("#ItemcommentPanel").remove() + $("."+file_id+line_num).remove() + $("#codeopration_anno_"+file_id+"_"+line_num).remove(); + show_annotation(file_id,line_num); + layer.msg(data.msg); + }else{ + layer.msg(data.msg); + } + },error:function(jqXHR, textStatus, errorThrown){ + if(jqXHR.readyState===0&&jqXHR.status===0){ + alert('网络故障,提交失败!请联网后重新提交'); + } + } + }); + +} function add_annotation(item,file_id, line_num) { @@ -506,20 +535,20 @@ 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 = ''; - str +=''; - $("#codeopration_anno_" + +file_id + "_" + line_num).html(str); - $(".addno-panel").hide(); - $(".source-addno-panel").remove(); - // show_annotation(file_id,line_num); - //将注释添加到当前行的上一行 - var contenthtml ='
'+'
'+'
'+"//"+ content+'
'+'
'+'
'; - var html = '
'+contenthtml+'
'; - var id=file_id+'_'+"L"+line_num; - $("#"+id).before(html); + // 因为可能注释或问题没有值的时候,不会为该代码块添加html代码,所以首先判断 + // 然后将注释数+1 + var codeopration_anno_div = $("#codeopration_anno_"+file_id+"_" + line_num).html() + var str = ''; + str +=''; + $("#codeopration_anno_" + +file_id + "_" + line_num).html(str); + $(".addno-panel").hide(); + $(".source-addno-panel").remove(); + // show_annotation(file_id,line_num); + //将注释添加到当前行的上一行 + var contenthtml ='
'+'
'+'
'+"//"+ content+'
'+'
'+'
'; + var html = '
'+contenthtml+'
'; + var id=file_id+'_'+"L"+line_num; + $("#"+id).before(html); $.ajax({ cache: false, type: "POST", @@ -534,7 +563,7 @@ function submit_annotation(file_id, line_num, content) { if (data.status == 'success') { layer.msg('提交成功'); }else{ - layer.msg(data.msg); + layer.msg(data.msg); } },error:function(jqXHR, textStatus, errorThrown){ if(jqXHR.readyState===0&&jqXHR.status===0){ diff --git a/templates/projects/filesub/annotation.html b/templates/projects/filesub/annotation.html index 0b4b85e..1e53b13 100644 --- a/templates/projects/filesub/annotation.html +++ b/templates/projects/filesub/annotation.html @@ -47,6 +47,7 @@
+ 删除 {% if allow_modify %} 修改 {% endif %}