diff --git a/Codepedia2/settings.py b/Codepedia2/settings.py index 201ae0a..6985e71 100644 --- a/Codepedia2/settings.py +++ b/Codepedia2/settings.py @@ -120,7 +120,7 @@ WSGI_APPLICATION = 'Codepedia2.wsgi.application' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'codepedia_1', + 'NAME': 'codepedia', 'USER': 'root', 'PASSWORD': 'codepedia123', 'HOST': '127.0.0.1' diff --git a/apps/operations/migrations/0016_annotation_modify_user_id.py b/apps/operations/migrations/0016_annotation_modify_user_id.py new file mode 100644 index 0000000..65e8bab --- /dev/null +++ b/apps/operations/migrations/0016_annotation_modify_user_id.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.6 on 2018-08-25 18:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('operations', '0015_auto_20180821_1142'), + ] + + operations = [ + migrations.AddField( + model_name='annotation', + name='modify_user_id', + field=models.CharField(max_length=255, null=True, verbose_name='本次标注的修改者的ID'), + ), + ] diff --git a/apps/operations/models.py b/apps/operations/models.py index 4ae62a9..bf57fa7 100644 --- a/apps/operations/models.py +++ b/apps/operations/models.py @@ -66,6 +66,7 @@ class Annotation(models.Model): create_time = models.DateTimeField(auto_now_add=True) update_time = models.DateTimeField(auto_now=True) commit_id = models.CharField(max_length=255) + modify_user_id = models.CharField(max_length=255,verbose_name='本次标注的修改者的ID',null=True) class Meta: db_table = 'Annotation' diff --git a/apps/operations/views.py b/apps/operations/views.py index 3a4bd3d..b3c73a8 100644 --- a/apps/operations/views.py +++ b/apps/operations/views.py @@ -46,8 +46,10 @@ def get_educoder_group_userlist_by_educoder_userid(userid,file_id): def get_group_users(user_id,file_id): educoder_userid = User.objects.get(id=user_id).educoder_userid + # print(educoder_userid) # 调用educoder的接口,返回对应的username list educoder_userids = get_educoder_group_userlist_by_educoder_userid(educoder_userid,file_id) + print(educoder_userids) users = User.objects.filter(educoder_userid__in=educoder_userids) return users @@ -89,11 +91,14 @@ class ShowAnnotationView(View): users = get_group_users(user_id,file_id) # user_ids = [] # 然后调用 + print(users) commit_id = self.get_current_commitid_by_fileid(file_id) - if users is None: + # print(Annotation.objects.filter(file_id=file_id, linenum=line_num,is_latest=1,commit_id=commit_id)) + if len(users)==0: annotations = Annotation.objects.filter(file_id=file_id, linenum=line_num,user_id=user_id,is_latest=1,commit_id=commit_id) else: annotations = Annotation.objects.filter(file_id=file_id, linenum=line_num,user__in=users,is_latest=1,commit_id=commit_id) + print(annotations) return annotations @@ -403,8 +408,9 @@ class ModifyAnnotationView(View): content = request.POST.get('content', '') file_id = int(request.POST.get('file_id', '')) linenum = int(request.POST.get('line_num', '')) + anno_id = int(request.POST.get('anno_id', '')) # 查询到之前的注释,根据file_id,line_num,user_id; - annotation = Annotation.objects.get(file_id=file_id, linenum=linenum, user_id=request.user.id,is_latest=1) + annotation = Annotation.objects.get(file_id=file_id, linenum=linenum, id=anno_id,is_latest=1) # 然后插入一条新的记录,anno_id其他的都一样,除了content以及is_latest new_annotation = Annotation() new_annotation.file_id = file_id @@ -413,6 +419,7 @@ class ModifyAnnotationView(View): new_annotation.project_id = annotation.project_id new_annotation.user = annotation.user new_annotation.anno_id = annotation.anno_id + new_annotation.modify_user_id = request.user.id new_annotation.is_latest = 1 project_name = File.objects.get(id=file_id).project.name diff --git a/apps/users/views.py b/apps/users/views.py index 8abe618..1402801 100644 --- a/apps/users/views.py +++ b/apps/users/views.py @@ -222,6 +222,7 @@ class LoginView(View): return render(request, 'users/login.html', {'msg': '用户名或密码错误!'}) def login_educoder(self,email,pass_word,request): + private_token = "hriEn3UwXfJs3PmyXnSG" user_params = {'username': email, 'password': pass_word,"private_token":private_token} login_url = 'https://www.educoder.net/api/v1/sources/login' @@ -230,18 +231,21 @@ class LoginView(View): print(response) status = response['status'] if status == 1: + # 因为用户可能是邮箱也可能是用户名登录,所以先获取到educoder用户的用户名 + # 调用接口获取用户的email + educoder_userid = response['user_id'] + print(educoder_userid) + userinfo_url = "http://www.educoder.net/api/v1/sources/"+str(educoder_userid)+"/get_user_info?private_token="+private_token + response = requests.get(userinfo_url) + response = json.loads(response.text) + + email = response['email'] + exist_records = User.objects.filter(email=email).first() if not exist_records: - educoder_userid = response['user_id'] - # educoder_userid = "15583" - userinfo_url = "http://www.educoder.net/api/v1/sources/"+str(educoder_userid)+"/get_user_info?private_token="+private_token - response = requests.get(userinfo_url) - response = json.loads(response.text) - user = User() user.username = response['username'] - while User.objects.filter(username=user.username).first(): user.username += str(random.randint(0,10)) @@ -270,7 +274,12 @@ class LoginView(View): return render(request, 'users/login.html', {'msg': '用户名或密码错误!'}) def login_default(self,email,pass_word,request): - exist_records = User.objects.filter(email=email).first() + import re + if re.match(r'[0-9a-zA-Z_]{0,19}@163.com',email): + exist_records = User.objects.filter(email=email).first() + else: + exist_records = User.objects.filter(username=email).first() + if exist_records: user = exist_records diff --git a/static/css/code_show.css b/static/css/code_show.css index 8139abb..5288692 100644 --- a/static/css/code_show.css +++ b/static/css/code_show.css @@ -1581,4 +1581,7 @@ color: #FFF !important; } .filePathInfomarbootom{ margin-bottom: 0px; +} + +.anno_textarea{ } \ No newline at end of file diff --git a/static/js/source.js b/static/js/source.js index a425719..66983cb 100644 --- a/static/js/source.js +++ b/static/js/source.js @@ -55,6 +55,9 @@ function show_annotation(file_id, line_num) { function close_modify_anno(){ $(".modify_anno_div").remove(); + $("#modify_anno_textarea").attr("readonly","readonly") + + ev = window.event; if(ev==undefined){ ev=arguments.callee.caller.arguments[0]||window.event; @@ -63,11 +66,13 @@ function close_modify_anno(){ } //注入html代码 -function inject_modifyAnno_html(item,file_id,linenum) { - $(".modify_anno_div").remove(); +function inject_modifyAnno_html(item,file_id,linenum,anno_id) { + $(".modify_anno_div").remove(); + $("#modify_anno_textarea").removeAttr("readonly"); + $("#modify_anno_textarea").focus() + html_str = '
'; $(item).after(html_str) @@ -79,7 +84,7 @@ function inject_modifyAnno_html(item,file_id,linenum) { } // FIXME -function modify_anno(file_id,line_num){ +function modify_anno(file_id,line_num,anno_id){ // 获取修改后的内容 var content=$("#modify_anno_textarea").val(); if (content == null || content == undefined || content.trim() == '') { @@ -90,7 +95,7 @@ function modify_anno(file_id,line_num){ cache: false, type: "POST", url: '/operations/modify_anno/', - data: { 'file_id': file_id, 'line_num': line_num,'content':content }, + data: { 'file_id': file_id, 'line_num': line_num,'anno_id':anno_id,'content':content }, dataType: 'json', async: true, beforeSend: function (xhr, settings) { diff --git a/templates/projects/filesub/annotation.html b/templates/projects/filesub/annotation.html index 6b40a7b..a6bdf79 100644 --- a/templates/projects/filesub/annotation.html +++ b/templates/projects/filesub/annotation.html @@ -25,9 +25,9 @@