Exemple #1
0
def entry_detail(request, date=None, slug=None, permalink=None):
    """Display one entry with the given slug and date.
    """
    if permalink:
        try:
            entry = EntryType.objects(permalink=permalink)[0]
        except IndexError:
            raise Http404
    else:
        try:
            today = datetime.strptime(date, "%Y/%b/%d")
            tomorrow = today + timedelta(days=1)
        except:
            raise Http404

        try:
            entry = EntryType.objects(publish_date__gte=today, 
                                      publish_date__lt=tomorrow, slug=slug)[0]
        except IndexError:
            raise Http404

    # Select correct form for entry type
    form_class = Comment.CommentForm

    if request.method == 'POST':
        form = form_class(request.user, request.POST)
        if form.is_valid():
            # Get necessary post data from the form
            comment = HtmlComment(**form.cleaned_data)
            if request.user.is_authenticated():
                comment.is_admin = True
            # Update entry with comment
            q = EntryType.objects(id=entry.id)
            comment.rendered_content = markup(comment.body, escape=True,
                                              small_headings=True)
            q.update(push__comments=comment)

            return HttpResponseRedirect(entry.get_absolute_url()+'#comments')
    else:
        form = form_class(request.user)

    # Check for comment expiry
    comments_expired = False
    if entry.comments_expiry_date:
        if entry.comments_expiry_date < datetime.now():
            comments_expired = True

    context = {
        'entry': entry,
        'form': form,
        'comments_expired': comments_expired,
    }
    return render_to_response(_lookup_template('entry_detail'), context,
                              context_instance=RequestContext(request))
Exemple #2
0
def entry_detail(request, date, slug):
    """Display one entry with the given slug and date.
    """
    try:
        today = datetime.strptime(date, "%Y/%b/%d")
        tomorrow = today + timedelta(days=1)
    except:
        raise Http404

    try:
        entry = EntryType.objects(publish_date__gte=today,
                                  publish_date__lt=tomorrow,
                                  slug=slug)[0]
    except IndexError:
        raise Http404

    # Select correct form for entry type
    form_class = Comment.CommentForm

    if request.method == 'POST':
        form = form_class(request.user, request.POST)
        if form.is_valid():
            # Get necessary post data from the form
            comment = HtmlComment(**form.cleaned_data)
            if request.user.is_authenticated():
                comment.is_admin = True
            # Update entry with comment
            q = EntryType.objects(id=entry.id)
            comment.rendered_content = markup(comment.body,
                                              escape=True,
                                              small_headings=True)
            q.update(push__comments=comment)

            return HttpResponseRedirect(entry.get_absolute_url() + '#comments')
    else:
        form = form_class(request.user)

    # Check for comment expiry
    comments_expired = False
    if entry.comments_expiry_date:
        if entry.comments_expiry_date < datetime.now():
            comments_expired = True

    context = {
        'entry': entry,
        'form': form,
        'comments_expired': comments_expired,
    }
    return render_to_response(_lookup_template('entry_detail'),
                              context,
                              context_instance=RequestContext(request))
Exemple #3
0
def delete_comment(request):
    """Delete a comment from the database.
    """
    comment_id = request.POST.get("comment_id", None)
    if request.method == "POST" and comment_id:
        # Delete matching comment from entry
        entry = EntryType.objects(comments__id=comment_id).first()
        if entry:
            entry.comments = [c for c in entry.comments if c.id != comment_id]
            entry.save()
        return HttpResponseRedirect(entry.get_absolute_url() + "#comments")
    return HttpResponseRedirect(reverse("recent-entries"))
Exemple #4
0
def delete_comment(request):
    """Delete a comment from the database.
    """
    comment_id = request.POST.get('comment_id', None)
    if request.method == 'POST' and comment_id:
        # Delete matching comment from entry
        entry = EntryType.objects(comments__id=comment_id).first()
        if entry:
            entry.comments = [c for c in entry.comments if c.id != comment_id]
            entry.save()
        return HttpResponseRedirect(entry.get_absolute_url() + '#comments')
    return HttpResponseRedirect(reverse('recent-entries'))
Exemple #5
0
def delete_comment(request):
    """Delete a comment from the database.
    """
    comment_id = request.POST.get('comment_id', None)
    try:
        comment_id = ObjectId(comment_id)
    except InvalidId:
        comment_Id = False

    if request.method == 'POST' and comment_id:
        # Delete matching comment from entry
        entry = EntryType.objects(comments__id=comment_id).first()
        if entry:
            entry.comments = [c for c in entry.comments if c.id != comment_id]
            entry.save()
            return HttpResponseRedirect(entry.get_absolute_url()+'#comments')
    return HttpResponseRedirect(reverse('recent-entries'))