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 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 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 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 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 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 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)