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)
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
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
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
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