def comment(request): if request.method == 'POST': if 'first_comment_time' not in request.session or request.session[ 'user_comment_count'] < 5: request.session['first_comment_time'] = datetime.datetime.now( ).strftime("%H %M %S") new_comment_obj = models.Comment( article_id=request.POST.get('article_id'), parent_comment_id=request.POST.get('parent_comment_id') or None, comment_type=request.POST.get("comment_type"), user_id=request.user.userprofile.id, comment=request.POST.get('comment')) user_obj = models.UserProfile.objects.get( id=request.user.userprofile.id) experience = user_obj.experience + 10 user_obj.experience = experience user_obj.save() new_comment_obj.save() user_comment_count = request.session['user_comment_count'] + 1 request.session['user_comment_count'] = user_comment_count return HttpResponse('post-comment-success') else: now_time = datetime.datetime.now().strftime("%H %M %S").split(' ') session_time = request.session['first_comment_time'].split(' ') time_diff = (int(now_time[0]) - int(session_time[0])) * 3600 + ( int(now_time[1]) - int(session_time[1])) * 60 + ( int(now_time[2]) - int(session_time[2])) if time_diff < 60: return HttpResponse('comment-num-out') elif time_diff > 60: del request.session['first_comment_time'] request.session['user_comment_count'] = 0 new_comment_obj = models.Comment( article_id=request.POST.get('article_id'), parent_comment_id=request.POST.get('parent_comment_id') or None, comment_type=request.POST.get("comment_type"), user_id=request.user.userprofile.id, comment=request.POST.get('comment')) user_obj = models.UserProfile.objects.get( id=request.user.userprofile.id) experience = user_obj.experience + 10 user_obj.experience = experience article_obj = models.Article.objects.get( id=request.POST.get('article_id')) priority = article_obj.priority + 5 article_obj.priority = priority article_obj.save() user_obj.save() new_comment_obj.save() user_comment_count = request.session['user_comment_count'] + 1 request.session['user_comment_count'] = user_comment_count request.session['first_comment_time'] = datetime.datetime.now( ).strftime("%H %M %S") return HttpResponse('post-comment-success') return HttpResponseRedirect(request.path)
def comment(request): print(request.POST) new_comment_obj = models.Comment( article_id=request.POST.get('article_id'), parent_comment_id=request.POST.get('parent_comment_id') or None, comment_type=request.POST.get('comment_type'), comment=request.POST.get('comment'), user_id=request.user.userprofile.id, ) new_comment_obj.save() return HttpResponse('ok')
def comment(request): print(request.POST) if request.method == 'POST': new_comment_obj = models.Comment( articles_id=request.POST.get('article_id'), parent_comment_id=request.POST.get('parent_comment_id') or None, comment_type=request.POST.get('comment_type'), user_id=request.user.userprofile.id, comment=request.POST.get('comment')) new_comment_obj.save() return HttpResponse('post-comment-success')
def userComment(request): # return HttpResponse("isok?") if request.method == 'POST': comment=models.Comment(comment_type=request.POST.get("comment_type"), comment=request.POST.get("comment"), article_id=request.POST.get("article_id"), parent_comment_id=request.POST.get("parent_comment_id",None), user_id=request.user.userprofile.id ) comment.save() return HttpResponse('post-comment-success')
def post_comment(request): if request.method == 'POST': try: new_comment_obj = models.Comment( article_id=request.POST.get("article_id"), parent_comment_id=request.POST.get("parent_comment_id") or None, comment_type=request.POST.get("comment_type"), user_id=request.user.userprofile.id, comment=request.POST.get("comment")) new_comment_obj.save() except Exception as e: return HttpResponse("post-comment-fail") return HttpResponse("post-comment-success")
def comment(request): print(request.POST) if request.method == 'POST': new_comment_obj = models.Comment( article_id=request.POST.get('article_id'), parent_comment_id=request.POST.get('parent_commet_id' or None), comment_type=request.POST.get("comment_type"), user_id=request.user.userprofile.id, #这里要主要,我们在bbs系统用户验证用的是Django自带的用户验证模块,经过验证的用户其实是admin的后台账户,我们在前台是userprofile和admin的user做了1对1的外键关联. #所以这里是 request.user.userprofile.id而不是request.userprofile.id comment=request.POST.get('comment'), ) new_comment_obj.save() return HttpResponse('post-comment-success')
def post_comments(request): if request.method == 'POST': if models.Article.objects.get(id=request.POST.get('article_id')): new_comment_obj = models.Comment( article_id=request.POST.get('article_id'), parent_comment_id=request.POST.get('parent_comment_id') or None, comment_type=request.POST.get('comment_type'), user_id=request.user.userprofile.id, comment=request.POST.get('comment') ) new_comment_obj.save() comment_error = None else: comment_error = '你所评论的文章不存在!' return HttpResponse(comment_error or 'ok')
def comment(request): ''' 获取文章评论 :param request: :return: ''' if request.method == "POST": # print(request.POST) new_comment_obj = models.Comment( article_id=request.POST.get("article_id"), parent_comment_id=request.POST.get("parent_comment_id", None), comment_type=request.POST.get("comment_type"), user_id=request.user.userprofile.id, comment=request.POST.get("comment_content"), ) new_comment_obj.save() return HttpResponse("success")
def comment(request): ''' 提交评论,将Ajax提交的数据写入数据库 :param request: :return: ''' print(request.POST) if request.method == 'POST': new_comment_obj = models.Comment( article_id=request.POST.get('article_id'), parent_comment_id=request.POST.get('parent_comment_id') or None, comment_type=request.POST.get('comment_type'), user_id=request.user.userprofile.id, comment=request.POST.get('comment')) new_comment_obj.save() return HttpResponse('ok')
def comment(request): """发表评论 """ ret = {'status': True, 'comment': ''} # print(request.POST) if request.method == 'POST': try: new_comment = models.Comment( article_id=request.POST.get('article_id'), parent_comment_id=request.POST.get('parent_id' or None), comment_type=request.POST.get('comment_type'), user_id=request.user.userprofile.id, comment=request.POST.get('comment'), ) new_comment.save() ret['comment'] = request.POST.get('comment') except Exception as e: ret['status'] = False ret['comment'] = e return HttpResponse(json.dumps(ret))