-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(apis_entities): replace custom permission name logic
Concating the permission in the template is cumbersome to read and prone to errors. Therefore we implemented methods on the model instances for most of the permissions and use them now in the templates.
- Loading branch information
Showing
2 changed files
with
50 additions
and
65 deletions.
There are no files selected for viewing
67 changes: 29 additions & 38 deletions
67
apis_core/apis_entities/templates/apis_entities/partials/entity_actions_nav.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,39 @@ | ||
{% load apiscore %} | ||
|
||
{% block action-nav %} | ||
{% with object|opts as opts %} | ||
{% with opts.object_name|lower as modelname %} | ||
{% with opts.app_label|add:"."|add:modelname|add:"_create" as object_create_perm %} | ||
{% with opts.app_label|add:"."|add:modelname|add:"_delete" as object_delete_perm %} | ||
|
||
{% if object_delete_perm in perms or object_create_perm in perms %} | ||
<ul class="nav nav-tabs card-header-tabs float-right"> | ||
<li class="nav-item"> | ||
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">Actions</a> | ||
<div class="dropdown-menu"> | ||
{% if object.get_delete_permission in perms or object_create_perm in perms %} | ||
<ul class="nav nav-tabs card-header-tabs float-right"> | ||
<li class="nav-item"> | ||
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">Actions</a> | ||
<div class="dropdown-menu"> | ||
|
||
{% if object_delete_perm in perms %} | ||
<a class="dropdown-item text-danger" | ||
href="{% url "apis_core:apis_entities:generic_entities_delete_view" modelname object.id %}"> | ||
<span class="material-symbols-outlined material-symbols-align">delete</span> Delete | ||
</a> | ||
{% endif %} | ||
|
||
{% if object_create_perm in perms %} | ||
<a class="dropdown-item" | ||
style="color: blueviolet" | ||
href="{% url "apis_core:apis_entities:generic_entities_duplicate_view" modelname object.id %}"> | ||
<span class="material-symbols-outlined material-symbols-align">content_copy</span> Duplicate | ||
</a> | ||
<a class="dropdown-item" | ||
style="color: dodgerblue" | ||
href="{% url "apis_core:apis_entities:generic_entities_merge_view" modelname object.id %}"> | ||
<span class="material-symbols-outlined material-symbols-align">cell_merge</span> Merge | ||
</a> | ||
{% if object.get_delete_permission in perms %} | ||
<a class="dropdown-item text-danger" href="{{ object.get_delete_url }}"> | ||
<span class="material-symbols-outlined material-symbols-align">delete</span> Delete | ||
</a> | ||
{% endif %} | ||
|
||
{% if object.history %} | ||
<a class="dropdown-item" href="{{ object.get_create_version_url }}"><span class="material-symbols-outlined material-symbols-align">add</span>Add Versiontag</a> | ||
{% endif %} | ||
{% endif %} | ||
{% if object.get_add_permission in perms %} | ||
<a class="dropdown-item" | ||
style="color: blueviolet" | ||
href="{{ object.get_duplciate_url }}"> | ||
<span class="material-symbols-outlined material-symbols-align">content_copy</span> Duplicate | ||
</a> | ||
<a class="dropdown-item" | ||
style="color: dodgerblue" | ||
href="{{ object.get_merge_url }}"> | ||
<span class="material-symbols-outlined material-symbols-align">cell_merge</span> Merge | ||
</a> | ||
{% endif %} | ||
|
||
</div> | ||
</li> | ||
</ul> | ||
{% if object.history %} | ||
<a class="dropdown-item" href="{{ object.get_create_version_url }}"><span class="material-symbols-outlined material-symbols-align">add</span>Add Versiontag</a> | ||
{% endif %} | ||
|
||
{% endwith %} | ||
{% endwith %} | ||
{% endwith %} | ||
{% endwith %} | ||
</div> | ||
</li> | ||
</ul> | ||
{% endif %} | ||
|
||
{% endblock action-nav %} |
48 changes: 21 additions & 27 deletions
48
apis_core/apis_entities/templates/apis_entities/partials/entity_base_nav.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,29 @@ | ||
{% load apiscore %} | ||
|
||
{% block base-nav %} | ||
{% with object|opts as opts %} | ||
{% with opts.object_name|lower as modelname %} | ||
{% with opts.app_label|add:"."|add:modelname|add:"_change" as object_change_perm %} | ||
|
||
{% if object_change_perm in perms %} | ||
<ul class="nav nav-tabs card-header-tabs float-left"> | ||
<li class="nav-item"> | ||
<a class="nav-link text-success | ||
{% if request.path == object.get_absolute_url %}active{% endif %} | ||
" href="{{ object.get_absolute_url }}"><span class="material-symbols-outlined material-symbols-align">visibility</span>View</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link text-warning | ||
{% if request.path == object.get_edit_url %}active{% endif %} | ||
" href="{{ object.get_edit_url }}"><span class="material-symbols-outlined material-symbols-align">edit</span>Edit</a> | ||
</li> | ||
{% if object.get_change_permission in perms %} | ||
<ul class="nav nav-tabs card-header-tabs float-left"> | ||
<li class="nav-item"> | ||
<a class="nav-link text-success | ||
{% if request.path == object.get_absolute_url %}active{% endif %} | ||
" href="{{ object.get_absolute_url }}"><span class="material-symbols-outlined material-symbols-align">visibility</span>View</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link text-warning | ||
{% if request.path == object.get_edit_url %}active{% endif %} | ||
" href="{{ object.get_edit_url }}"><span class="material-symbols-outlined material-symbols-align">edit</span>Edit</a> | ||
</li> | ||
|
||
{% if object.history %} | ||
<li class="nav-item"> | ||
<a class="nav-link | ||
{% if request.path == object.get_history_url %}active{% endif %} | ||
" style="color: #007bff" href="{{ object.get_history_url }}"><span class="material-symbols-outlined material-symbols-align">history</span>View History</a> | ||
</li> | ||
{% endif %} | ||
{% if object.history %} | ||
<li class="nav-item"> | ||
<a class="nav-link | ||
{% if request.path == object.get_history_url %}active{% endif %} | ||
" style="color: #007bff" href="{{ object.get_history_url }}"><span class="material-symbols-outlined material-symbols-align">history</span>View History</a> | ||
</li> | ||
{% endif %} | ||
|
||
</ul> | ||
{% endif %} | ||
</ul> | ||
{% endif %} | ||
|
||
{% endwith %} | ||
{% endwith %} | ||
{% endwith %} | ||
{% endblock base-nav %} |