def post(post_id): form = CommentForm() if form.validate_on_submit(): new_comment = Comment() new_comment.name = form.name.data new_comment.text = form.text.data new_comment.post_id = post_id new_comment.date = datetime.datetime.now() db.session.add(new_comment) db.session.commit() post = Post.query.get_or_404(post_id) tags = post.tags comments = post.comments.order_by(Comment.date.desc()).all() recent, top_tags = sidebar_data() return render_template( 'post.html', post=post, tags=tags, comments=comments, recent=recent, top_tags=top_tags, form=form )
def post(post_id): form = CommentForm() if form.validate_on_submit(): new_comment = Comment() new_comment.name = form.name.data new_comment.text = form.text.data new_comment.post_id = post_id new_comment.date = datetime.now() db.session.add(new_comment) db.session.commit() return redirect(url_for('.post', post_id=post_id)) post = Post.query.get_or_404(post_id) # 添加阅读量 post.read = post.read + 1 db.session.add(post) db.session.commit() tags = post.tags comments = post.comments.order_by(Comment.date.desc()).all() # 是否有编辑权限 permission = Permission(UserNeed(post.user.id)) is_edit = permission.can() or admin_permission.can() if g.is_login: form.name.data = current_user.username return render_template('post.html', post=post, tags=tags, is_edit=is_edit, comments=comments, form=form)
def post(post_id): form = CommentForm() if form.validate_on_submit(): new_comment = Comment() new_comment.name = form.name.data new_comment.text = form.text.data new_comment.post_id = post_id new_comment.date = datetime.datetime.now() db.session.add(new_comment) db.session.commit() form.name.data = None form.text.data = None post = Post.query.get_or_404(post_id) tags = post.tags comments = post.comments.order_by(Comment.date.desc()).all() recent, top_tags = sidebar_data() if request.method == 'POST': return redirect(url_for('blog.post', post_id=post_id)) else: return render_template('blog/post.html', post=post, tags=tags, comments=comments, recent=recent, top_tags=top_tags, form=form)
def post(post_id, page=1): form = CommentForm() if request.method == 'POST': if form.validate_on_submit(): comment = Comment() comment.name = form.name.data comment.text = form.text.data comment.post_id = post_id comment.date = datetime.datetime.now() db.session.add(comment) db.session.commit() return redirect(url_for('post', post_id=post.id)) post = Post.query.get_or_404(post_id) tags = post.tags comments = post.comments.order_by(Comment.date.desc() ).paginate(page, 10) recent, top_tags = sidebar_data() return render_template( 'post.html', post=post, tags=tags, comments=comments, recent=recent, top_tags=top_tags, form=form )
def post(post_id): form = CommentForm() if form.validate_on_submit(): new_comment = Comment() new_comment.name = form.name.data new_comment.text = form.text.data new_comment.post_id = post_id new_comment.date = datetime.datetime.now() db.session.add(new_comment) db.session.commit() post = Post.query.get_or_404(post_id) tags = post.tags comments = post.comments.order_by(Comment.date.desc()).all() recent, top_tags = sidebar_data() return render_template('post.html', post=post, tags=tags, comments=comments, recent=recent, top_tags=top_tags, form=form)
def post_comment(request): form = CommentForm(request.POST) if form.is_valid(): if form.cleaned_data['answer_to']: answer_to = form.cleaned_data['answer_to'] content_id = None else: answer_to = None content_id = form.cleaned_data['content_id'] if request.user.is_authenticated: new_comment = Comment(author_user=request.user, passed=True, text=form.cleaned_data['text'], answer_to_id=answer_to, content_id=content_id) else: new_comment = Comment(author_name=form.cleaned_data['author_name'], text=form.cleaned_data['text'], answer_to_id=answer_to, content_id=content_id) if Settings.objects.get(id=1).comments_manual_valuation == 0: new_comment.passed = 1 new_comment.save() return HttpResponse(content=serializers.serialize( 'json', [Comment.objects.get(id=new_comment.id)], use_natural_foreign_keys=True, use_natural_primary_keys=True), status=201, content_type='application/json') else: return HttpResponse(status=400)
def add_comment_to_post(request, pk): photo = Photos.objects.get(pk=pk) puser = Photos.objects.only('author').get(pk=pk) print(puser) if request.user.is_authenticated: user = User.objects.get(username=request.user) if request.method == "POST": form = LoggedInCommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.picture = photo comment.author = user comment.save() return HttpResponseRedirect('') else: form = LoggedInCommentForm() args = {'form': form, 'puser': puser, 'user': user} return render(request, 'add_comment_to_post.html', args) else: if request.method == "POST": form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.picture = photo comment.save() return HttpResponseRedirect('') else: form = CommentForm() return render(request, 'add_comment_to_post.html', {'form': form}) form = CommentForm() return render(request, 'add_comment_to_post.html', {'form': form})
def post(self, request, *args, **kwargs): form = CommentForm(data=request.POST) if form.is_valid(): Comment.objects.create( article=form.cleaned_data['article'], author=form.cleaned_data['author'], text=form.cleaned_data['text'] ) return redirect('comment_view') else: return render(request, 'comment_create_view.html', context={'form': form})
def post(self, request, *args, **kwargs): comment = get_object_or_404(Comment, pk=kwargs.get('pk')) form = CommentForm(data=request.POST) if form.is_valid(): comment.author = form.cleaned_data['author'] comment.text = form.cleaned_data['text'] comment.article = form.cleaned_data['article'] comment.save() return redirect('comment_view') else: return render(request, 'comment/comment_update.html', context={'form': form, 'comment': comment})
def post(self, request, **kwargs): comments = get_object_or_404(Comment, pk=kwargs['pk']) form = CommentForm(data=request.POST) if form.is_valid(): data = form.cleaned_data comments.author = data['author'] comments.text = data['text'] comments.article = data['article'] comments.save() return redirect('comment_view', pk=comments.pk) else: return render(request, 'comment/update.html', context={'form': form})
def post(self, request, *args, **kwargs): form = CommentForm(data=request.POST) if form.is_valid(): comment = Comment.objects.create( author=form.cleaned_data['author'], text=form.cleaned_data['text'], article=form.cleaned_data['article'], ) return redirect('comment_index', pk=comment.article.pk) else: return render(request, 'comment/create.html', context={'form': form})
def get_post(post_id): form = CommentForm() post = Post.query.get_or_404(post_id) if g.current_user and form.validate_on_submit(): comment = Comment(form.text.data) comment.post_id = post_id comment.user_id = g.current_user.id comment.date = datetime.datetime.now() db.session.add(comment) db.session.commit() form.text.data = "" return render_template('post.html', post=post, form=form)
def post(self, request, *args, **kwargs): comment = get_object_or_404(Comment, pk=kwargs['pk']) form = CommentForm(data=request.POST) if form.is_valid(): Comment.objects.create(author=form.cleaned_data['author'], text=form.cleaned_data['text'], article=form.cleaned_data['article']) return redirect('comment_index') else: return render(request, 'comment/update.html', context={ 'form': form, 'comment': comment })
def reviewer_profile_comment(request, class_num, sub, topics, id): """ Arguments: `request`: Request from user. `class_num`: Class in which the contributor has contributed. `sub`: Subject in which the contributor has contributed. `topics`: Topic on which reviewer commented. `id`: Id of the reviewer. This function takes the request of user and directs it to the profile page which consists of the contributor's contributions in a specific subject of a specific class. """ context = RequestContext(request) comment = Comment.objects.filter(subject_id=id).order_by('-submit_date') reviewer = Reviewer.objects.get(user=request.user) if request.method == 'POST': print "we have a new comment" comment_form = CommentForm(data=request.POST) if comment_form.is_valid(): comments = comment_form.save(commit=False) subject = Subject.objects.get(pk=id) comments.subject = subject comments.user = reviewer comments.save() url = reverse('webapp.views.reviewer_profile_comment', kwargs={ 'class_num': class_num, 'sub': sub, 'topics': topics, 'id': id} ) return HttpResponseRedirect(url) else: if comment_form.errors: print comment_form.errors else: comment_form = CommentForm() context_dict = { 'comment_form': comment_form, 'comment': comment, 'reviewer': reviewer, } return render_to_response("reviewer_comment.html", context_dict, context)
def get(self, request, *args, **kwargs): comment = get_object_or_404(Comment, pk=kwargs.get('pk')) form = CommentForm(data={ 'author': comment.author, 'text': comment.text, # 'article': comment.article }) return render(request, 'comment/comment_update.html', context={'form': form, 'comment': comment})
def get(self, request, *args, **kwargs): article_pk = kwargs.get('pk') article = get_object_or_404(Article, pk=article_pk) form = CommentForm(initial={ 'article': article.title, 'author': 'Anonym' }) return render(request, 'comment/create.html', context={'form': form})
def get(self, request, *args, **kwargs): article = get_object_or_404(Comment, pk=kwargs['pk']) form = CommentForm(data={ 'article': article.article, 'author': article.author, 'text': article.text }) return render(request, 'comment_update_view.html', context={'form': form, 'comment': article})
def post(post_id): form = CommentForm() post = Post.objects(id=post_id).get_or_404() if form.validate_on_submit(): new_comment = Comment() new_comment.name = form.name.data new_comment.text = form.text.data new_comment.date = datetime.datetime.now() post.comments.append(new_comment) post.save() tags = post.tags comments = post.comments return with_sidebar_render('post.html', post=post, tags=tags, comments=comments, form=form)
def reviewer_profile_comment(request, class_num, sub, topics, id): context = RequestContext(request) comment = Comment.objects.filter(subject_id=id) reviewer = Reviewer.objects.get(user=request.user) if request.method == 'POST': print "we have a new comment" comment_form = CommentForm(data=request.POST) if comment_form.is_valid(): comments = comment_form.save(commit=False) subject = Subject.objects.get(pk=id) comments.subject = subject comments.user = reviewer comments.save() url = reverse('webapp.views.reviewer_profile_comment', kwargs={ 'class_num': class_num, 'sub': sub, 'topics': topics, 'id': id }) return HttpResponseRedirect(url) # return HttpResponseRedirect(reverse('/reviewer/profile/comments/%s/%s/' % sub_id % rev_id)) else: if comment_form.errors: print comment_form.errors else: comment_form = CommentForm() context_dict = { 'comment_form': comment_form, 'comment': comment, 'reviewer': reviewer } return render_to_response("reviewer_comment.html", context_dict, context)
def reviewer_profile_comment(request,class_num,sub,topics,id): context = RequestContext(request) comment = Comment.objects.filter(subject_id = id) reviewer = Reviewer.objects.get(user = request.user) if request.method == 'POST': print "we have a new comment" comment_form = CommentForm(data = request.POST) if comment_form.is_valid(): comments = comment_form.save(commit=False) subject = Subject.objects.get(pk = id) comments.subject = subject comments.user = reviewer comments.save() url = reverse('webapp.views.reviewer_profile_comment', kwargs={'class_num' : class_num ,'sub':sub,'topics':topics,'id':id}) return HttpResponseRedirect(url) # return HttpResponseRedirect(reverse('/reviewer/profile/comments/%s/%s/' % sub_id % rev_id)) else: if comment_form.errors: print comment_form.errors else: comment_form = CommentForm() context_dict = {'comment_form': comment_form, 'comment' : comment,'reviewer':reviewer} return render_to_response("reviewer_comment.html",context_dict,context)
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) article_pk = kwargs.get('pk') article = get_object_or_404(Article, pk=article_pk) context['article'] = article context['form'] = CommentForm() comments = article.comments.order_by('-created_at') paginator = Paginator(comments, 3, 0) page_numder = self.request.GET.get('page', 1) page = paginator.get_page(page_numder) context['paginator'] = paginator context['page_obj'] = page context['comments'] = page.object_list context['is_paginated'] = page.has_other_pages() return context
def reviewer_profile_comment(request, class_num, sub, topics, id): """ Arguments: `request`: Request from user. `class_num`: Class in which the contributor has contributed. `sub`: Subject in which the contributor has contributed. `topics`: Topic on which reviewer commented. `id`: Id of the reviewer. This function takes the request of user and directs it to the profile page which consists of the contributor's contributions in a specific subject of a specific class. """ context = RequestContext(request) comment = Comment.objects.filter(subject_id=id).order_by('-submit_date') reviewer = Reviewer.objects.get(user=request.user) if request.method == 'POST': print "we have a new comment" comment_form = CommentForm(data=request.POST) if comment_form.is_valid(): comments = comment_form.save(commit=False) subject = Subject.objects.get(pk=id) comments.subject = subject comments.user = reviewer comments.save() url = reverse('webapp.views.reviewer_profile_comment', kwargs={ 'class_num': class_num, 'sub': sub, 'topics': topics, 'id': id }) return HttpResponseRedirect(url) else: if comment_form.errors: print comment_form.errors else: comment_form = CommentForm() context_dict = { 'comment_form': comment_form, 'comment': comment, 'reviewer': reviewer, } return render_to_response("reviewer_comment.html", context_dict, context)
def website_detail(request, website_slug): website = RatingWebsite.objects.get(slug=website_slug) ratings = Rating.objects.filter(website=website).order_by('-published')[:5] comments = Comment.objects.filter(website=website).order_by('-published') current_rating = 0 if request.user.is_authenticated: # try to get the instance of user's rating for this website try: current_rating = Rating.objects.get(user=request.user, website=website).rating except Rating.DoesNotExist: pass if request.method == 'POST' and request.user.is_authenticated: comment_form = CommentForm(request.POST) if comment_form.is_valid(): comment = comment_form.save(commit=False) comment.user = request.user comment.website = website comment.save() messages.success(request, 'Comment saved.') return redirect('website_detail', website_slug) elif request.user.is_authenticated: comment_form = CommentForm() else: comment_form = None context_dict = { 'website': website, 'ratings': ratings, 'comments': comments, 'current_rating': current_rating, 'comment_form': comment_form } return render(request, 'webapp/website_details.html', context_dict)
def get(self, request, *args, **kwargs): form = CommentForm() return render(request, 'comment/create.html', context={'form': form})
def event(request, event_name): context_dict = {} try: l = visits[event] except: l = [] try: event = Event.objects.get(slug=event_name) except: event = None if request.method == 'POST': profile = UserProfile.objects.get(user=request.user) try: fan = FanProfile.objects.get(profile=profile) except: pass if 'achievement' in request.POST: try: name = '+25xp for going to a gig %s' % event.name achievement = Achievement.objects.create(fan=fan, name=name) fan.xp += 25 fan.save() visits[event] = l + [request.user] except: pass else: comment_form = None try: comment_form = CommentForm(data=request.POST) except: pass if comment_form: comment = comment_form.save(commit=False) comment.event = event comment.user = profile comment.save() try: name = '+10xp for writing a comment about a gig %s' % event.name achievement = Achievement.objects.create(fan=fan, name=name) fan.xp += 10 fan.save() except: pass if event: event.views += 1 event.save() try: comments = Comment.objects.filter(event=event).order_by('date') context_dict['comments'] = comments except: pass context_dict['event'] = event else: return HttpResponseRedirect('/create_event/') try: context_dict['visited'] = visits[event] except: pass return render(request, 'webapp/event.html', context_dict)
def get(self, request, *args, **kwargs): if request.method == 'GET': form = CommentForm() return render(request, 'comments/comment_create.html', context={'form': form})