How To Hide A Button And How To Have A New Tab Redirection On It?
I'm working as an intern for a company on GeoNode 2.8. I have to hide the Download Layer
button if the user is not in the permission list. The previous intern made it in an older version of Geonode
by adding a {% get_obj_perms request.user for resource.layer as "perms" %}
before the button display function. But when I add it on my version of GeoNode, it didn't change anything and the button still there.
{% if resource.storeType != "remoteStore" %}
{% get_obj_perms request.user for resource.layer as "layer_perms" %}
<li class="list-group-item">
{% if links or links_download %}
<button class="btn btn-primary btn-md btn-block" data-toggle="modal" data-target="#download-layer">{% trans "Download Layer" %}</button>
{% else %}
{% if request.user.is_authenticated %}
<button class="btn btn-primary btn-md btn-block" id="request-download">{% trans "Request Download" %}</button>
{% endif %}
{% endif %}
</li>
{% endif %}
Second part, I have a button in a navbar with a redirection like this
<li><a target="_blank" rel="nofollow noreferrer" href="{% url "help" %}">{% trans "Help" %}</a></li>
My issue is the next one, how can I have a redirection but in a new tab, I thought I could use target = _blank
but it's django and it doesn't work.
like this:
<li><a target= "_blank" target="_blank" rel="nofollow noreferrer" href="{% url "help" %}">{% trans "Help" %}</a></li>
I think it's something to change in the urls.py
but I'm new in it so I don't know how to add this redirection.
url(r'^help/$',
TemplateView.as_view(template_name='help.html'),
name='help'),
Answer
You have fetched the permissions of the user on the specified object as
{% get_obj_perms request.user for resource.layer as "layer_perms" %}
But you have not used the permissions obtained from this line. So you need to check if the user has a permission (e.g. can_view, can_download, etc.) on the layer object.
You can change your code as so:
{% if resource.storeType != "remoteStore" %}
{% get_obj_perms request.user for resource.layer as "layer_perms" %}
<li class="list-group-item">
{% if links or links_download %}
{% if "can_download" in layer_perms %} # change here, check if user has required permissions
<button class="btn btn-primary btn-md btn-block" data-toggle="modal" data-target="#download-layer">{% trans "Download Layer" %}</button>
{% endif %} # close the condition
{% else %}
{% if request.user.is_authenticated %}
<button class="btn btn-primary btn-md btn-block" id="request-download">{% trans "Request Download" %}</button>
{% endif %}
{% endif %}
</li>
{% endif %}
Make sure you change your code as per your requirement.
For further reference, you can have a look at guardian-template-tags
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module