From c080282b54295876be058dc97e00e11a28f1bec7 Mon Sep 17 00:00:00 2001 From: wrmswindmill Date: Thu, 4 Oct 2018 13:51:16 +0800 Subject: [PATCH] add user_watch_behavior --- apps/operations/migrations/0022_userwatch.py | 33 +++++++++++++++++++ apps/operations/models.py | 18 ++++++++++ apps/operations/urls.py | 8 ++--- apps/operations/views.py | 20 +++++++++-- apps/users/views.py | 15 ++------- dump.rdb | Bin 588 -> 726 bytes static/js/source.js | 29 +++++++++++++--- templates/users/login.html | 2 +- 8 files changed, 100 insertions(+), 25 deletions(-) create mode 100644 apps/operations/migrations/0022_userwatch.py diff --git a/apps/operations/migrations/0022_userwatch.py b/apps/operations/migrations/0022_userwatch.py new file mode 100644 index 0000000..9b3a4ca --- /dev/null +++ b/apps/operations/migrations/0022_userwatch.py @@ -0,0 +1,33 @@ +# Generated by Django 2.0.6 on 2018-10-04 13:40 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('projects', '0020_project_is_competition_project'), + ('operations', '0021_remove_search_answer_project'), + ] + + operations = [ + migrations.CreateModel( + name='UserWatch', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('view_type', models.CharField(choices=[('issue_question', '问题'), ('annotation', '注释'), ('file', '代码文件')], default='', max_length=20, verbose_name='查看对象名称')), + ('line_num', models.IntegerField(default=0)), + ('create_time', models.DateTimeField(auto_now_add=True)), + ('file', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='projects.File', verbose_name='文件')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='用户')), + ], + options={ + 'verbose_name': '查看', + 'verbose_name_plural': '查看', + 'db_table': 'UserWatch', + }, + ), + ] diff --git a/apps/operations/models.py b/apps/operations/models.py index f0f1d33..06ad4ba 100644 --- a/apps/operations/models.py +++ b/apps/operations/models.py @@ -331,6 +331,24 @@ class Vote(models.Model): verbose_name = u"点赞" verbose_name_plural = verbose_name +class UserWatch(models.Model): + TYPE_CHOICE = [ + ('issue_question', '问题'), + ('annotation', '注释'), + ('file', '代码文件'), + ] + + view_type = models.CharField(max_length= 20, choices=TYPE_CHOICE, default='', verbose_name='查看对象名称') + line_num = models.IntegerField(default=0) + file = models.ForeignKey(File,verbose_name=u"文件",on_delete=models.CASCADE) + user = models.ForeignKey(User,verbose_name=u"用户",on_delete=models.CASCADE) + create_time = models.DateTimeField(auto_now_add=True) + + class Meta: + db_table = 'UserWatch' + verbose_name = u"查看" + verbose_name_plural = verbose_name + class AnnotationStrategy(models.Model): CHOICE = [ diff --git a/apps/operations/urls.py b/apps/operations/urls.py index 440b656..542ff96 100644 --- a/apps/operations/urls.py +++ b/apps/operations/urls.py @@ -15,10 +15,7 @@ Including another URLconf """ from django.urls import path -from .views import ShowIssueQuestionView, ShowAnnotationView, ShowNavigationView -from .views import AddAnnotationView, AddArticleView, AddQuestionView, AddIssueAnswerView, AddCommentView,Collect_Search_Answer -from .views import UpdateAnnotationView, UpdateArticleView, UpdateQuestionView, UpdateAnswerView, UpdateCommentView,RightView,GetJstreeIdView,DeleteView -from .views import AddVoteView, AcceptAnswerView, ShowMethodInfo, GetHotestIssuesView, Get_CodeReading_Content_View, AddQuestionAnswerView, GetAddtabParasView,ModifyAnnotationView +from .views import * app_name = "operations" urlpatterns = [ @@ -46,5 +43,6 @@ urlpatterns = [ path('right/',RightView.as_view(),name='right/'), path('get_jstree_id/',GetJstreeIdView.as_view(),name='get_jstree_id/'), path('submit_search_answer/',Collect_Search_Answer.as_view(),name='submit_search_answer/'), - path('delete/',DeleteView.as_view(),name="delete/") + path('delete/',DeleteView.as_view(),name="delete/"), + path('record_user_watch_behavior/',SaveUserBehaviorView.as_view(),name='record_user_watch_behavior/') ] diff --git a/apps/operations/views.py b/apps/operations/views.py index 0faafaa..68383bc 100644 --- a/apps/operations/views.py +++ b/apps/operations/views.py @@ -12,7 +12,7 @@ from django.db.models import Count from .models import Annotation, Question, QuestionAnswer, Article, Issue, IssueAnswer, IssueStandardAnswers, IssueChoices,Search_Answer from .models import AnnotationComment, QuestionAnswerComment, ArticleComment, IssueComment, AnnotationStrategy,Competition -from .models import Vote +from .models import Vote,UserWatch from users.models import User from .forms import NewArticleForm from projects.models import File,Method @@ -81,7 +81,7 @@ user_team_map ={} set_init_rank() -def get_educoder_group_userlist_by_educoder_userid(userid,file_id): +def get_educoder_group_userlist_by_educoder_userid(userid,line_num): # 根据file_id查询project再查询到对应的比赛 project = File.objects.get(id=file_id).project try: @@ -1533,3 +1533,19 @@ class GetProjectTreeView(View): except: return HttpResponse(json.dumps({"status": "fail"}), content_type='application/json') +class SaveUserBehaviorView(View): + def post(self, request): + # 先判断他是文件还是文件夹 + if not request.user.is_authenticated: + return HttpResponse(json.dumps({"status": "fail", "msg": "用户未登录"}), content_type='application/json') + try: + user_watch = UserWatch() + user_watch.user = request.user + user_watch.file = File.objects.get(id=request.POST.get("file_id","")) + user_watch.line_num = request.POST.get("line_num","") + user_watch.view_type = request.POST.get("view_type","") + print(user_watch) + user_watch.save() + return HttpResponse(json.dumps({"status": "success"}), content_type='application/json') + except: + return HttpResponse(json.dumps({"status": "fail"}), content_type='application/json') diff --git a/apps/users/views.py b/apps/users/views.py index e3b193c..e7e1a90 100644 --- a/apps/users/views.py +++ b/apps/users/views.py @@ -88,7 +88,7 @@ class RegisterView(View): user.email = email user.is_active = True user.password = make_password(pwd1) - user.password_codepedia = user.password + user.password_codepedia = make_password(pwd1) user.save() return render(request,'users/login.html') @@ -195,7 +195,7 @@ class LoginView(View): user = User() user.username = email user.password = make_password(pass_word) - user.password_codepedia = user.password + user.password_codepedia = make_password(pass_word) user.email = email if 'lastname' in user_message: user.nick_name = user_message['lastname'] @@ -275,21 +275,11 @@ class LoginView(View): return render(request, 'users/login.html', {'msg': '用户名或密码错误!'}) def login_default(self,email,pass_word,request): - # import re - # if re.match(r'[0-9a-zA-Z_]{0,19}@163.com',email): - # print(11111111111) exist_records = User.objects.filter(email=email).first() - # print(exist_records) - # else: - # exist_records = User.objects.filter(username=email).first() - # print(exist_records) - if exist_records: - user = exist_records user.password = user.password_codepedia user.save() - user = authenticate(email=email, password=pass_word) if user is not None: if user.is_active: @@ -320,6 +310,7 @@ class LoginView(View): # chocie=2表示educoder,是指用educoder的方式登陆 # chocie=3表示trustie,是指用trustie的方式登陆 if choice == 1: + print(1111) return self.login_default(email,pass_word,request) elif choice == 2: return self.login_educoder(email,pass_word,request) diff --git a/dump.rdb b/dump.rdb index 349c3c0d4fbf9b19721ae69d535130de769e2f09..c1d69f298ff58321dbc0761d3bb66c0d2a3138da 100644 GIT binary patch delta 382 zcmWm6KP*F06bA5n?>X;P{Htn7smHBoG?J2*C<&n|sSdg~UEZKelNyMTN-X|{ModP; zF0rtjm<=YANg7KhiqIylWBBFEch8smh|k7JxMTDBHdAfdSkJD6^4a{uQ!&;*v5<>f zXn_!34b4>{$Sd((QIBni0jAjy3$PJ3$!3e^H!^yflKH|8*Il-68;(1P6-B7#4bxQk zsmRHPF6Ltv`~S~x8?A#9zZ8v2{82P#8}5?Cs-m#OnxcrpdOOgzHeD{DlE8W=P+4N# z1GK6=+7v0lyEWuv10}oXI>5WU2b!)e%Y0yiO T4zyEk$wp)ByW%e&CD;A{y?A1y delta 197 zcmcb{dWL0!p}^w98>4@5loqF^=;o&89txP~D5v81z-b=KJSGN)nF`EYw-^`>NHDT| zWI7<3z{(&G#0o&HG_hWs(S73NO^nWy-57H<8h~QWK->YuT?wpg&WtRdm=1ITS$d2t zpP3HqN?>JVVRGP}e3DV#%a@7eJJSJmMwTB;2aJIl>=RhoWf@t1G955ta$w~(WMuix tbij{^