def post(self, request, *args, **kwargs): content = request.POST.get('content') aid = kwargs.get('aid') cid = request.POST.get('cid') tid = request.POST.get('tid') reply = unicode(request.POST.get('reply', '-1')) if reply == '1': comments = Comment.objects.filter(id=cid) if not comments.exists(): self.message = '回复评论不存在' self.status_code = INFO_NO_EXIST return self.render_to_response(dict()) toer = Guest.objects.get(id=tid) comment = CommentReply(comment=comments[0], to=toer) else: article = Article.objects.filter(id=aid) if not article.exists(): self.message = '评论文章不存在' self.status_code = INFO_NO_EXIST return self.render_to_response(dict()) comment = Comment() comment.belong = article[0] if content: comment.content = content else: self.message = '请输入评论内容' self.status_code = ERROR_DATA return self.render_to_response(dict()) if not self.wrap_check_token_result(): state = self.generate_state() comment.state = state comment.save() url = get_github_auth(state) return self.render_to_response({'url': url}) else: comment.author = self.user comment.review = True comment.save() send_mail('新评论', '你有一条新评论, 登陆查看 www.rapospectre.com ', '*****@*****.**', ['*****@*****.**'], fail_silently=True) if isinstance(comment, CommentReply): send_html_mail('评论回复', comment.to, comment.comment.belong, [comment.to.email]) return self.render_to_response(dict())
def post(self, request, *args, **kwargs): content = request.POST.get('content') aid = kwargs.get('aid') cid = request.POST.get('cid') tid = request.POST.get('tid') reply = unicode(request.POST.get('reply', '-1')) if reply == '1': comments = Comment.objects.filter(id=cid) if not comments.exists(): self.message = '回复评论不存在' self.status_code = INFO_NO_EXIST return self.render_to_response(dict()) toer = Guest.objects.get(id=tid) comment = CommentReply(comment=comments[0], to=toer) else: article = Article.objects.filter(id=aid) if not article.exists(): self.message = '评论文章不存在' self.status_code = INFO_NO_EXIST return self.render_to_response(dict()) comment = Comment() comment.belong = article[0] if content: comment.content = content else: self.message = '请输入评论内容' self.status_code = ERROR_DATA return self.render_to_response(dict()) if not self.wrap_check_token_result(): state = self.generate_state() comment.state = state comment.save() url = get_github_auth(state) return self.render_to_response({'url': url}) else: comment.author = self.user comment.review = True comment.save() send_mail('新评论', '你有一条新评论, 登陆查看 www.rapospectre.com ', '*****@*****.**', ['*****@*****.**'], fail_silently=True) if isinstance(comment, CommentReply): send_html_mail('评论回复', comment.to, comment.comment.belong, [comment.to.email]) return self.render_to_response(dict())
def get(self, request, *args, **kwargs): code = request.GET.get('code') state = request.GET.get('state') if code and state: access_token = get_access_token(code, state) email, nick, avatar = get_user_info(access_token) guest = Guest.objects.filter(email=email) token = self.create_token() if guest.exists(): guest = guest[0] guest.token = token guest.save() else: status, avatar_path = save_image( avatar, '{0}{1}.png'.format(nick, unicode(time.time()).split('.')[0])) guest = Guest(email=email, nick=nick, token=token) guest.set_password('123456q_+|') if status: guest.avatar = avatar_path guest.save() comment = Comment.objects.filter(state=state) aid = 0 if not comment.exists(): comment = CommentReply.objects.filter(state=state) else: aid = comment[0].belong.id send_mail('新评论', '你有一条新评论, 登陆查看 www.rapospectre.com', '*****@*****.**', ['*****@*****.**'], fail_silently=True) if comment.exists(): comment = comment[0] comment.author = guest comment.review = True comment.save() if aid == 0: aid = comment.comment.belong.id send_html_mail('评论回复', comment.to, comment.comment.belong, [comment.to.email]) request.session['token'] = token return HttpResponseRedirect('/blog/{0}'.format(aid))
def get(self, request, *args, **kwargs): code = request.GET.get('code') state = request.GET.get('state') if code and state: access_token = get_access_token(code, state) gid, email, nick, avatar = get_user_info(access_token) guest = Guest.objects.filter(uid=gid) token = self.create_token() if guest.exists(): guest = guest[0] guest.token = token guest.save() else: # status, avatar_path = save_image(avatar, '{0}{1}.png'.format(nick, unicode(time.time()).split('.')[0])) guest = Guest(email=email, nick=nick, token=token, uid=gid) guest.set_password('123456q_+|') # if status: guest.avatar = avatar guest.save() comment = Comment.objects.filter(state=state) aid = 0 if not comment.exists(): comment = CommentReply.objects.filter(state=state) else: aid = comment[0].belong.id send_mail('新评论', '你有一条新评论, 登陆查看 www.rapospectre.com', '*****@*****.**', ['*****@*****.**'], fail_silently=True) if comment.exists(): comment = comment[0] comment.author = guest comment.review = True comment.save() if aid == 0: aid = comment.comment.belong.id send_html_mail('评论回复', comment.to, comment.comment.belong, [comment.to.email]) request.session['token'] = token return HttpResponseRedirect('/blog/{0}'.format(aid))