[PATCH] Show drafts for logged-in user if logged in

3 views
Skip to first unread message

m...@nysv.org

unread,
Nov 23, 2009, 5:30:06 AM11/23/09
to byteflow...@googlegroups.com, m...@nysv.org
# HG changeset patch
# User Markus Törnqvist <m...@nysv.org>
# Date 1258972156 0
# Branch mjt
# Node ID 3726ed038850425dd9fc1856da95359b807f8e98
# Parent f3f9e490507ea98e5b20ba71ba9d1fa46f88674d
Show drafts for logged-in user if logged in

diff --git a/apps/blog/views.py b/apps/blog/views.py
--- a/apps/blog/views.py
+++ b/apps/blog/views.py
@@ -26,6 +26,8 @@
from tagging.views import tagged_object_list
from render import render

+from django.db.models import Q
+
def _get_reply_to(request):
try:
return int(request.GET.get('reply_to', None))
@@ -35,7 +37,13 @@

def post_list(request, *args, **kwargs):
"""Post listing. Only shows posts that are older than now()"""
- kwargs['queryset'] = Post.objects.exclude(date__gt=dt.now())
+
+ if request.user.id:
+ q_lookup = (Q(is_draft=False) | Q(author=request.user) & Q(is_draft=True))
+ kwargs['queryset'] = Post.whole_objects.filter(q_lookup)
+ else:
+ kwargs['queryset'] = Post.objects.exclude(date__gt=dt.now())
+
return object_list(request, *args, **kwargs)


Yuri Baburov

unread,
Nov 23, 2009, 5:41:00 AM11/23/09
to byteflow...@googlegroups.com, m...@nysv.org
Hi Marcus,

I believe this patch should imply changes in themes templates to show
which posts are drafts? Maybe, with "[draft]" in title or some icon..

--
Best regards, Yuri V. Baburov, ICQ# 99934676, Skype: yuri.baburov,
MSN: bu...@live.com

Stephan Jaensch

unread,
Nov 23, 2009, 5:41:52 AM11/23/09
to byteflow...@googlegroups.com
Hi,

Am 23.11.2009 um 11:30 schrieb m...@nysv.org:

> def post_list(request, *args, **kwargs):
> """Post listing. Only shows posts that are older than now()"""
> - kwargs['queryset'] = Post.objects.exclude(date__gt=dt.now())
> +
> + if request.user.id:
> + q_lookup = (Q(is_draft=False) | Q(author=request.user) & Q(is_draft=True))
> + kwargs['queryset'] = Post.whole_objects.filter(q_lookup)
> + else:
> + kwargs['queryset'] = Post.objects.exclude(date__gt=dt.now())
> +
> return object_list(request, *args, **kwargs)

The "& Q(is_draft=True)" is unnecessary, isn't it? Plus, if I read the patch correctly, it shows future (not yet published) entries to logged-in users (Post.objects.exclude(date__gt=dt.now()) is only done for non-logged-in users).

Cheers,
Stephan

Markus Törnqvist

unread,
Nov 23, 2009, 5:47:04 AM11/23/09
to byteflow...@googlegroups.com
>On Mon, Nov 23, 2009 at 4:30 PM, <m...@nysv.org> wrote:
>> # Node ID 3726ed038850425dd9fc1856da95359b807f8e98

>> Show drafts for logged-in user if logged in

On Mon, Nov 23, 2009 at 04:41:00PM +0600, Yuri Baburov wrote:
>I believe this patch should imply changes in themes templates to show
>which posts are drafts? Maybe, with "[draft]" in title or some icon..

Hehe, that's what I thought too, but IMO those are separate patches.

And I don't use a regular theme so I don't know about modifying those;
do they have maintainers who can decide if they want to have it or not?

Anyway, that patching should be fairly easy:
{% if object.is_draft %}
DRAFT:
{% endif %}
{{ object.name }}

Or somesuch.

I found this useful even without changing my theme :)

Spasibo!

--
mjt

Markus Törnqvist

unread,
Nov 23, 2009, 6:19:10 AM11/23/09
to byteflow...@googlegroups.com
On Mon, Nov 23, 2009 at 11:41:52AM +0100, Stephan Jaensch wrote:
>
>The "& Q(is_draft=True)" is unnecessary, isn't it? Plus, if I read the patch

You're right, I guess I was just wrapping my head implicitly around the
syntax or something :)

>correctly, it shows future (not yet published) entries to logged-in users
>(Post.objects.exclude(date__gt=dt.now()) is only done for non-logged-in
>users).

And that was me being plain stupid :)

I submitted another take on it, one that hides the future messages
and makes the query a bit slimmer.

Thanks!

--
mjt

Reply all
Reply to author
Forward
0 new messages