def show_comment(tid): form = ReplyForm() if request.method == 'GET': page = request.args.get('page') if not page: page = 1 else: page = int(page) if page == 1: comment = Comment.query.get(tid) else: comment = None title = Comment.query.get(tid).title reply_list = Reply.query.filter_by(tid = tid).order_by(Reply.tid).paginate(page, MAX_REPLY_NUM_ONE_PAGE,False) return render_template('showcomment.html', tid = tid, title = title, comment = comment, page = page,reply_list = reply_list, form = form) else: reply = Reply(tid = tid, userid = current_user.userid, nickname = current_user.nickname, \ content = form.content.data, post_time = get_now_time()) comment = Comment.query.get(tid) comment.re += 1 reply.save() db.session.commit() return redirect(request.referrer)
async def submit_reply(event, ctx, user, *args, **kwargs): data = event.body replier_uid = str(user['_id']) rid = 'r' + str(uuid.uuid4())[:13] qid = data.qid q_m = QuestionModel.get_maybe(qid) if q_m == Nothing: raise LambdaError(404, 'question not found') body = data.body if not (0 < len(body) <= 4000): raise Exception("Your question is too large!") ts = datetime.datetime.now() parent_rid = data.get('parent_rid', None) child_rids = list() is_staff = await has_role('qanda_staff', user['_id']) r = Reply(rid=rid, qid=qid, uid=replier_uid, body=body, ts=ts, parent_rid=parent_rid, child_rids=child_rids, is_staff=is_staff, display_name=gen_display_name(user, data.display_choice)) r.save() update_actions = [ ReplyIdsByQid.rids.set( (ReplyIdsByQid.rids | []).prepend([GenericPointer(ts=ts, id=rid)])) ] ReplyIdsByQid(qid="global").update(actions=update_actions) ReplyIdsByQid(qid=qid).update(actions=update_actions) ReplyIdsByUid(uid=replier_uid).update(actions=update_actions) await email_notify_new_reply(replier_uid, r, q_m.getValue()) return {'reply': r.to_python(), 'submitted': True, 'rid': rid}
def show_comment(tid): form = ReplyForm() if request.method == 'GET': page = request.args.get('page') if not page: page = 1 else: page = int(page) if page == 1: comment = Comment.query.get(tid) else: comment = None title = Comment.query.get(tid).title reply_list = Reply.query.filter_by(tid=tid).order_by( Reply.tid).paginate(page, MAX_REPLY_NUM_ONE_PAGE, False) return render_template('showcomment.html', tid=tid, title=title, comment=comment, page=page, reply_list=reply_list, form=form) else: reply = Reply(tid = tid, userid = current_user.userid, nickname = current_user.nickname, \ content = form.content.data, post_time = get_now_time()) comment = Comment.query.get(tid) comment.re += 1 reply.save() db.session.commit() return redirect(request.referrer)
def reply(obj): user = User.object.get(id = obj[u"user"]) reply = Reply(post_id = obj[u"post"],user_id = user.name,content = obj[u"content"],time = obj[u"time"]) try: reply.save() error = None except(ValueError, IntegrityError) as e: error = str(e) return error
def reply(obj): user = User.object.get(id=obj[u"user"]) reply = Reply(post_id=obj[u"post"], user_id=user.name, content=obj[u"content"], time=obj[u"time"]) try: reply.save() error = None except (ValueError, IntegrityError) as e: error = str(e) return error
def post(self, request, *args, **kwargs): request_id = kwargs['request_id'] request = RequestSend.objects.get(id=request_id) email_to = request.recruiter.user.email subject = " Contact details " message = " contact details of " + request.jobseeker.user.first_name + request.jobseeker.user.last_name + "Email : " + str(request.jobseeker.user.email) + "Mobile:" + str(request.jobseeker.mobile) + "Land Line:" + str(request.jobseeker.land_num) from_email = settings.DEFAULT_FROM_EMAIL reply = Reply() reply.request = request reply.request.is_replied = True request.save() reply.save() send_mail(subject, message, from_email,[email_to]) return HttpResponseRedirect(reverse('request'))
def save(self, user, topic, reply=None): data = self.data content = unicode(data.get('content')) data.update({ 'user_id': user.id, 'topic_id': topic.id, 'content': strip_xss_tags(content) }) if reply: category = 'edit' pre_content = reply.content cur_content = data.get('content') changed = 0 if pre_content != cur_content: diff_content = ghdiff.diff(pre_content, cur_content, css=None) changed = 1 if changed == 1: reply.content = cur_content History(user_id=user.id, content=diff_content, reply_id=reply.id).save() else: return reply else: category = 'create' reply = Reply(**data) return reply.save(category=category)
def comment_reply(request, post_id, comment_id): if request.method == 'GET': reply_text = request.GET['reply_text'] # forbidden_words = Forbidden.objects.all() # # for forbidden_word in forbidden_words: # reply_text = reply_text.replace(forbidden_word.word, ("*" * len(forbidden_word.word))) comment = Comment.objects.get(pk=comment_id) reply = Reply(reply_comment=comment, reply_text=reply_text, reply_user=request.user) reply.save() return HttpResponseRedirect('/ourblog/post/' + post_id) else: return HttpResponse("Request method is not a GET")
def add_comment(request,tid): ''' func add comment ''' content = request.POST.get("rv_comment",'') if content.strip() == '': return redirect("topic",id=tid) ref_user = request.POST.get("ref_user","") ref_content = request.POST.get("ref_content","") all_content = content if ref_user != '' and ref_content != '': all_content = "||"+ref_content+" "+ref_user+""" \n\n %s """%content topic = Topic.objects.get(id=tid) reply = Reply(content=all_content,creator=request.user,topic=topic) reply.save() #we need to update the Topic_reply_amount table topic_reply_amount = Topic_reply_amount.objects.get(topic=topic) topic_reply_amount.amount = F('amount') + 1 topic_reply_amount.save() return redirect("topic",id=tid)
def post_view(request,article_id): try: article = Article.objects.get_article_by_article_id(article_id) except Article.DoesNotExist: raise Http404 form = ReplyForm(request.POST) if not form.is_valid(): return get_view(request,article_id,errors=form.errors) now = timezone.now() reply = Reply( article = article, nickname = form.cleaned_data.get('nickname'), content = form.cleaned_data.get('content'), created = now, ) reply.save() return redirect('/article/%s/#reply' %article.id )
def add_comment(request, tid): ''' func add comment ''' content = request.POST.get("rv_comment", '') if content.strip() == '': return redirect("topic", id=tid) ref_user = request.POST.get("ref_user", "") ref_content = request.POST.get("ref_content", "") all_content = content if ref_user != '' and ref_content != '': all_content = "||" + ref_content + " " + ref_user + """ \n\n %s """ % content topic = Topic.objects.get(id=tid) reply = Reply(content=all_content, creator=request.user, topic=topic) reply.save() #we need to update the Topic_reply_amount table topic_reply_amount = Topic_reply_amount.objects.get(topic=topic) topic_reply_amount.amount = F('amount') + 1 topic_reply_amount.save() return redirect("topic", id=tid)
def save(self, user, topic, reply=None): data = self.data content = unicode(data.get('content')) data.update({'user_id': user.id, 'topic_id': topic.id, 'content': strip_xss_tags(content)}) if reply: category = 'edit' pre_content = reply.content cur_content = data.get('content') changed = 0 if pre_content != cur_content: diff_content = ghdiff.diff(pre_content, cur_content, css=None) changed = 1 if changed == 1: reply.content = cur_content History(user_id=user.id, content=diff_content, reply_id=reply.id).save() else: return reply else: category = 'create' reply = Reply(**data) return reply.save(category=category)