Skip to content

Commit

Permalink
fix(generic): hide create button if permission does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Feb 15, 2024
1 parent edb783e commit 154d2dd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions apis_core/generic/templates/generic/generic_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% load render_table from django_tables2 %}
{% load crispy_forms_tags %}
{% load apisgeneric %}
{% load apiscore %}

{% block scripts %}
{{ block.super }}
Expand All @@ -23,8 +24,16 @@
<div class="row">
<div class="col">{{ object_list.model|contenttype }}</div>
<div class="col">
<a class="btn btn-outline-success float-right btn-sm"
href="{% url 'apis_core:generic:create' object_list.model|contenttype %}">Create</a>
{% with object_list.model|opts as opts %}
{% with opts.app_label|add:"."|add:opts.verbose_name|add:"_create" as object_create_perm %}

{% if object_create_perm in perms %}
<a class="btn btn-outline-success float-right btn-sm"
href="{% url 'apis_core:generic:create' object_list.model|contenttype %}">Create</a>
{% endif %}

{% endwith %}
{% endwith %}
</div>
</div>
</div>
Expand Down

0 comments on commit 154d2dd

Please sign in to comment.