def comment_on_photo(request, photo): form = CommentForm(request.POST) if form.is_valid(): comment = Comment(uname=request.user.username, text=form.cleaned_data['comment'], time=timezone.now(), photo=photo) comment.save() return form
def add_comment_ajax(request): """ Add a new comment view """ logger.info('ADD comment called user='******', ip='+str(request.META['REMOTE_ADDR'])) #checking for POST if request.method == 'POST': pk = request.POST["pk"] author = request.user item = get_object_or_404(Image, pk=pk) comment = Comment(image=item) cf = get_comment_form(author, data=request.POST, instance=comment) if cf.is_valid(): #actions for valid comment and captcha comment = cf.save(commit=False) item.last_commented = datetime.datetime.now() item.save() if author.is_authenticated(): comment.author=author comment.save() comment.data_id = pk comment.permited = unicode('permit') logger.info('ADD comment called user='******', ip='+str(request.META['REMOTE_ADDR'])+', comment='+str(comment.body)) if notification: notification.send([item.user], "c_add", {"ph_title":item.title, "notice":comment.body}) return render_to_response("comments/single_comment.html", {"comment": comment, "pk": comment.pk}, context_instance=RequestContext(request)) else: #form unvalid return form with errors return render_to_response("comments/comment_form.html",{"comment_form": cf, "cf_pk": pk,}) else: return render_to_response("comments/comment_form.html",{"comment_form": get_comment_form(request.user)})