[PATCH] Show logged-in user's drafts for logged in user

2 views
Skip to first unread message

m...@nysv.org

unread,
Nov 25, 2009, 8:47:59 AM11/25/09
to byteflow...@googlegroups.com
# HG changeset patch
# User Markus Törnqvist <m...@nysv.org>
# Date 1259156866 0
# Branch mjt
# Node ID a924ab1969b1f0a5b37e9ec245016899c388cfd4
# Parent f3f9e490507ea98e5b20ba71ba9d1fa46f88674d
Show logged-in user's drafts for logged in user
while hiding future publications.

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,18 @@

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:
+ # the OR clause includes logged-in user's drafts as well
+ q_lookup = (Q(is_draft=False) | Q(author=request.user))
+ qs = Post.whole_objects.filter(q_lookup)
+ else:
+ qs = Post.objects.all()
+
+ # hide all posts that are not yet published
+ kwargs['queryset'] = qs.exclude(date__gt=dt.now())
+
return object_list(request, *args, **kwargs)


Alexander Solovyov

unread,
Nov 25, 2009, 3:24:27 PM11/25/09
to byteflow...@googlegroups.com
On Wed, Nov 25, 2009 at 3:47 PM, <m...@nysv.org> wrote:
>
> # HG changeset patch
> # User Markus Törnqvist <m...@nysv.org>
> # Date 1259156866 0
> # Branch mjt
> # Node ID a924ab1969b1f0a5b37e9ec245016899c388cfd4
> # Parent  f3f9e490507ea98e5b20ba71ba9d1fa46f88674d
> Show logged-in user's drafts for logged in user
> while hiding future publications.

Thanks, applied and pushed. Still not marked as draft in templates, though. ;-)

--
Alexander

Markus Törnqvist

unread,
Nov 25, 2009, 3:45:44 PM11/25/09
to byteflow...@googlegroups.com
On Wed, Nov 25, 2009 at 10:24:27PM +0200, Alexander Solovyov wrote:
>
>Thanks, applied and pushed. Still not marked as draft in templates, though. ;-)

Like I said, I wouldn't know how to appropriately screw with other people's
templates, IMO it's best people look at their own templates and if they
find it important enough, they'll submit a patch ;)

--
mjt

Alexander Solovyov

unread,
Nov 25, 2009, 3:55:49 PM11/25/09
to byteflow...@googlegroups.com
2009/11/25 Markus Törnqvist <m...@nysv.org>:

Yeah, sure. ;-) Just mentioning.

--
Alexander

Reply all
Reply to author
Forward
0 new messages