def replyComment(request): commentForm = forms.CommentForm(request.POST) if commentForm.is_valid(): comment = commentForm.cleaned_data.get('thisComment') user_id = request.session.get('user_id') user = user_views.query_by_id(user_id) course = thisPageCourse to_comment_id = commentForm.cleaned_data.get("ToCommentID") to_comment = query_by_id(to_comment_id) # 创建新回复 newComment = models.Comment() newComment.To_Comment_ID = to_comment newComment.Comment_text = comment newComment.Course_ID = course newComment.Comment_User_ID = user newComment.save() comments = query_by_Course(thisPageCourse) newCommentForm = forms.CommentForm() return render(request, 'detail.html', {"course": thisPageCourse, 'commentForm': newCommentForm, 'comments': comments}) newCommentForm = forms.CommentForm() comments = query_by_Course(thisPageCourse) return render(request, 'detail.html', {"course": thisPageCourse, 'commentForm': newCommentForm, 'comments': comments, 'message': '回复不得为空'})
def star(request): user = user_views.query_by_id(request.session.get('user_id')) stars = get_favorite_list(user) real_stars = [] for star in stars: for course in course_views.get_all_courses(): if course == star.Course_ID: real_stars.append(course) break return render(request, 'star.html', {'courses': real_stars})
def record(request): if request.method == 'POST': record_id = request.POST.get("delete_id") page_num = request.POST.get("page") delete_by_id(record_id) return redirect('/record/?page=' + page_num) user_id = request.session.get("user_id") user = MS_views.query_by_id(user_id) my_records = query_by_user(user) page = 1 if request.method == 'GET' and request.GET.get('page') is not None: page = request.GET.get('page') if my_records.count() % 7 == 0: total_page = int(my_records.count() / 7) else: total_page = int(my_records.count() / 7) + 1 if int(page) > total_page: page = total_page return redirect('/record/?page=' + str(page)) return render(request, "BrowseRecords.html", { "records": my_records, "this_page": page })
def makeComment(request): commentForm = forms.CommentForm(request.POST) if commentForm.is_valid(): comment = commentForm.cleaned_data.get('thisComment') # 读取表单返回的值,返回类型为字典dict型 user_id = request.session.get('user_id') user = user_views.query_by_id(user_id) course = thisPageCourse newComment = models.Comment() newComment.Comment_text = comment newComment.Course_ID = course newComment.Comment_User_ID = user newComment.save() comments = query_by_Course(thisPageCourse) newCommentForm = forms.CommentForm() return render(request, 'detail.html', {"course": thisPageCourse, 'commentForm': newCommentForm, 'comments': comments}) newCommentForm = forms.CommentForm() comments = query_by_Course(thisPageCourse) return render(request, 'detail.html', {"course": thisPageCourse, 'commentForm': newCommentForm, 'comments': comments, 'message': '评论不得为空'})
def index(request): # tests.testCoursePart.test_add_course(self=None) courses = get_all_courses() if request.GET.get('course_name') != "" and \ request.GET.get('course_name') is not None: courses = web_query_by_name(courses, request) if request.GET.get('course_college') != "" and \ request.GET.get('course_college') is not None: courses = web_query_by_college(courses, request) if request.GET.get('course_teacher') != "" and \ request.GET.get('course_teacher') is not None: courses = web_query_by_teacher(courses, request) if request.GET.get('course_type') != "" and \ request.GET.get('course_type') is not None: courses = web_query_by_type(courses, request) if request.method == 'POST': # decision = request.POST.get('decision_id') if request.POST.get('decision_id') == "like": add_favor(request.session.get('user_id'), request.POST.get('star_id')) else: delete_favor(request.session.get('user_id'), request.POST.get('star_id')) return redirect('/index/') # all_course = get_all_courses() user = user_view.query_by_id(request.session.get('user_id')) stars = get_favorite_list(user) real_stars = [] for star in stars: for course in get_all_courses(): if course == star.Course_ID: real_stars.append(course) break return render(request, 'index.html', { 'courses': courses, 'stars': real_stars })
def add_record(user_id, course_id): newRecord = models.BrowseRecords() newRecord.Course_ID = CP_views.query_by_id2(course_id) newRecord.User_ID = MS_views.query_by_id(user_id) newRecord.save()
def messages(request): user_id = request.session.get('user_id') user = user_views.query_by_id(user_id) Messages = get_user_messages(user) return render(request, "messages.html", {"messages": Messages})
def my_comments(request): user_id = request.session.get('user_id') user = user_views.query_by_id(user_id) myComments = query_by_user(user) return render(request, "my_comments.html", {"my_comments": myComments})
def delete_favor(user_id, course_id): user = user_views.query_by_id(user_id) course = course_views.query_by_id2(course_id) favor = models.Favorites.objects.get(Course_ID=course, User_ID=user) models.Favorites.delete(favor)
def add_favor(user_id, course_id): user = user_views.query_by_id(user_id) course = course_views.query_by_id2(course_id) models.Favorites.objects.update_or_create(Course_ID=course, User_ID=user)