Fixed #28529 -- Fixed VariableDoesNotExist warnings in admin templates.
This commit is contained in:
parent
93bd860710
commit
a9f5652113
|
@ -300,6 +300,7 @@ class AdminSite:
|
||||||
'site_url': site_url,
|
'site_url': site_url,
|
||||||
'has_permission': self.has_permission(request),
|
'has_permission': self.has_permission(request),
|
||||||
'available_apps': self.get_app_list(request),
|
'available_apps': self.get_app_list(request),
|
||||||
|
'is_popup': False,
|
||||||
}
|
}
|
||||||
|
|
||||||
def password_change(self, request, extra_context=None):
|
def password_change(self, request, extra_context=None):
|
||||||
|
@ -431,6 +432,8 @@ class AdminSite:
|
||||||
'name': capfirst(model._meta.verbose_name_plural),
|
'name': capfirst(model._meta.verbose_name_plural),
|
||||||
'object_name': model._meta.object_name,
|
'object_name': model._meta.object_name,
|
||||||
'perms': perms,
|
'perms': perms,
|
||||||
|
'admin_url': None,
|
||||||
|
'add_url': None,
|
||||||
}
|
}
|
||||||
if perms.get('change') or perms.get('view'):
|
if perms.get('change') or perms.get('view'):
|
||||||
model_dict['view_only'] = not perms.get('change')
|
model_dict['view_only'] = not perms.get('change')
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% if cl.formset.errors %}
|
{% if cl.formset and cl.formset.errors %}
|
||||||
<p class="errornote">
|
<p class="errornote">
|
||||||
{% if cl.formset.total_error_count == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %}
|
{% if cl.formset.total_error_count == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %}
|
||||||
</p>
|
</p>
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
|
<div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist">
|
||||||
{% block search %}{% search_form cl %}{% endblock %}
|
{% block search %}{% search_form cl %}{% endblock %}
|
||||||
{% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
|
{% block date_hierarchy %}{% if cl.date_hierarchy %}{% date_hierarchy cl %}{% endif %}{% endblock %}
|
||||||
|
|
||||||
{% block filters %}
|
{% block filters %}
|
||||||
{% if cl.has_filters %}
|
{% if cl.has_filters %}
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
<form id="changelist-form" method="post"{% if cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %} novalidate>{% csrf_token %}
|
<form id="changelist-form" method="post"{% if cl.formset and cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %} novalidate>{% csrf_token %}
|
||||||
{% if cl.formset %}
|
{% if cl.formset %}
|
||||||
<div>{{ cl.formset.management_form }}</div>
|
<div>{{ cl.formset.management_form }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for result in results %}
|
{% for result in results %}
|
||||||
{% if result.form.non_field_errors %}
|
{% if result.form and result.form.non_field_errors %}
|
||||||
<tr><td colspan="{{ result|length }}">{{ result.form.non_field_errors }}</td></tr>
|
<tr><td colspan="{{ result|length }}">{{ result.form.non_field_errors }}</td></tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<tr class="{% cycle 'row1' 'row2' %}">{% for item in result %}{{ item }}{% endfor %}</tr>
|
<tr class="{% cycle 'row1' 'row2' %}">{% for item in result %}{{ item }}{% endfor %}</tr>
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
{% include "admin/includes/fieldset.html" %}
|
{% include "admin/includes/fieldset.html" %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if inline_admin_form.needs_explicit_pk_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
|
{% if inline_admin_form.needs_explicit_pk_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
|
||||||
{{ inline_admin_form.fk_field.field }}
|
{% if inline_admin_form.fk_field %}{{ inline_admin_form.fk_field.field }}{% endif %}
|
||||||
</div>{% endfor %}
|
</div>{% endfor %}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -36,12 +36,12 @@
|
||||||
{% if inline_admin_form.show_url %}<a href="{{ inline_admin_form.absolute_url }}">{% trans "View on site" %}</a>{% endif %}
|
{% if inline_admin_form.show_url %}<a href="{{ inline_admin_form.absolute_url }}">{% trans "View on site" %}</a>{% endif %}
|
||||||
</p>{% endif %}
|
</p>{% endif %}
|
||||||
{% if inline_admin_form.needs_explicit_pk_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
|
{% if inline_admin_form.needs_explicit_pk_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
|
||||||
{{ inline_admin_form.fk_field.field }}
|
{% if inline_admin_form.fk_field %}{{ inline_admin_form.fk_field.field }}{% endif %}
|
||||||
{% spaceless %}
|
{% spaceless %}
|
||||||
{% for fieldset in inline_admin_form %}
|
{% for fieldset in inline_admin_form %}
|
||||||
{% for line in fieldset %}
|
{% for line in fieldset %}
|
||||||
{% for field in line %}
|
{% for field in line %}
|
||||||
{% if field.field.is_hidden %} {{ field.field }} {% endif %}
|
{% if not field.is_readonly and field.field.is_hidden %}{{ field.field }}{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
{% for fieldset in inline_admin_form %}
|
{% for fieldset in inline_admin_form %}
|
||||||
{% for line in fieldset %}
|
{% for line in fieldset %}
|
||||||
{% for field in line %}
|
{% for field in line %}
|
||||||
{% if not field.field.is_hidden %}
|
{% if field.is_readonly or not field.field.is_hidden %}
|
||||||
<td{% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
|
<td{% if field.field.name %} class="field-{{ field.field.name }}"{% endif %}>
|
||||||
{% if field.is_readonly %}
|
{% if field.is_readonly %}
|
||||||
<p>{{ field.contents }}</p>
|
<p>{{ field.contents }}</p>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<div class="submit-row">
|
<div class="submit-row">
|
||||||
{% block submit-row %}
|
{% block submit-row %}
|
||||||
{% if show_save %}<input type="submit" value="{% trans 'Save' %}" class="default" name="_save">{% endif %}
|
{% if show_save %}<input type="submit" value="{% trans 'Save' %}" class="default" name="_save">{% endif %}
|
||||||
{% if show_delete_link %}
|
{% if show_delete_link and original %}
|
||||||
{% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
|
{% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
|
||||||
<p class="deletelink-box"><a href="{% add_preserved_filters delete_url %}" class="deletelink">{% trans "Delete" %}</a></p>
|
<p class="deletelink-box"><a href="{% add_preserved_filters delete_url %}" class="deletelink">{% trans "Delete" %}</a></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -418,6 +418,7 @@ def date_hierarchy(cl):
|
||||||
years = getattr(cl.queryset, 'dates')(field_name, 'year')
|
years = getattr(cl.queryset, 'dates')(field_name, 'year')
|
||||||
return {
|
return {
|
||||||
'show': True,
|
'show': True,
|
||||||
|
'back': None,
|
||||||
'choices': [{
|
'choices': [{
|
||||||
'link': link({year_field: str(year.year)}),
|
'link': link({year_field: str(year.year)}),
|
||||||
'title': str(year.year),
|
'title': str(year.year),
|
||||||
|
|
|
@ -46,6 +46,7 @@ class ChangeList:
|
||||||
self.list_display = list_display
|
self.list_display = list_display
|
||||||
self.list_display_links = list_display_links
|
self.list_display_links = list_display_links
|
||||||
self.list_filter = list_filter
|
self.list_filter = list_filter
|
||||||
|
self.has_filters = None
|
||||||
self.date_hierarchy = date_hierarchy
|
self.date_hierarchy = date_hierarchy
|
||||||
self.search_fields = search_fields
|
self.search_fields = search_fields
|
||||||
self.list_select_related = list_select_related
|
self.list_select_related = list_select_related
|
||||||
|
|
|
@ -154,8 +154,12 @@ class ForeignKeyRawIdWidget(forms.TextInput):
|
||||||
context['link_title'] = _('Lookup')
|
context['link_title'] = _('Lookup')
|
||||||
# The JavaScript code looks for this class.
|
# The JavaScript code looks for this class.
|
||||||
context['widget']['attrs'].setdefault('class', 'vForeignKeyRawIdAdminField')
|
context['widget']['attrs'].setdefault('class', 'vForeignKeyRawIdAdminField')
|
||||||
|
else:
|
||||||
|
context['related_url'] = None
|
||||||
if context['widget']['value']:
|
if context['widget']['value']:
|
||||||
context['link_label'], context['link_url'] = self.label_and_url_for_value(value)
|
context['link_label'], context['link_url'] = self.label_and_url_for_value(value)
|
||||||
|
else:
|
||||||
|
context['link_label'] = None
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def base_url_parameters(self):
|
def base_url_parameters(self):
|
||||||
|
|
|
@ -371,9 +371,9 @@ replaced with the name of the invalid variable.
|
||||||
While ``string_if_invalid`` can be a useful debugging tool, it is a bad
|
While ``string_if_invalid`` can be a useful debugging tool, it is a bad
|
||||||
idea to turn it on as a 'development default'.
|
idea to turn it on as a 'development default'.
|
||||||
|
|
||||||
Many templates, including those in the Admin site, rely upon the silence
|
Many templates, including some of the Django's templates, rely upon the
|
||||||
of the template system when a nonexistent variable is encountered. If you
|
silence of the template system when a nonexistent variable is encountered.
|
||||||
assign a value other than ``''`` to ``string_if_invalid``, you will
|
If you assign a value other than ``''`` to ``string_if_invalid``, you will
|
||||||
experience rendering problems with these templates and sites.
|
experience rendering problems with these templates and sites.
|
||||||
|
|
||||||
Generally, ``string_if_invalid`` should only be enabled in order to debug
|
Generally, ``string_if_invalid`` should only be enabled in order to debug
|
||||||
|
|
Loading…
Reference in New Issue