Conditionally Show ToolBar?

42 views
Skip to first unread message

Christopher Marshall

unread,
Mar 23, 2016, 5:06:40 PM3/23/16
to django CMS developers
I am sure this is a newbie question.  We are evaluating CMS's and I have been experimenting with django CMS.  I have created a simple template of my own that seems to be working but I haven't been able to figure out part of what I need.
  • If an anonymous or non-privileged user requests a page, the page should be displayed without an traces of the cms toolbar.
  • If an appropriately privileged user is accessing the page that user should be able to edit the page.
If I include {% cms_toolbar %} in the template I get the tool bar all the time and if I take it out the tool bar is shown none of the time.  So how do I make the display conditional on having a logged in user wanting to edit the page? 

thanks,
Chris

Daniele Procida

unread,
Mar 29, 2016, 5:13:09 AM3/29/16
to Django Cms-Developers
On Wed, Mar 23, 2016, Christopher Marshall <cbmam...@gmail.com> wrote:

>If I include {% cms_toolbar %} in the template I get the tool bar all the
>time and if I take it out the tool bar is shown none of the time. So how
>do I make the display conditional on having a logged in user wanting to
>edit the page?

One would expect this to work:

{% if request.user.is_authenticated %}
{% cms_toolbar %}
{% endif %}

though it doesn't. I am not sure why.

Any better suggestions?

Daniele

Jonas Obrist

unread,
Mar 29, 2016, 5:40:34 AM3/29/16
to django CMS developers
The way I solved this in the past was a custom toolbar middleware (subclassing the normal one), overwriting is_cms_request [1] to see if the toolbar should be shown or not (based on user account info)

Jonas

Iacopo Spalletti

unread,
Mar 29, 2016, 8:29:30 AM3/29/16
to django-cms...@googlegroups.com
On 29/03/2016 11:40, Jonas Obrist wrote:
> The way I solved this in the past was a custom toolbar middleware
> (subclassing the normal one), overwriting is_cms_request [1] to see if
> the toolbar should be shown or not (based on user account info)

Likewise.
I subclassed the templatetag for the same reason, but Jonas' solution is
a lot cleaner

>
> Jonas
>
> [1] https://github.com/divio/django-cms/blob/6868946e8867112c5c8db6a80ee6a442eb36fbb1/cms/middleware/toolbar.py#L55
>
> On Tuesday, March 29, 2016 at 6:13:09 PM UTC+9, Daniele Procida wrote:
>
> On Wed, Mar 23, 2016, Christopher Marshall <cbmam...@gmail.com
> <mailto:cbmam...@gmail.com>> wrote:
>
> >If I include {% cms_toolbar %} in the template I get the tool bar
> all the
> >time and if I take it out the tool bar is shown none of the time.
> So how
> >do I make the display conditional on having a logged in user
> wanting to
> >edit the page?
>
> One would expect this to work:
>
> {% if request.user.is_authenticated %}
> {% cms_toolbar %}
> {% endif %}
>
> though it doesn't. I am not sure why.
>
> Any better suggestions?
>
> Daniele
>
> --
> Message URL:
> https://groups.google.com/d/msg/django-cms-developers/topic-id/message-id
> Unsubscribe: send a message to
> django-cms-devel...@googlegroups.com
> ---
> You received this message because you are subscribed to the Google
> Groups "django CMS developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-cms-devel...@googlegroups.com
> <mailto:django-cms-devel...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/django-cms-developers/9dc2fb1f-6aba-4d63-8775-870bc4e99991%40googlegroups.com
> <https://groups.google.com/d/msgid/django-cms-developers/9dc2fb1f-6aba-4d63-8775-870bc4e99991%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
Iacopo Spalletti

Nephila s.a.s. - Firenze
Telefono: +39 055 5357189
Assistenza Tecnica: +39 055 3985730
http://nephila.it
Reply all
Reply to author
Forward
0 new messages