add user_watch_behavior

This commit is contained in:
wrmswindmill 2018-10-04 13:51:16 +08:00
parent 2bccd9060e
commit c080282b54
8 changed files with 100 additions and 25 deletions

View File

@ -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',
},
),
]

View File

@ -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 = [

View File

@ -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/')
]

View File

@ -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')

View File

@ -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)

BIN
dump.rdb

Binary file not shown.

View File

@ -137,12 +137,28 @@ function getCookie(name) {
}
var csrftoken = getCookie('csrftoken');
function record_user_watch_behavior(file_id,line_num,view_type){
$.ajax({
cache: false,
type: "POST",
url: '/operations/record_user_watch_behavior/',
data: { 'file_id': file_id, 'line_num': line_num,'view_type':view_type },
dataType: 'json',
async: true,
beforeSend: function (xhr, settings) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
});
}
function show_annotation(file_id, line_num) {
ev = window.event;
if(ev==undefined){
ev=arguments.callee.caller.arguments[0]||window.event;
}
var mousePos = mouseCoords(ev)
// ev = window.event;
// if(ev==undefined){
// ev=arguments.callee.caller.arguments[0]||window.event;
// }
// var mousePos = mouseCoords(ev)
record_user_watch_behavior(file_id,line_num,"annotation")
$.ajax({
cache: false,
@ -271,12 +287,15 @@ function modify_anno(file_id,line_num,anno_id){
// FIXME
function show_issue_question(file_id, line_num, issue_ids) {
issueid_str=issue_ids.toString()
ev = window.event;
if(ev==undefined){
ev=arguments.callee.caller.arguments[0]||window.event;
}
var mousePos = mouseCoords(ev)
// record_user_watch_behavior(file_id,line_num,"issue_question")
//发送问题id返回问题内容
$.ajax({
cache: false,

View File

@ -24,7 +24,7 @@
<form id="email_register_form" method="post" action="{% url 'users:login' %}" autocomplete="off">
<ul>
<li class="new_register_li form-group {% if login_form.errors.email %}errorput{% endif %}">
<input type="text" class="new_register_input" id="id_email" name="email" placeholder="请输入您的邮箱地址或用户名">
<input type="text" class="new_register_input" id="id_email" name="email" placeholder="请输入您的邮箱地址">
</li>
<li class="new_register_li form-group {% if login_form.errors.password %} errorput{% endif %}">
<input type="password" class="new_register_input" id="id_password" name="password" value="{{ login_form.password1.value }}" placeholder="请输入6-20位非中文字符密码" />