summaryrefslogtreecommitdiff
path: root/tests/admin_views
diff options
context:
space:
mode:
authorRaffaele Salmaso <raffaele@salmaso.org>2017-01-12 17:06:00 +0100
committerCarlton Gibson <carlton.gibson@noumenal.es>2018-02-28 08:49:40 +0100
commit5cc28dc752c3ae78456bb835c3ba195489fc26d7 (patch)
treedabc737b959f842c880d01542e48eb0dfe079cc5 /tests/admin_views
parent6e52e2554dcc902b446f9d371ed1e6a07f36d6ec (diff)
Fixed #27728 -- Allowed overriding admin templatetags templates.
Diffstat (limited to 'tests/admin_views')
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/actions.html6
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/change_form_object_tools.html7
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/change_list_object_tools.html7
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/change_list_results.html38
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/date_hierarchy.html9
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/pagination.html12
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/prepopulated_fields_js.html7
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/search_form.html16
-rw-r--r--tests/admin_views/templates/admin/admin_views/article/submit_line.html7
-rw-r--r--tests/admin_views/test_templatetags.py45
10 files changed, 152 insertions, 2 deletions
diff --git a/tests/admin_views/templates/admin/admin_views/article/actions.html b/tests/admin_views/templates/admin/admin_views/article/actions.html
new file mode 100644
index 0000000000..9aa238fd2a
--- /dev/null
+++ b/tests/admin_views/templates/admin/admin_views/article/actions.html
@@ -0,0 +1,6 @@
+{% extends "admin/actions.html" %}
+{% load i18n %}
+
+{% block actions-submit %}
+<button type="submit" class="button override-actions" title="{% trans "Run the selected action" %}" name="index" value="{{ action_index|default:0 }}">{% trans "Go" %}</button>
+{% endblock %}
diff --git a/tests/admin_views/templates/admin/admin_views/article/change_form_object_tools.html b/tests/admin_views/templates/admin/admin_views/article/change_form_object_tools.html
new file mode 100644
index 0000000000..609974bb95
--- /dev/null
+++ b/tests/admin_views/templates/admin/admin_views/article/change_form_object_tools.html
@@ -0,0 +1,7 @@
+{% extends "admin/change_form_object_tools.html" %}
+{% load i18n admin_urls %}
+
+{% block object-tools-items %}
+<li><a href="#" id="change-form-export" class="override-change_form_object_tools change-form-object-tools-item">{% trans "Export" %}</a></li>
+{{ block.super }}
+{% endblock %}
diff --git a/tests/admin_views/templates/admin/admin_views/article/change_list_object_tools.html b/tests/admin_views/templates/admin/admin_views/article/change_list_object_tools.html
new file mode 100644
index 0000000000..1a9be91952
--- /dev/null
+++ b/tests/admin_views/templates/admin/admin_views/article/change_list_object_tools.html
@@ -0,0 +1,7 @@
+{% extends "admin/change_list_object_tools.html" %}
+{% load i18n admin_urls %}
+
+{% block object-tools-items %}
+<li><a href="#" id="change-list-export" class="override-change_list_object_tools change-list-object-tools-item">{% trans "Export" %}</a></li>
+{{ block.super }}
+{% endblock %}
diff --git a/tests/admin_views/templates/admin/admin_views/article/change_list_results.html b/tests/admin_views/templates/admin/admin_views/article/change_list_results.html
new file mode 100644
index 0000000000..ceb581f8ef
--- /dev/null
+++ b/tests/admin_views/templates/admin/admin_views/article/change_list_results.html
@@ -0,0 +1,38 @@
+{% load i18n static %}
+{% if result_hidden_fields %}
+<div class="hiddenfields">{# DIV for HTML validation #}
+{% for item in result_hidden_fields %}{{ item }}{% endfor %}
+</div>
+{% endif %}
+{% if results %}
+<div class="results override-change_list_results">
+<table id="result_list">
+<thead>
+<tr>
+{% for header in result_headers %}
+<th scope="col" {{ header.class_attrib }}>
+ {% if header.sortable %}
+ {% if header.sort_priority > 0 %}
+ <div class="sortoptions">
+ <a class="sortremove" href="{{ header.url_remove }}" title="{% trans "Remove from sorting" %}"></a>
+ {% if num_sorted_fields > 1 %}<span class="sortpriority" title="{% blocktrans with priority_number=header.sort_priority %}Sorting priority: {{ priority_number }}{% endblocktrans %}">{{ header.sort_priority }}</span>{% endif %}
+ <a href="{{ header.url_toggle }}" class="toggle {% if header.ascending %}ascending{% else %}descending{% endif %}" title="{% trans "Toggle sorting" %}"></a>
+ </div>
+ {% endif %}
+ {% endif %}
+ <div class="text">{% if header.sortable %}<a href="{{ header.url_primary }}">{{ header.text|capfirst }}</a>{% else %}<span>{{ header.text|capfirst }}</span>{% endif %}</div>
+ <div class="clear"></div>
+</th>{% endfor %}
+</tr>
+</thead>
+<tbody>
+{% for result in results %}
+{% if result.form.non_field_errors %}
+ <tr><td colspan="{{ result|length }}">{{ result.form.non_field_errors }}</td></tr>
+{% endif %}
+<tr class="{% cycle 'row1' 'row2' %}">{% for item in result %}{{ item }}{% endfor %}</tr>
+{% endfor %}
+</tbody>
+</table>
+</div>
+{% endif %}
diff --git a/tests/admin_views/templates/admin/admin_views/article/date_hierarchy.html b/tests/admin_views/templates/admin/admin_views/article/date_hierarchy.html
new file mode 100644
index 0000000000..de1cb747b5
--- /dev/null
+++ b/tests/admin_views/templates/admin/admin_views/article/date_hierarchy.html
@@ -0,0 +1,9 @@
+{% extends "admin/date_hierarchy.html" %}
+{% load i18n %}
+
+{% block date-hierarchy-choices %}
+<select id="date-selector" class="override-date_hierarchy">{% for choice in choices %}
+ <option{% if choice.link %} value="{{ choice.link }}"{% endif %}>{{ choice.title }}</option>
+{% endfor %}</select>
+<button id="date-selected">{% trans "Go" %}</button>
+{% endblock %}
diff --git a/tests/admin_views/templates/admin/admin_views/article/pagination.html b/tests/admin_views/templates/admin/admin_views/article/pagination.html
new file mode 100644
index 0000000000..e072cacd3c
--- /dev/null
+++ b/tests/admin_views/templates/admin/admin_views/article/pagination.html
@@ -0,0 +1,12 @@
+{% load admin_list %}
+{% load i18n %}
+<p class="paginator override-pagination">
+{% if pagination_required %}
+{% for i in page_range %}
+ {% paginator_number cl i %}
+{% endfor %}
+{% endif %}
+{{ cl.result_count }} {% if cl.result_count == 1 %}{{ cl.opts.verbose_name }}{% else %}{{ cl.opts.verbose_name_plural }}{% endif %}
+{% if show_all_url %}&nbsp;&nbsp;<a href="{{ show_all_url }}" class="showall">{% trans 'Show all' %}</a>{% endif %}
+{% if cl.formset and cl.result_count %}<input type="submit" name="_save" class="default" value="{% trans 'Save' %}"/>{% endif %}
+</p>
diff --git a/tests/admin_views/templates/admin/admin_views/article/prepopulated_fields_js.html b/tests/admin_views/templates/admin/admin_views/article/prepopulated_fields_js.html
new file mode 100644
index 0000000000..0ee8c7a06c
--- /dev/null
+++ b/tests/admin_views/templates/admin/admin_views/article/prepopulated_fields_js.html
@@ -0,0 +1,7 @@
+{% load l10n static %}
+<script type="text/javascript"
+ id="django-admin-prepopulated-fields-constants"
+ class="override-prepopulated_fields_js"
+ src="{% static "admin/js/prepopulate_init.js" %}"
+ data-prepopulated-fields="{{ prepopulated_fields_json }}">
+</script>
diff --git a/tests/admin_views/templates/admin/admin_views/article/search_form.html b/tests/admin_views/templates/admin/admin_views/article/search_form.html
new file mode 100644
index 0000000000..5b5e6a58f6
--- /dev/null
+++ b/tests/admin_views/templates/admin/admin_views/article/search_form.html
@@ -0,0 +1,16 @@
+{% load i18n static %}
+{% if cl.search_fields %}
+<div id="toolbar" class="override-search_form"><form id="changelist-search" method="get">
+<div><!-- DIV needed for valid HTML -->
+<label for="searchbar"><img src="{% static "admin/img/search.svg" %}" alt="Search" /></label>
+<input type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" autofocus />
+<input type="submit" value="{% trans 'Search' %}" />
+{% if show_result_count %}
+ <span class="small quiet">{% blocktrans count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }} results{% endblocktrans %} (<a href="?{% if cl.is_popup %}_popup=1{% endif %}">{% if cl.show_full_result_count %}{% blocktrans with full_result_count=cl.full_result_count %}{{ full_result_count }} total{% endblocktrans %}{% else %}{% trans "Show all" %}{% endif %}</a>)</span>
+{% endif %}
+{% for pair in cl.params.items %}
+ {% if pair.0 != search_var %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}"/>{% endif %}
+{% endfor %}
+</div>
+</form></div>
+{% endif %}
diff --git a/tests/admin_views/templates/admin/admin_views/article/submit_line.html b/tests/admin_views/templates/admin/admin_views/article/submit_line.html
new file mode 100644
index 0000000000..4a2ca08890
--- /dev/null
+++ b/tests/admin_views/templates/admin/admin_views/article/submit_line.html
@@ -0,0 +1,7 @@
+{% extends "admin/submit_line.html" %}
+{% load i18n admin_urls %}
+
+{% block submit-row %}
+{% if show_publish %}<input type="submit" value="{% trans 'Publish' %}" class="default" name="_publish" />{% endif %}
+{{ block.super }}
+{% endblock %}
diff --git a/tests/admin_views/test_templatetags.py b/tests/admin_views/test_templatetags.py
index 44a08f32cd..db78636d5d 100644
--- a/tests/admin_views/test_templatetags.py
+++ b/tests/admin_views/test_templatetags.py
@@ -7,9 +7,10 @@ from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.test import RequestFactory, TestCase
from django.urls import reverse
+from django.utils.encoding import force_text
-from .admin import site
-from .models import Question
+from .admin import ArticleAdmin, site
+from .models import Article, Question
from .tests import AdminViewBasicTestCase
@@ -28,6 +29,46 @@ class AdminTemplateTagsTest(AdminViewBasicTestCase):
self.assertIs(template_context['extra'], True)
self.assertIs(template_context['show_save'], True)
+ def test_can_override_change_form_templatetags(self):
+ """
+ admin_modify templatetags can follow the 'standard' search patter admin/app_label/model/template.html
+ """
+ factory = RequestFactory()
+ article = Article.objects.all()[0]
+ request = factory.get(reverse('admin:admin_views_article_change', args=[article.pk]))
+ request.user = self.superuser
+ admin = ArticleAdmin(Article, site)
+ extra_context = {'show_publish': True, 'extra': True}
+ response = admin.change_view(request, str(article.pk), extra_context=extra_context)
+ response.render()
+ self.assertIs(response.context_data['show_publish'], True)
+ self.assertIs(response.context_data['extra'], True)
+ content = force_text(response.content)
+ self.assertIs('name="_save"' in content, True)
+ self.assertIs('name="_publish"' in content, True)
+ self.assertIs('override-change_form_object_tools' in content, True)
+ self.assertIs('override-prepopulated_fields_js' in content, True)
+
+ def test_can_override_change_list_templatetags(self):
+ """
+ admin_list templatetags can follow the 'standard' search patter admin/app_label/model/template.html
+ """
+ factory = RequestFactory()
+ request = factory.get(reverse('admin:admin_views_article_changelist'))
+ request.user = self.superuser
+ admin = ArticleAdmin(Article, site)
+ admin.date_hierarchy = 'date'
+ admin.search_fields = ('title', 'content',)
+ response = admin.changelist_view(request)
+ response.render()
+ content = force_text(response.content)
+ self.assertIs('override-actions' in content, True)
+ self.assertIs('override-change_list_object_tools' in content, True)
+ self.assertIs('override-change_list_results' in content, True)
+ self.assertIs('override-date_hierarchy' in content, True)
+ self.assertIs('override-pagination' in content, True)
+ self.assertIs('override-search_form' in content, True)
+
class DateHierarchyTests(TestCase):
factory = RequestFactory()