Beispiel #1
0
def reply(request, diary_id):
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            new_comment = form.save(commit=False)
            new_comment.diary = get_object_or_404(Diary, pk=diary_id)
            new_comment.creator = request.user
            new_comment.created = datetime.datetime.now()
            new_comment.save()
            form.save_m2m()
    return HttpResponseRedirect(reverse('diary.views.view_diary',
                                        args=[diary_id]))
Beispiel #2
0
def reply(request, diary_id):
    """Adds a comment to a diary entry where pk=diary_id."""
    entry = get_object_or_404(DiaryEntry, pk=diary_id)
    if entry.creator != request.user and (entry.is_private or entry.is_draft):
        raise PermissionDenied

    form = CommentForm(creator=request.user, diary=entry,
                       data=request.POST)
    if form.is_valid():
        comment = form.save()
        if len(comment.text) >= MIN_COMMENT_LENGTH_MOJO:
            process_mojo_action(request.user, 'diary_comment')
        invalidate_count(entry.comments.all())
        NewCommentEvent.notify(request.user, entry)
        # Send notifications to diary comment watchers.
        NewCommentEvent(comment).fire(exclude=request.user)
        return HttpResponseRedirect(entry.get_absolute_url())

    return single(request, username=entry.creator.username,
                  year=entry.created_day.year, month=entry.created_day.month,
                  day=entry.created_day.day, comment_form=form)