def edit_comment(request, comment_id): comment = get_object_or_404(EventComment, id=comment_id) if ( not request.user.profile.can_edit_event(comment.event) and request.user.profile.id != comment.author.id ): messages.add_message( request, messages.WARNING, message=_("You can not edit a comment that is not yours."), ) return redirect(comment.event.get_absolute_url()) if request.method == "POST": comment_form = EventCommentForm(request.POST, instance=comment) if comment_form.is_valid(): comment_form.save() return redirect( comment.event.get_absolute_url() + "#comment-%s" % comment.id ) else: messages.add_message( request, messages.ERROR, message=_("Error updating comment.") ) return redirect(comment.event.get_absolute_url())
def comment_event(request, event_id): event = Event.objects.get(id=event_id) if request.user.is_anonymous: messages.add_message(request, messages.WARNING, message=_("You must be logged in to comment.")) return redirect(event.get_absolute_url()) if request.method == 'POST': new_comment = EventComment(author=request.user.profile, event=event) comment_form = EventCommentForm(request.POST, instance=new_comment) if comment_form.is_valid(): new_comment = comment_form.save() send_comment_emails(new_comment) return redirect(event.get_absolute_url()+'#comment-%s'%new_comment.id) return redirect(event.get_absolute_url())