templates: add in-context edition links

This commit is contained in:
Chris Tactic 2024-01-22 07:03:18 +01:00
parent 6d556fcd5d
commit 89f80ad103
3 changed files with 26 additions and 0 deletions

View File

@ -113,6 +113,7 @@ Usefull context:
{% block headings %} {% block headings %}
<div> <div>
<h1 class="title is-1 {% block title-class %}{% endblock %}">{% block title %}{{ title|default:"" }}{% endblock %}</h1> <h1 class="title is-1 {% block title-class %}{% endblock %}">{% block title %}{{ title|default:"" }}{% endblock %}</h1>
{% include "aircox/edit-link.html" %}
</div> </div>
<div> <div>
{% spaceless %} {% spaceless %}

View File

@ -0,0 +1,20 @@
{% load aircox i18n %}
{% block user-actions-container %}
{% has_perm page page.program.change_permission_codename simple=True as can_edit %}
{% if user.is_authenticated and can_edit %}
{% with request.resolver_match.view_name as view_name %}
&nbsp;
{% if view_name in 'program-edit,bla' %}
<!--
<a href="{% url 'program-detail' page.slug %}" target="_self">
<span title="{% translate 'View' %} {{ page }}">{% translate 'View' %} 👁 </span>
</a>
-->
{% else %}
<a href="{% url view_name|edit_view page.pk %}" target="_self">
<span title="{% translate 'Edit' %} {{ page }}">{% translate 'Edit' %} 🖉 </span>
</a>
{% endif %}
{% endwith %}
{% endif %}
{% endblock %}

View File

@ -136,3 +136,8 @@ def do_verbose_name(obj, plural=False):
if isinstance(obj, str): if isinstance(obj, str):
return obj return obj
return obj._meta.verbose_name_plural if plural else obj._meta.verbose_name return obj._meta.verbose_name_plural if plural else obj._meta.verbose_name
@register.filter(name="edit_view")
def do_edit_view(obj):
return "%s-edit" % obj.split("-")[0]