mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #28529 -- Fixed VariableDoesNotExist warnings in admin templates.
This commit is contained in:
		
				
					committed by
					
						 Tim Graham
						Tim Graham
					
				
			
			
				
	
			
			
			
						parent
						
							93bd860710
						
					
				
				
					commit
					a9f5652113
				
			| @@ -300,6 +300,7 @@ class AdminSite: | ||||
|             'site_url': site_url, | ||||
|             'has_permission': self.has_permission(request), | ||||
|             'available_apps': self.get_app_list(request), | ||||
|             'is_popup': False, | ||||
|         } | ||||
|  | ||||
|     def password_change(self, request, extra_context=None): | ||||
| @@ -431,6 +432,8 @@ class AdminSite: | ||||
|                 'name': capfirst(model._meta.verbose_name_plural), | ||||
|                 'object_name': model._meta.object_name, | ||||
|                 'perms': perms, | ||||
|                 'admin_url': None, | ||||
|                 'add_url': None, | ||||
|             } | ||||
|             if perms.get('change') or perms.get('view'): | ||||
|                 model_dict['view_only'] = not perms.get('change') | ||||
|   | ||||
| @@ -46,7 +46,7 @@ | ||||
|           {% endblock %} | ||||
|         </ul> | ||||
|     {% endblock %} | ||||
|     {% if cl.formset.errors %} | ||||
|     {% if cl.formset and cl.formset.errors %} | ||||
|         <p class="errornote"> | ||||
|         {% if cl.formset.total_error_count == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %} | ||||
|         </p> | ||||
| @@ -54,7 +54,7 @@ | ||||
|     {% endif %} | ||||
|     <div class="module{% if cl.has_filters %} filtered{% endif %}" id="changelist"> | ||||
|       {% 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 %} | ||||
|         {% if cl.has_filters %} | ||||
| @@ -65,7 +65,7 @@ | ||||
|         {% endif %} | ||||
|       {% 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 %} | ||||
|         <div>{{ cl.formset.management_form }}</div> | ||||
|       {% endif %} | ||||
|   | ||||
| @@ -27,7 +27,7 @@ | ||||
| </thead> | ||||
| <tbody> | ||||
| {% 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> | ||||
| {% endif %} | ||||
| <tr class="{% cycle 'row1' 'row2' %}">{% for item in result %}{{ item }}{% endfor %}</tr> | ||||
|   | ||||
| @@ -19,7 +19,7 @@ | ||||
|     {% include "admin/includes/fieldset.html" %} | ||||
|   {% endfor %} | ||||
|   {% 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 %} | ||||
| </fieldset> | ||||
| </div> | ||||
|   | ||||
| @@ -36,12 +36,12 @@ | ||||
|           {% if inline_admin_form.show_url %}<a href="{{ inline_admin_form.absolute_url }}">{% trans "View on site" %}</a>{% endif %} | ||||
|             </p>{% 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 %} | ||||
|           {% for fieldset in inline_admin_form %} | ||||
|             {% for line in fieldset %} | ||||
|               {% 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 %} | ||||
| @@ -50,7 +50,7 @@ | ||||
|         {% for fieldset in inline_admin_form %} | ||||
|           {% for line in fieldset %} | ||||
|             {% 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 %}> | ||||
|               {% if field.is_readonly %} | ||||
|                   <p>{{ field.contents }}</p> | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| <div class="submit-row"> | ||||
| {% block submit-row %} | ||||
| {% 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 %} | ||||
|     <p class="deletelink-box"><a href="{% add_preserved_filters delete_url %}" class="deletelink">{% trans "Delete" %}</a></p> | ||||
| {% endif %} | ||||
|   | ||||
| @@ -418,6 +418,7 @@ def date_hierarchy(cl): | ||||
|             years = getattr(cl.queryset, 'dates')(field_name, 'year') | ||||
|             return { | ||||
|                 'show': True, | ||||
|                 'back': None, | ||||
|                 'choices': [{ | ||||
|                     'link': link({year_field: str(year.year)}), | ||||
|                     'title': str(year.year), | ||||
|   | ||||
| @@ -46,6 +46,7 @@ class ChangeList: | ||||
|         self.list_display = list_display | ||||
|         self.list_display_links = list_display_links | ||||
|         self.list_filter = list_filter | ||||
|         self.has_filters = None | ||||
|         self.date_hierarchy = date_hierarchy | ||||
|         self.search_fields = search_fields | ||||
|         self.list_select_related = list_select_related | ||||
|   | ||||
| @@ -154,8 +154,12 @@ class ForeignKeyRawIdWidget(forms.TextInput): | ||||
|             context['link_title'] = _('Lookup') | ||||
|             # The JavaScript code looks for this class. | ||||
|             context['widget']['attrs'].setdefault('class', 'vForeignKeyRawIdAdminField') | ||||
|         else: | ||||
|             context['related_url'] = None | ||||
|         if context['widget']['value']: | ||||
|             context['link_label'], context['link_url'] = self.label_and_url_for_value(value) | ||||
|         else: | ||||
|             context['link_label'] = None | ||||
|         return context | ||||
|  | ||||
|     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 | ||||
|     idea to turn it on as a 'development default'. | ||||
|  | ||||
|     Many templates, including those in the Admin site, rely upon the silence | ||||
|     of the template system when a nonexistent variable is encountered. If you | ||||
|     assign a value other than ``''`` to ``string_if_invalid``, you will | ||||
|     Many templates, including some of the Django's templates, rely upon the | ||||
|     silence of the template system when a nonexistent variable is encountered. | ||||
|     If you assign a value other than ``''`` to ``string_if_invalid``, you will | ||||
|     experience rendering problems with these templates and sites. | ||||
|  | ||||
|     Generally, ``string_if_invalid`` should only be enabled in order to debug | ||||
|   | ||||
		Reference in New Issue
	
	Block a user