Django - how to create a private subpage?

24 views
Skip to first unread message

Petey

unread,
Oct 11, 2011, 1:56:17 PM10/11/11
to django...@googlegroups.com
I am trying to do a private subpage for every user which will be accessed trough url:
    url(r'^galeria/$', 'publisher.views.private_gallery'),

I was trying to create a query set for private gallery by using a signal: user_logged_in

p = Publisher.objects.filter(status='p', pub_type='private_gallery', user_gallery=str(user_logged_in)).order_by('-id')

However, django does not accept signals in querysets.
Could you give me some good hints on making private pages which can be viewed only by Users?

Kurtis Mullins

unread,
Oct 11, 2011, 5:09:11 PM10/11/11
to django...@googlegroups.com
Check out this page: https://docs.djangoproject.com/en/dev/topics/auth/#handling-object-permissions
Also, you may want to check out decorators if the user only has to be logged in. Another method you could use are groups.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/3gwZr3oZjRIJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Victor Hooi

unread,
Oct 11, 2011, 5:16:16 PM10/11/11
to django...@googlegroups.com
heya,

I might be misunderstanding your requriements, but could you use the @user_passes_test decorator with a has_perm check?

@user_passes_test(lambda u: u.has_perm('private_pages.foo'))


You can probably make the lambda a bit smarter, instead of using has_perm, check if the pagename matches the username.

Cheers,
Victor

Matt Schinckel

unread,
Oct 11, 2011, 6:42:48 PM10/11/11
to django...@googlegroups.com
That line (p = ...) is in a view, right?

It will probably want to be:

    p = Publisher.objects.filter(status='p', pub_type='private_gallery', user_gallery=request.user).order_by('-id')

Matt.
Reply all
Reply to author
Forward
0 new messages