Skip to content

Commit 945ce5f

Browse files
committed
Fixed the breadcrumbs in modern Django, added object_history template
1 parent 5aaf6f1 commit 945ce5f

File tree

7 files changed

+74
-21
lines changed

7 files changed

+74
-21
lines changed

polymorphic_tree/admin/childadmin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@ def delete_confirmation_template(self):
3434
templates = super(PolymorphicMPTTChildModelAdmin, self).delete_confirmation_template
3535
templates.insert(-2, "admin/polymorphic_tree/delete_confirmation.html")
3636
return templates
37+
38+
@property
39+
def object_history_template(self):
40+
# Insert template before default admin/polymorphic to have the tree in the breadcrumb
41+
templates = super(PolymorphicMPTTChildModelAdmin, self).object_history_template
42+
if isinstance(templates, list): # allow pre django-polymorphic 0.9.1 to work without errors.
43+
templates.insert(-2, "admin/polymorphic_tree/object_history.html")
44+
return templates
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
11
{% extends "admin/change_form.html" %}
2-
{% load i18n admin_modify admin_urls polymorphic_admin_tags polymorphic_tree_admin_tags %}
32

4-
{# Add tree levels to polymorphic breadcrumb #}
5-
{% block breadcrumbs %}{% if not is_popup %}{% breadcrumb_scope base_opts %}
6-
<div class="breadcrumbs">
7-
<a href="{% url 'admin:index' %}">{% trans "Home" %}</a> &rsaquo;
8-
<a href="{% url 'admin:app_list' app_label=app_label %}">{{ app_label|capfirst|escape }}</a> &rsaquo;
9-
{% if has_change_permission %}<a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo;
10-
{% for p in original|mptt_breadcrumb %}
11-
<a href="{% url opts|admin_urlname:'change' p.id %}">{{ p.title }}</a> &rsaquo;
12-
{% endfor %}
13-
{% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
14-
</div>
15-
{% endbreadcrumb_scope %}{% endif %}{% endblock %}
3+
{% block breadcrumbs %}{% if not is_popup %}{% include "admin/polymorphic_tree/change_form_breadcrumbs.html" %}{% endif %}{% endblock %}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% load i18n admin_urls polymorphic_admin_tags polymorphic_tree_admin_tags %}
2+
3+
{% breadcrumb_scope base_opts %}
4+
<div class="breadcrumbs">
5+
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
6+
{% if opts.app_config %}{# Django 1.7+ #}
7+
&rsaquo; <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a>
8+
&rsaquo; {% if has_change_permission %}<a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %}
9+
{% else %}
10+
&rsaquo; <a href="{% url 'admin:app_list' app_label=app_label %}">{{ app_label|capfirst|escape }}</a>
11+
&rsaquo; {% if has_change_permission %}<a href="{% url opts|admin_urlname:'changelist' %}">{{ module_name }}</a>{% else %}{{ module_name }}{% endif %}
12+
{% endif %}
13+
14+
{# Add tree levels to polymorphic breadcrumb #}
15+
{% for parent in original|mptt_breadcrumb %}
16+
&rsaquo; <a href="{% url opts|admin_urlname:'change' parent.pk|admin_urlquote %}">{{ parent }}</a>
17+
{% endfor %}
18+
19+
&rsaquo; {% if add %}{% trans 'Add' %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
20+
</div>
21+
{% endbreadcrumb_scope %}

polymorphic_tree/templates/admin/polymorphic_tree/delete_confirmation.html

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
{# Add tree levels to polymorphic breadcrumb #}
55
{% block breadcrumbs %}{% breadcrumb_scope base_opts %}
66
<div class="breadcrumbs">
7-
<a href="{% url 'admin:index' %}">{% trans "Home" %}</a> &rsaquo;
8-
<a href="{% url 'admin:app_list' app_label=app_label %}">{{ app_label|capfirst|escape }}</a> &rsaquo;
9-
<a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
10-
{% for p in object|mptt_breadcrumb %}
11-
<a href="{% url opts|admin_urlname:'change' p.id %}">{{ p.title }}</a> &rsaquo;
7+
<a href="{% url 'admin:index' %}">{% trans "Home" %}</a>
8+
{% if opts.app_config %}{# Django 1.7+ #}
9+
&rsaquo; <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a>
10+
{% else %}
11+
&rsaquo; <a href="{% url 'admin:app_list' app_label=app_label %}">{{ app_label|capfirst|escape }}</a>
12+
{% endif %}
13+
&rsaquo; <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
14+
15+
{% for parent in object|mptt_breadcrumb %}
16+
&rsaquo; <a href="{% url opts|admin_urlname:'change' parent.pk|admin_urlquote %}">{{ parent }}</a>
1217
{% endfor %}
13-
<a href="{% url opts|admin_urlname:'change' object.id %}">{{ object|truncatewords:"18" }}</a> &rsaquo;
14-
{% trans 'Delete' %}
18+
19+
&rsaquo; <a href="{% url opts|admin_urlname:'change' object.pk|admin_urlquote %}">{{ object|truncatewords:"18" }}</a>
20+
&rsaquo; {% trans 'Delete' %}
1521
</div>
1622
{% endbreadcrumb_scope %}{% endblock %}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% extends 'admin/object_history.html' %}{% comment %}
2+
3+
This file is selected by default to display polymorphic mptt object history.
4+
When using reversion or reversion-compare, this template could be replaced
5+
with the proper {% extends "reversion/object_history.html" %} template.
6+
Hence, the breadcrumb code is in a separate include file.
7+
8+
{% endcommenr %}
9+
10+
{% block breadcrumbs %}{% include "admin/polymorphic_tree/object_history_breadcrumbs.html" %}{% endblock %}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{% load i18n admin_urls polymorphic_admin_tags polymorphic_tree_admin_tags %}
2+
3+
{% breadcrumb_scope base_opts %}
4+
<div class="breadcrumbs">
5+
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
6+
{% if opts.app_config %}{# Django 1.7+ #}
7+
&rsaquo; <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a>
8+
{% else %}
9+
&rsaquo; <a href="{% url 'admin:app_list' app_label=app_label %}">{{ app_label|capfirst|escape }}</a>
10+
{% endif %}
11+
&rsaquo; <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
12+
13+
{% for parent in object|mptt_breadcrumb %}
14+
&rsaquo; <a href="{% url opts|admin_urlname:'change' parent.pk|admin_urlquote %}">{{ parent }}</a>
15+
{% endfor %}
16+
17+
&rsaquo; <a href="{% url opts|admin_urlname:'change' object.pk|admin_urlquote %}">{{ object|truncatewords:"18" }}</a>
18+
&rsaquo; {% trans 'History' %}
19+
</div>
20+
{% endbreadcrumb_scope %}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def find_version(*parts):
3939
license='Apache 2.0',
4040

4141
install_requires=[
42-
'django-polymorphic>=0.8.1', # ensure Django 1.9 compatibility
42+
'django-polymorphic>=0.9.1', # needed for object_history_template fix
4343
'django-mptt>=0.6.0', # Still allow 0.6 to have Django 1.5 support
4444
'django-tag-parser>=2.1', # ensure Django 1.8 compatibility
4545
'future>=0.12.2',

0 commit comments

Comments
 (0)