Fixed #29038 -- Removed closing slash from HTML void tags.

This commit is contained in:
Jon Dufresne 2018-01-20 23:09:10 -08:00 committed by Tim Graham
parent 4b0f39d9fb
commit ff05de760c
112 changed files with 1487 additions and 1483 deletions

View File

@ -809,7 +809,7 @@ class ModelAdmin(BaseModelAdmin):
A list_display column containing a checkbox widget. A list_display column containing a checkbox widget.
""" """
return helpers.checkbox.render(helpers.ACTION_CHECKBOX_NAME, str(obj.pk)) return helpers.checkbox.render(helpers.ACTION_CHECKBOX_NAME, str(obj.pk))
action_checkbox.short_description = mark_safe('<input type="checkbox" id="action-toggle" />') action_checkbox.short_description = mark_safe('<input type="checkbox" id="action-toggle">')
def get_actions(self, request): def get_actions(self, request):
""" """

View File

@ -5,7 +5,7 @@
{% block extrahead %}{{ block.super }} {% block extrahead %}{{ block.super }}
<script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script> <script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
{% endblock %} {% endblock %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />{% endblock %} {% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}">{% endblock %}
{% block bodyclass %}{{ block.super }} {{ opts.app_label }}-{{ opts.model_name }} change-form{% endblock %} {% block bodyclass %}{{ block.super }} {{ opts.app_label }}-{{ opts.model_name }} change-form{% endblock %}
{% if not is_popup %} {% if not is_popup %}
{% block breadcrumbs %} {% block breadcrumbs %}
@ -20,9 +20,9 @@
{% endif %} {% endif %}
{% block content %}<div id="content-main"> {% block content %}<div id="content-main">
<form action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %} <form action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
<input type="text" name="username" value="{{ original.get_username }}" style="display: none" /> <input type="text" name="username" value="{{ original.get_username }}" style="display: none">
<div> <div>
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %} {% if is_popup %}<input type="hidden" name="_popup" value="1">{% endif %}
{% if form.errors %} {% if form.errors %}
<p class="errornote"> <p class="errornote">
{% if form.errors.items|length == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %} {% if form.errors.items|length == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %}
@ -52,7 +52,7 @@
</fieldset> </fieldset>
<div class="submit-row"> <div class="submit-row">
<input type="submit" value="{% trans 'Change password' %}" class="default" /> <input type="submit" value="{% trans 'Change password' %}" class="default">
</div> </div>
</div> </div>

View File

@ -3,16 +3,16 @@
<html lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}> <html lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
<head> <head>
<title>{% block title %}{% endblock %}</title> <title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}" /> <link rel="stylesheet" type="text/css" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}">
{% block extrastyle %}{% endblock %} {% block extrastyle %}{% endblock %}
{% if LANGUAGE_BIDI %}<link rel="stylesheet" type="text/css" href="{% block stylesheet_rtl %}{% static "admin/css/rtl.css" %}{% endblock %}" />{% endif %} {% if LANGUAGE_BIDI %}<link rel="stylesheet" type="text/css" href="{% block stylesheet_rtl %}{% static "admin/css/rtl.css" %}{% endblock %}">{% endif %}
{% block extrahead %}{% endblock %} {% block extrahead %}{% endblock %}
{% block responsive %} {% block responsive %}
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"> <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" type="text/css" href="{% static "admin/css/responsive.css" %}" /> <link rel="stylesheet" type="text/css" href="{% static "admin/css/responsive.css" %}">
{% if LANGUAGE_BIDI %}<link rel="stylesheet" type="text/css" href="{% static "admin/css/responsive_rtl.css" %}" />{% endif %} {% if LANGUAGE_BIDI %}<link rel="stylesheet" type="text/css" href="{% static "admin/css/responsive_rtl.css" %}">{% endif %}
{% endblock %} {% endblock %}
{% block blockbots %}<meta name="robots" content="NONE,NOARCHIVE" />{% endblock %} {% block blockbots %}<meta name="robots" content="NONE,NOARCHIVE">{% endblock %}
</head> </head>
{% load i18n %} {% load i18n %}
@ -81,7 +81,7 @@
{{ content }} {{ content }}
{% endblock %} {% endblock %}
{% block sidebar %}{% endblock %} {% block sidebar %}{% endblock %}
<br class="clear" /> <br class="clear">
</div> </div>
<!-- END Content --> <!-- END Content -->

View File

@ -6,7 +6,7 @@
{{ media }} {{ media }}
{% endblock %} {% endblock %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />{% endblock %} {% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}">{% endblock %}
{% block coltype %}colM{% endblock %} {% block coltype %}colM{% endblock %}
@ -39,8 +39,8 @@
{% endblock %} {% endblock %}
<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form" novalidate>{% csrf_token %}{% block form_top %}{% endblock %} <form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form" novalidate>{% csrf_token %}{% block form_top %}{% endblock %}
<div> <div>
{% if is_popup %}<input type="hidden" name="{{ is_popup_var }}" value="1" />{% endif %} {% if is_popup %}<input type="hidden" name="{{ is_popup_var }}" value="1">{% endif %}
{% if to_field %}<input type="hidden" name="{{ to_field_var }}" value="{{ to_field }}" />{% endif %} {% if to_field %}<input type="hidden" name="{{ to_field_var }}" value="{{ to_field }}">{% endif %}
{% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %} {% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %}
{% if errors %} {% if errors %}
<p class="errornote"> <p class="errornote">

View File

@ -3,9 +3,9 @@
{% block extrastyle %} {% block extrastyle %}
{{ block.super }} {{ block.super }}
<link rel="stylesheet" type="text/css" href="{% static "admin/css/changelists.css" %}" /> <link rel="stylesheet" type="text/css" href="{% static "admin/css/changelists.css" %}">
{% if cl.formset %} {% if cl.formset %}
<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" /> <link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}">
{% endif %} {% endif %}
{% if cl.formset or action_form %} {% if cl.formset or action_form %}
<script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script> <script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>

View File

@ -5,6 +5,6 @@
{% for choice in choices %} {% for choice in choices %}
<li> {% if choice.link %}<a href="{{ choice.link }}">{% endif %}{{ choice.title }}{% if choice.link %}</a>{% endif %}</li> <li> {% if choice.link %}<a href="{{ choice.link }}">{% endif %}{{ choice.title }}{% if choice.link %}</a>{% endif %}</li>
{% endfor %} {% endfor %}
</ul><br class="clear" /> </ul><br class="clear">
</div> </div>
{% endif %} {% endif %}

View File

@ -41,10 +41,10 @@
<ul>{{ deleted_objects|unordered_list }}</ul> <ul>{{ deleted_objects|unordered_list }}</ul>
<form method="post">{% csrf_token %} <form method="post">{% csrf_token %}
<div> <div>
<input type="hidden" name="post" value="yes" /> <input type="hidden" name="post" value="yes">
{% if is_popup %}<input type="hidden" name="{{ is_popup_var }}" value="1" />{% endif %} {% if is_popup %}<input type="hidden" name="{{ is_popup_var }}" value="1">{% endif %}
{% if to_field %}<input type="hidden" name="{{ to_field_var }}" value="{{ to_field }}" />{% endif %} {% if to_field %}<input type="hidden" name="{{ to_field_var }}" value="{{ to_field }}">{% endif %}
<input type="submit" value="{% trans "Yes, I'm sure" %}" /> <input type="submit" value="{% trans "Yes, I'm sure" %}">
<a href="#" class="button cancel-link">{% trans "No, take me back" %}</a> <a href="#" class="button cancel-link">{% trans "No, take me back" %}</a>
</div> </div>
</form> </form>

View File

@ -43,11 +43,11 @@
<form method="post">{% csrf_token %} <form method="post">{% csrf_token %}
<div> <div>
{% for obj in queryset %} {% for obj in queryset %}
<input type="hidden" name="{{ action_checkbox_name }}" value="{{ obj.pk|unlocalize }}" /> <input type="hidden" name="{{ action_checkbox_name }}" value="{{ obj.pk|unlocalize }}">
{% endfor %} {% endfor %}
<input type="hidden" name="action" value="delete_selected" /> <input type="hidden" name="action" value="delete_selected">
<input type="hidden" name="post" value="yes" /> <input type="hidden" name="post" value="yes">
<input type="submit" value="{% trans "Yes, I'm sure" %}" /> <input type="submit" value="{% trans "Yes, I'm sure" %}">
<a href="#" class="button cancel-link">{% trans "No, take me back" %}</a> <a href="#" class="button cancel-link">{% trans "No, take me back" %}</a>
</div> </div>
</form> </form>

View File

@ -13,7 +13,7 @@
{% for field in inline_admin_formset.fields %} {% for field in inline_admin_formset.fields %}
{% if not field.widget.is_hidden %} {% if not field.widget.is_hidden %}
<th{% if field.required %} class="required"{% endif %}>{{ field.label|capfirst }} <th{% if field.required %} class="required"{% endif %}>{{ field.label|capfirst }}
{% if field.help_text %}&nbsp;<img src="{% static "admin/img/icon-unknown.svg" %}" class="help help-tooltip" width="10" height="10" alt="({{ field.help_text|striptags }})" title="{{ field.help_text|striptags }}" />{% endif %} {% if field.help_text %}&nbsp;<img src="{% static "admin/img/icon-unknown.svg" %}" class="help help-tooltip" width="10" height="10" alt="({{ field.help_text|striptags }})" title="{{ field.help_text|striptags }}">{% endif %}
</th> </th>
{% endif %} {% endif %}
{% endfor %} {% endfor %}

View File

@ -1,7 +1,7 @@
{% extends "admin/base_site.html" %} {% extends "admin/base_site.html" %}
{% load i18n static %} {% load i18n static %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}" />{% endblock %} {% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}">{% endblock %}
{% block coltype %}colMS{% endblock %} {% block coltype %}colMS{% endblock %}
@ -67,7 +67,7 @@
{% else %} {% else %}
<a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a> <a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
{% endif %} {% endif %}
<br/> <br>
{% if entry.content_type %} {% if entry.content_type %}
<span class="mini quiet">{% filter capfirst %}{{ entry.content_type }}{% endfilter %}</span> <span class="mini quiet">{% filter capfirst %}{{ entry.content_type }}{% endfilter %}</span>
{% else %} {% else %}

View File

@ -1,7 +1,7 @@
{% extends "admin/base_site.html" %} {% extends "admin/base_site.html" %}
{% load i18n static %} {% load i18n static %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/login.css" %}" /> {% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/login.css" %}">
{{ form.media }} {{ form.media }}
{% endblock %} {% endblock %}
@ -49,7 +49,7 @@
<div class="form-row"> <div class="form-row">
{{ form.password.errors }} {{ form.password.errors }}
{{ form.password.label_tag }} {{ form.password }} {{ form.password.label_tag }} {{ form.password }}
<input type="hidden" name="next" value="{{ next }}" /> <input type="hidden" name="next" value="{{ next }}">
</div> </div>
{% url 'admin_password_reset' as password_reset_url %} {% url 'admin_password_reset' as password_reset_url %}
{% if password_reset_url %} {% if password_reset_url %}
@ -58,7 +58,7 @@
</div> </div>
{% endif %} {% endif %}
<div class="submit-row"> <div class="submit-row">
<label>&nbsp;</label><input type="submit" value="{% trans 'Log in' %}" /> <label>&nbsp;</label><input type="submit" value="{% trans 'Log in' %}">
</div> </div>
</form> </form>

View File

@ -8,5 +8,5 @@
{% endif %} {% endif %}
{{ cl.result_count }} {% if cl.result_count == 1 %}{{ cl.opts.verbose_name }}{% else %}{{ cl.opts.verbose_name_plural }}{% 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 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 %} {% if cl.formset and cl.result_count %}<input type="submit" name="_save" class="default" value="{% trans 'Save' %}">{% endif %}
</p> </p>

View File

@ -7,21 +7,21 @@
<a class="related-widget-wrapper-link change-related" id="change_id_{{ name }}" <a class="related-widget-wrapper-link change-related" id="change_id_{{ name }}"
data-href-template="{{ change_related_template_url }}?{{ url_params }}" data-href-template="{{ change_related_template_url }}?{{ url_params }}"
title="{% blocktrans %}Change selected {{ model }}{% endblocktrans %}"> title="{% blocktrans %}Change selected {{ model }}{% endblocktrans %}">
<img src="{% static 'admin/img/icon-changelink.svg' %}" alt="{% trans 'Change' %}"/> <img src="{% static 'admin/img/icon-changelink.svg' %}" alt="{% trans 'Change' %}">
</a> </a>
{% endif %} {% endif %}
{% if can_add_related %} {% if can_add_related %}
<a class="related-widget-wrapper-link add-related" id="add_id_{{ name }}" <a class="related-widget-wrapper-link add-related" id="add_id_{{ name }}"
href="{{ add_related_url }}?{{ url_params }}" href="{{ add_related_url }}?{{ url_params }}"
title="{% blocktrans %}Add another {{ model }}{% endblocktrans %}"> title="{% blocktrans %}Add another {{ model }}{% endblocktrans %}">
<img src="{% static 'admin/img/icon-addlink.svg' %}" alt="{% trans 'Add' %}"/> <img src="{% static 'admin/img/icon-addlink.svg' %}" alt="{% trans 'Add' %}">
</a> </a>
{% endif %} {% endif %}
{% if can_delete_related %} {% if can_delete_related %}
<a class="related-widget-wrapper-link delete-related" id="delete_id_{{ name }}" <a class="related-widget-wrapper-link delete-related" id="delete_id_{{ name }}"
data-href-template="{{ delete_related_template_url }}?{{ url_params }}" data-href-template="{{ delete_related_template_url }}?{{ url_params }}"
title="{% blocktrans %}Delete selected {{ model }}{% endblocktrans %}"> title="{% blocktrans %}Delete selected {{ model }}{% endblocktrans %}">
<img src="{% static 'admin/img/icon-deletelink.svg' %}" alt="{% trans 'Delete' %}"/> <img src="{% static 'admin/img/icon-deletelink.svg' %}" alt="{% trans 'Delete' %}">
</a> </a>
{% endif %} {% endif %}
{% endspaceless %} {% endspaceless %}

View File

@ -2,14 +2,14 @@
{% if cl.search_fields %} {% if cl.search_fields %}
<div id="toolbar"><form id="changelist-search" method="get"> <div id="toolbar"><form id="changelist-search" method="get">
<div><!-- DIV needed for valid HTML --> <div><!-- DIV needed for valid HTML -->
<label for="searchbar"><img src="{% static "admin/img/search.svg" %}" alt="Search" /></label> <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="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" autofocus>
<input type="submit" value="{% trans 'Search' %}" /> <input type="submit" value="{% trans 'Search' %}">
{% if show_result_count %} {% 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> <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 %} {% endif %}
{% for pair in cl.params.items %} {% for pair in cl.params.items %}
{% if pair.0 != search_var %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}"/>{% endif %} {% if pair.0 != search_var %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}">{% endif %}
{% endfor %} {% endfor %}
</div> </div>
</form></div> </form></div>

View File

@ -1,11 +1,11 @@
{% load i18n admin_urls %} {% load i18n admin_urls %}
<div class="submit-row"> <div class="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 %}
{% 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 %}
{% if show_save_as_new %}<input type="submit" value="{% trans 'Save as new' %}" name="_saveasnew" />{% endif %} {% if show_save_as_new %}<input type="submit" value="{% trans 'Save as new' %}" name="_saveasnew">{% endif %}
{% if show_save_and_add_another %}<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother" />{% endif %} {% if show_save_and_add_another %}<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother">{% endif %}
{% if show_save_and_continue %}<input type="submit" value="{% trans 'Save and continue editing' %}" name="_continue" />{% endif %} {% if show_save_and_continue %}<input type="submit" value="{% trans 'Save and continue editing' %}" name="_continue">{% endif %}
</div> </div>

View File

@ -1,6 +1,6 @@
{% if widget.is_initial %}<p class="file-upload">{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %} {% if widget.is_initial %}<p class="file-upload">{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %}
<span class="clearable-file-input"> <span class="clearable-file-input">
<input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}" /> <input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}">
<label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label></span>{% endif %}<br /> <label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label></span>{% endif %}<br>
{{ widget.input_text }}:{% endif %} {{ widget.input_text }}:{% endif %}
<input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %} />{% if widget.is_initial %}</p>{% endif %} <input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>{% if widget.is_initial %}</p>{% endif %}

View File

@ -7,21 +7,21 @@
<a class="related-widget-wrapper-link change-related" id="change_id_{{ name }}" <a class="related-widget-wrapper-link change-related" id="change_id_{{ name }}"
data-href-template="{{ change_related_template_url }}?{{ url_params }}" data-href-template="{{ change_related_template_url }}?{{ url_params }}"
title="{% blocktrans %}Change selected {{ model }}{% endblocktrans %}"> title="{% blocktrans %}Change selected {{ model }}{% endblocktrans %}">
<img src="{% static 'admin/img/icon-changelink.svg' %}" alt="{% trans 'Change' %}"/> <img src="{% static 'admin/img/icon-changelink.svg' %}" alt="{% trans 'Change' %}">
</a> </a>
{% endif %} {% endif %}
{% if can_add_related %} {% if can_add_related %}
<a class="related-widget-wrapper-link add-related" id="add_id_{{ name }}" <a class="related-widget-wrapper-link add-related" id="add_id_{{ name }}"
href="{{ add_related_url }}?{{ url_params }}" href="{{ add_related_url }}?{{ url_params }}"
title="{% blocktrans %}Add another {{ model }}{% endblocktrans %}"> title="{% blocktrans %}Add another {{ model }}{% endblocktrans %}">
<img src="{% static 'admin/img/icon-addlink.svg' %}" alt="{% trans 'Add' %}"/> <img src="{% static 'admin/img/icon-addlink.svg' %}" alt="{% trans 'Add' %}">
</a> </a>
{% endif %} {% endif %}
{% if can_delete_related %} {% if can_delete_related %}
<a class="related-widget-wrapper-link delete-related" id="delete_id_{{ name }}" <a class="related-widget-wrapper-link delete-related" id="delete_id_{{ name }}"
data-href-template="{{ delete_related_template_url }}?{{ url_params }}" data-href-template="{{ delete_related_template_url }}?{{ url_params }}"
title="{% blocktrans %}Delete selected {{ model }}{% endblocktrans %}"> title="{% blocktrans %}Delete selected {{ model }}{% endblocktrans %}">
<img src="{% static 'admin/img/icon-deletelink.svg' %}" alt="{% trans 'Delete' %}"/> <img src="{% static 'admin/img/icon-deletelink.svg' %}" alt="{% trans 'Delete' %}">
</a> </a>
{% endif %} {% endif %}
{% endspaceless %} {% endspaceless %}

View File

@ -1,4 +1,4 @@
<p class="datetime"> <p class="datetime">
{{ date_label }} {% with widget=widget.subwidgets.0 %}{% include widget.template_name %}{% endwith %}<br /> {{ date_label }} {% with widget=widget.subwidgets.0 %}{% include widget.template_name %}{% endwith %}<br>
{{ time_label }} {% with widget=widget.subwidgets.1 %}{% include widget.template_name %}{% endwith %} {{ time_label }} {% with widget=widget.subwidgets.1 %}{% include widget.template_name %}{% endwith %}
</p> </p>

View File

@ -1 +1 @@
{% if widget.value %}<p class="url">{{ current_label }} <a href="{{ widget.href }}">{{ widget.value }}</a><br />{{ change_label }} {% endif %}{% include "django/forms/widgets/input.html" %}{% if widget.value %}</p>{% endif %} {% if widget.value %}<p class="url">{{ current_label }} <a href="{{ widget.href }}">{{ widget.value }}</a><br>{{ change_label }} {% endif %}{% include "django/forms/widgets/input.html" %}{% if widget.value %}</p>{% endif %}

View File

@ -1,6 +1,6 @@
{% extends "admin/base_site.html" %} {% extends "admin/base_site.html" %}
{% load i18n static %} {% load i18n static %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />{% endblock %} {% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}">{% endblock %}
{% block userlinks %}{% url 'django-admindocs-docroot' as docsroot %}{% if docsroot %}<a href="{{ docsroot }}">{% trans 'Documentation' %}</a> / {% endif %} {% trans 'Change password' %} / <a href="{% url 'admin:logout' %}">{% trans 'Log out' %}</a>{% endblock %} {% block userlinks %}{% url 'django-admindocs-docroot' as docsroot %}{% if docsroot %}<a href="{{ docsroot }}">{% trans 'Documentation' %}</a> / {% endif %} {% trans 'Change password' %} / <a href="{% url 'admin:logout' %}">{% trans 'Log out' %}</a>{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
<div class="breadcrumbs"> <div class="breadcrumbs">
@ -51,7 +51,7 @@
</fieldset> </fieldset>
<div class="submit-row"> <div class="submit-row">
<input type="submit" value="{% trans 'Change my password' %}" class="default" /> <input type="submit" value="{% trans 'Change my password' %}" class="default">
</div> </div>
</div> </div>

View File

@ -1,7 +1,7 @@
{% extends "admin/base_site.html" %} {% extends "admin/base_site.html" %}
{% load i18n static %} {% load i18n static %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />{% endblock %} {% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}">{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
<div class="breadcrumbs"> <div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a> <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
@ -29,7 +29,7 @@
<label for="id_new_password2">{% trans 'Confirm password:' %}</label> <label for="id_new_password2">{% trans 'Confirm password:' %}</label>
{{ form.new_password2 }} {{ form.new_password2 }}
</div> </div>
<input type="submit" value="{% trans 'Change my password' %}" /> <input type="submit" value="{% trans 'Change my password' %}">
</fieldset> </fieldset>
</form> </form>

View File

@ -1,7 +1,7 @@
{% extends "admin/base_site.html" %} {% extends "admin/base_site.html" %}
{% load i18n static %} {% load i18n static %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />{% endblock %} {% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}">{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
<div class="breadcrumbs"> <div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a> <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
@ -22,7 +22,7 @@
<label for="id_email">{% trans 'Email address:' %}</label> <label for="id_email">{% trans 'Email address:' %}</label>
{{ form.email }} {{ form.email }}
</div> </div>
<input type="submit" value="{% trans 'Reset my password' %}" /> <input type="submit" value="{% trans 'Reset my password' %}">
</fieldset> </fieldset>
</form> </form>

View File

@ -177,7 +177,7 @@ def result_headers(cl):
def _boolean_icon(field_val): def _boolean_icon(field_val):
icon_url = static('admin/img/icon-%s.svg' % icon_url = static('admin/img/icon-%s.svg' %
{True: 'yes', False: 'no', None: 'unknown'}[field_val]) {True: 'yes', False: 'no', None: 'unknown'}[field_val])
return format_html('<img src="{}" alt="{}" />', icon_url, field_val) return format_html('<img src="{}" alt="{}">', icon_url, field_val)
def _coerce_field_name(field_name, field_index): def _coerce_field_name(field_name, field_index):

View File

@ -20,12 +20,12 @@
{% for library in filter_libraries %} {% for library in filter_libraries %}
<div class="module"> <div class="module">
<h2>{% firstof library.grouper _("Built-in filters") %}</h2> <h2>{% firstof library.grouper _("Built-in filters") %}</h2>
{% if library.grouper %}<p class="small quiet">{% blocktrans with code="{"|add:"% load "|add:library.grouper|add:" %"|add:"}" %}To use these filters, put <code>{{ code }}</code> in your template before using the filter.{% endblocktrans %}</p><hr />{% endif %} {% if library.grouper %}<p class="small quiet">{% blocktrans with code="{"|add:"% load "|add:library.grouper|add:" %"|add:"}" %}To use these filters, put <code>{{ code }}</code> in your template before using the filter.{% endblocktrans %}</p><hr>{% endif %}
{% for filter in library.list|dictsort:"name" %} {% for filter in library.list|dictsort:"name" %}
<h3 id="{{ library.grouper|default:"built_in" }}-{{ filter.name }}">{{ filter.name }}</h3> <h3 id="{{ library.grouper|default:"built_in" }}-{{ filter.name }}">{{ filter.name }}</h3>
{{ filter.title }} {{ filter.title }}
{{ filter.body }} {{ filter.body }}
{% if not forloop.last %}<hr />{% endif %} {% if not forloop.last %}<hr>{% endif %}
{% endfor %} {% endfor %}
</div> </div>
{% endfor %} {% endfor %}

View File

@ -20,12 +20,12 @@
{% for library in tag_libraries %} {% for library in tag_libraries %}
<div class="module"> <div class="module">
<h2>{% firstof library.grouper _("Built-in tags") %}</h2> <h2>{% firstof library.grouper _("Built-in tags") %}</h2>
{% if library.grouper %}<p class="small quiet">{% blocktrans with code="{"|add:"% load "|add:library.grouper|add:" %"|add:"}" %}To use these tags, put <code>{{ code }}</code> in your template before using the tag.{% endblocktrans %}</p><hr />{% endif %} {% if library.grouper %}<p class="small quiet">{% blocktrans with code="{"|add:"% load "|add:library.grouper|add:" %"|add:"}" %}To use these tags, put <code>{{ code }}</code> in your template before using the tag.{% endblocktrans %}</p><hr>{% endif %}
{% for tag in library.list|dictsort:"name" %} {% for tag in library.list|dictsort:"name" %}
<h3 id="{{ library.grouper|default:"built_in" }}-{{ tag.name }}">{{ tag.name }}</h3> <h3 id="{{ library.grouper|default:"built_in" }}-{{ tag.name }}">{{ tag.name }}</h3>
<h4>{{ tag.title|striptags }}</h4> <h4>{{ tag.title|striptags }}</h4>
{{ tag.body }} {{ tag.body }}
{% if not forloop.last %}<hr />{% endif %} {% if not forloop.last %}<hr>{% endif %}
{% endfor %} {% endfor %}
</div> </div>
{% endfor %} {% endfor %}

View File

@ -50,7 +50,7 @@
View function: <code>{{ full_name }}</code>. Name: <code>{{ url_name }}</code>. View function: <code>{{ full_name }}</code>. Name: <code>{{ url_name }}</code>.
{% endblocktrans %}</p> {% endblocktrans %}</p>
<p>{{ view.title }}</p> <p>{{ view.title }}</p>
<hr /> <hr>
{% endifchanged %} {% endifchanged %}
{% endfor %} {% endfor %}
</div> </div>

View File

@ -274,7 +274,7 @@ class BaseForm:
normal_row='<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', normal_row='<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>',
error_row='<tr><td colspan="2">%s</td></tr>', error_row='<tr><td colspan="2">%s</td></tr>',
row_ender='</td></tr>', row_ender='</td></tr>',
help_text_html='<br /><span class="helptext">%s</span>', help_text_html='<br><span class="helptext">%s</span>',
errors_on_separate_row=False) errors_on_separate_row=False)
def as_ul(self): def as_ul(self):

View File

@ -1,5 +1,5 @@
{% if widget.is_initial %}{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %} {% if widget.is_initial %}{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %}
<input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}" /> <input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}">
<label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label>{% endif %}<br /> <label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label>{% endif %}<br>
{{ widget.input_text }}:{% endif %} {{ widget.input_text }}:{% endif %}
<input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %} /> <input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>

View File

@ -1 +1 @@
<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} /> <input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value }}"{% endif %}{% include "django/forms/widgets/attrs.html" %}>

View File

@ -1,5 +1,5 @@
{% if widget.is_initial %}{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %} {% if widget.is_initial %}{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %}
<input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}" /> <input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}">
<label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label>{% endif %}<br /> <label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label>{% endif %}<br>
{{ widget.input_text }}:{% endif %} {{ widget.input_text }}:{% endif %}
<input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %} /> <input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>

View File

@ -1 +1 @@
<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} /> <input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %}>

View File

@ -74,7 +74,7 @@ class Media:
media = sorted(self._css) media = sorted(self._css)
return chain.from_iterable([ return chain.from_iterable([
format_html( format_html(
'<link href="{}" type="text/css" media="{}" rel="stylesheet" />', '<link href="{}" type="text/css" media="{}" rel="stylesheet">',
self.absolute_path(path), medium self.absolute_path(path), medium
) for path in self._css[medium] ) for path in self._css[medium]
] for medium in media) ] for medium in media)

View File

@ -6,7 +6,7 @@ from django.utils.safestring import SafeText
def csrf_input(request): def csrf_input(request):
return format_html( return format_html(
'<input type="hidden" name="csrfmiddlewaretoken" value="{}" />', '<input type="hidden" name="csrfmiddlewaretoken" value="{}">',
get_token(request)) get_token(request))

View File

@ -404,7 +404,7 @@ def force_escape(value):
def linebreaks_filter(value, autoescape=True): def linebreaks_filter(value, autoescape=True):
""" """
Replace line breaks in plain text with appropriate HTML; a single Replace line breaks in plain text with appropriate HTML; a single
newline becomes an HTML line break (``<br />``) and a new line newline becomes an HTML line break (``<br>``) and a new line
followed by a blank line becomes a paragraph break (``</p>``). followed by a blank line becomes a paragraph break (``</p>``).
""" """
autoescape = autoescape and not isinstance(value, SafeData) autoescape = autoescape and not isinstance(value, SafeData)
@ -416,13 +416,13 @@ def linebreaks_filter(value, autoescape=True):
def linebreaksbr(value, autoescape=True): def linebreaksbr(value, autoescape=True):
""" """
Convert all newlines in a piece of plain text to HTML line breaks Convert all newlines in a piece of plain text to HTML line breaks
(``<br />``). (``<br>``).
""" """
autoescape = autoescape and not isinstance(value, SafeData) autoescape = autoescape and not isinstance(value, SafeData)
value = normalize_newlines(value) value = normalize_newlines(value)
if autoescape: if autoescape:
value = escape(value) value = escape(value)
return mark_safe(value.replace('\n', '<br />')) return mark_safe(value.replace('\n', '<br>'))
@register.filter(is_safe=True) @register.filter(is_safe=True)

View File

@ -54,7 +54,7 @@ class CsrfTokenNode(Node):
if csrf_token == 'NOTPROVIDED': if csrf_token == 'NOTPROVIDED':
return format_html("") return format_html("")
else: else:
return format_html("<input type='hidden' name='csrfmiddlewaretoken' value='{}' />", csrf_token) return format_html("<input type='hidden' name='csrfmiddlewaretoken' value='{}'>", csrf_token)
else: else:
# It's very probable that the token is missing because of # It's very probable that the token is missing because of
# misconfiguration, so we raise a warning # misconfiguration, so we raise a warning
@ -1408,7 +1408,7 @@ def widthratio(parser, token):
For example:: For example::
<img src="bar.png" alt="Bar" <img src="bar.png" alt="Bar"
height="10" width="{% widthratio this_value max_value max_width %}" /> height="10" width="{% widthratio this_value max_value max_width %}">
If ``this_value`` is 175, ``max_value`` is 200, and ``max_width`` is 100, If ``this_value`` is 175, ``max_value`` is 200, and ``max_width`` is 100,
the image in the above example will be 88 pixels wide the image in the above example will be 88 pixels wide

View File

@ -118,7 +118,7 @@ class Element:
output += ''.join(str(c) for c in self.children) output += ''.join(str(c) for c in self.children)
output += '\n</%s>' % self.name output += '\n</%s>' % self.name
else: else:
output += ' />' output += '>'
return output return output
def __repr__(self): def __repr__(self):

View File

@ -124,13 +124,13 @@ def format_html_join(sep, format_string, args_generator):
@keep_lazy_text @keep_lazy_text
def linebreaks(value, autoescape=False): def linebreaks(value, autoescape=False):
"""Convert newlines into <p> and <br />s.""" """Convert newlines into <p> and <br>s."""
value = normalize_newlines(value) value = normalize_newlines(value)
paras = re.split('\n{2,}', str(value)) paras = re.split('\n{2,}', str(value))
if autoescape: if autoescape:
paras = ['<p>%s</p>' % escape(p).replace('\n', '<br />') for p in paras] paras = ['<p>%s</p>' % escape(p).replace('\n', '<br>') for p in paras]
else: else:
paras = ['<p>%s</p>' % p.replace('\n', '<br />') for p in paras] paras = ['<p>%s</p>' % p.replace('\n', '<br>') for p in paras]
return '\n\n'.join(paras) return '\n\n'.join(paras)

View File

@ -62,9 +62,9 @@ DEFAULT_DIRECTORY_INDEX_TEMPLATE = """
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Language" content="en-us" /> <meta http-equiv="Content-Language" content="en-us">
<meta name="robots" content="NONE,NOARCHIVE" /> <meta name="robots" content="NONE,NOARCHIVE">
<title>{% blocktrans %}Index of {{ directory }}{% endblocktrans %}</title> <title>{% blocktrans %}Index of {{ directory }}{% endblocktrans %}</title>
</head> </head>
<body> <body>

View File

@ -30,7 +30,7 @@ Configuring static files
.. code-block:: html+django .. code-block:: html+django
{% load static %} {% load static %}
<img src="{% static "my_app/example.jpg" %}" alt="My image"/> <img src="{% static "my_app/example.jpg" %}" alt="My image">
4. Store your static files in a folder called ``static`` in your app. For 4. Store your static files in a folder called ``static`` in your app. For
example ``my_app/static/my_app/example.jpg``. example ``my_app/static/my_app/example.jpg``.

View File

@ -535,8 +535,8 @@ Use the arrow keys to move up and down.
+++ b/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt
@@ -1065,3 +1065,13 @@ You can put several Django forms inside one ``<form>`` tag. To give each @@ -1065,3 +1065,13 @@ You can put several Django forms inside one ``<form>`` tag. To give each
>>> print(father.as_ul()) >>> print(father.as_ul())
<li><label for="id_father-first_name">First name:</label> <input type="text" name="father-first_name" id="id_father-first_name" /></li> <li><label for="id_father-first_name">First name:</label> <input type="text" name="father-first_name" id="id_father-first_name"></li>
<li><label for="id_father-last_name">Last name:</label> <input type="text" name="father-last_name" id="id_father-last_name" /></li> <li><label for="id_father-last_name">Last name:</label> <input type="text" name="father-last_name" id="id_father-last_name"></li>
+ +
+The prefix can also be specified on the form class:: +The prefix can also be specified on the form class::
+ +

View File

@ -307,7 +307,7 @@ Here's what the "base.html" template, including the use of :doc:`static files
<title>{% block title %}{% endblock %}</title> <title>{% block title %}{% endblock %}</title>
</head> </head>
<body> <body>
<img src="{% static "images/sitelogo.png" %}" alt="Logo" /> <img src="{% static "images/sitelogo.png" %}" alt="Logo">
{% block content %}{% endblock %} {% block content %}{% endblock %}
</body> </body>
</html> </html>

View File

@ -22,10 +22,10 @@ tutorial, so that the template contains an HTML ``<form>`` element:
<form action="{% url 'polls:vote' question.id %}" method="post"> <form action="{% url 'polls:vote' question.id %}" method="post">
{% csrf_token %} {% csrf_token %}
{% for choice in question.choice_set.all %} {% for choice in question.choice_set.all %}
<input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" /> <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}">
<label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br /> <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br>
{% endfor %} {% endfor %}
<input type="submit" value="Vote" /> <input type="submit" value="Vote">
</form> </form>
A quick rundown: A quick rundown:

View File

@ -70,7 +70,7 @@ Next, add the following at the top of ``polls/templates/polls/index.html``:
{% load static %} {% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" /> <link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}">
The ``{% static %}`` template tag generates the absolute URL of static files. The ``{% static %}`` template tag generates the absolute URL of static files.

View File

@ -76,7 +76,7 @@ editing content:
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
<input type="submit" value="Send message" /> <input type="submit" value="Send message">
</form> </form>
@ -132,7 +132,7 @@ editing content:
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
<input type="submit" value="Save" /> <input type="submit" value="Save">
</form> </form>
``UpdateView`` ``UpdateView``
@ -189,7 +189,7 @@ editing content:
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
<input type="submit" value="Update" /> <input type="submit" value="Update">
</form> </form>
``DeleteView`` ``DeleteView``
@ -240,5 +240,5 @@ editing content:
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
<p>Are you sure you want to delete "{{ object }}"?</p> <p>Are you sure you want to delete "{{ object }}"?</p>
<input type="submit" value="Confirm" /> <input type="submit" value="Confirm">
</form> </form>

View File

@ -1180,7 +1180,7 @@ subclass::
# for each line of the address and you want to separate each # for each line of the address and you want to separate each
# line by a linebreak # line by a linebreak
return format_html_join( return format_html_join(
mark_safe('<br/>'), mark_safe('<br>'),
'{}', '{}',
((line,) for line in instance.get_full_address()), ((line,) for line in instance.get_full_address()),
) or mark_safe("<span class='errors'>I can't determine this address.</span>") ) or mark_safe("<span class='errors'>I can't determine this address.</span>")

View File

@ -255,9 +255,9 @@ precedence::
... comment = forms.CharField() ... comment = forms.CharField()
>>> f = CommentForm(initial={'name': 'instance'}, auto_id=False) >>> f = CommentForm(initial={'name': 'instance'}, auto_id=False)
>>> print(f) >>> print(f)
<tr><th>Name:</th><td><input type="text" name="name" value="instance" required /></td></tr> <tr><th>Name:</th><td><input type="text" name="name" value="instance" required></td></tr>
<tr><th>Url:</th><td><input type="url" name="url" required /></td></tr> <tr><th>Url:</th><td><input type="url" name="url" required></td></tr>
<tr><th>Comment:</th><td><input type="text" name="comment" required /></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" required></td></tr>
.. method:: Form.get_initial_for_field(field, field_name) .. method:: Form.get_initial_for_field(field, field_name)
@ -322,10 +322,10 @@ You can alter the field of :class:`Form` instance to change the way it is
presented in the form:: presented in the form::
>>> f.as_table().split('\n')[0] >>> f.as_table().split('\n')[0]
'<tr><th>Name:</th><td><input name="name" type="text" value="instance" required /></td></tr>' '<tr><th>Name:</th><td><input name="name" type="text" value="instance" required></td></tr>'
>>> f.fields['name'].label = "Username" >>> f.fields['name'].label = "Username"
>>> f.as_table().split('\n')[0] >>> f.as_table().split('\n')[0]
'<tr><th>Username:</th><td><input name="name" type="text" value="instance" required /></td></tr>' '<tr><th>Username:</th><td><input name="name" type="text" value="instance" required></td></tr>'
Beware not to alter the ``base_fields`` attribute because this modification Beware not to alter the ``base_fields`` attribute because this modification
will influence all subsequent ``ContactForm`` instances within the same Python will influence all subsequent ``ContactForm`` instances within the same Python
@ -334,7 +334,7 @@ process::
>>> f.base_fields['name'].label = "Username" >>> f.base_fields['name'].label = "Username"
>>> another_f = CommentForm(auto_id=False) >>> another_f = CommentForm(auto_id=False)
>>> another_f.as_table().split('\n')[0] >>> another_f.as_table().split('\n')[0]
'<tr><th>Username:</th><td><input name="name" type="text" value="class" required /></td></tr>' '<tr><th>Username:</th><td><input name="name" type="text" value="class" required></td></tr>'
Accessing "clean" data Accessing "clean" data
====================== ======================
@ -438,10 +438,10 @@ simply ``print`` it::
>>> f = ContactForm() >>> f = ContactForm()
>>> print(f) >>> print(f)
<tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" required /></td></tr> <tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" required></td></tr>
<tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" required /></td></tr> <tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" required></td></tr>
<tr><th><label for="id_sender">Sender:</label></th><td><input type="email" name="sender" id="id_sender" required /></td></tr> <tr><th><label for="id_sender">Sender:</label></th><td><input type="email" name="sender" id="id_sender" required></td></tr>
<tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" /></td></tr> <tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself"></td></tr>
If the form is bound to data, the HTML output will include that data If the form is bound to data, the HTML output will include that data
appropriately. For example, if a field is represented by an appropriately. For example, if a field is represented by an
@ -455,10 +455,10 @@ include ``checked`` if appropriate::
... 'cc_myself': True} ... 'cc_myself': True}
>>> f = ContactForm(data) >>> f = ContactForm(data)
>>> print(f) >>> print(f)
<tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" value="hello" required /></td></tr> <tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" value="hello" required></td></tr>
<tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" value="Hi there" required /></td></tr> <tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" value="Hi there" required></td></tr>
<tr><th><label for="id_sender">Sender:</label></th><td><input type="email" name="sender" id="id_sender" value="foo@example.com" required /></td></tr> <tr><th><label for="id_sender">Sender:</label></th><td><input type="email" name="sender" id="id_sender" value="foo@example.com" required></td></tr>
<tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" checked /></td></tr> <tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" checked></td></tr>
This default output is a two-column HTML table, with a ``<tr>`` for each field. This default output is a two-column HTML table, with a ``<tr>`` for each field.
Notice the following: Notice the following:
@ -506,12 +506,12 @@ containing one field::
>>> f = ContactForm() >>> f = ContactForm()
>>> f.as_p() >>> f.as_p()
'<p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" required /></p>\n<p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" required /></p>\n<p><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" required /></p>\n<p><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></p>' '<p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" required></p>\n<p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" required></p>\n<p><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" required></p>\n<p><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself"></p>'
>>> print(f.as_p()) >>> print(f.as_p())
<p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" required /></p> <p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" required></p>
<p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" required /></p> <p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" required></p>
<p><label for="id_sender">Sender:</label> <input type="email" name="sender" id="id_sender" required /></p> <p><label for="id_sender">Sender:</label> <input type="email" name="sender" id="id_sender" required></p>
<p><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></p> <p><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself"></p>
``as_ul()`` ``as_ul()``
----------- -----------
@ -525,12 +525,12 @@ flexibility::
>>> f = ContactForm() >>> f = ContactForm()
>>> f.as_ul() >>> f.as_ul()
'<li><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" required /></li>\n<li><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" required /></li>\n<li><label for="id_sender">Sender:</label> <input type="email" name="sender" id="id_sender" required /></li>\n<li><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></li>' '<li><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" required></li>\n<li><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" required></li>\n<li><label for="id_sender">Sender:</label> <input type="email" name="sender" id="id_sender" required></li>\n<li><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself"></li>'
>>> print(f.as_ul()) >>> print(f.as_ul())
<li><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" required /></li> <li><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" required></li>
<li><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" required /></li> <li><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" required></li>
<li><label for="id_sender">Sender:</label> <input type="email" name="sender" id="id_sender" required /></li> <li><label for="id_sender">Sender:</label> <input type="email" name="sender" id="id_sender" required></li>
<li><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></li> <li><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself"></li>
``as_table()`` ``as_table()``
-------------- --------------
@ -543,12 +543,12 @@ it calls its ``as_table()`` method behind the scenes::
>>> f = ContactForm() >>> f = ContactForm()
>>> f.as_table() >>> f.as_table()
'<tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" required /></td></tr>\n<tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" required /></td></tr>\n<tr><th><label for="id_sender">Sender:</label></th><td><input type="email" name="sender" id="id_sender" required /></td></tr>\n<tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" /></td></tr>' '<tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" required></td></tr>\n<tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" required></td></tr>\n<tr><th><label for="id_sender">Sender:</label></th><td><input type="email" name="sender" id="id_sender" required></td></tr>\n<tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself"></td></tr>'
>>> print(f) >>> print(f)
<tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" required /></td></tr> <tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" required></td></tr>
<tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" required /></td></tr> <tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" required></td></tr>
<tr><th><label for="id_sender">Sender:</label></th><td><input type="email" name="sender" id="id_sender" required /></td></tr> <tr><th><label for="id_sender">Sender:</label></th><td><input type="email" name="sender" id="id_sender" required></td></tr>
<tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" /></td></tr> <tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself"></td></tr>
.. _ref-forms-api-styling-form-rows: .. _ref-forms-api-styling-form-rows:
@ -618,20 +618,20 @@ tags nor ``id`` attributes::
>>> f = ContactForm(auto_id=False) >>> f = ContactForm(auto_id=False)
>>> print(f.as_table()) >>> print(f.as_table())
<tr><th>Subject:</th><td><input type="text" name="subject" maxlength="100" required /></td></tr> <tr><th>Subject:</th><td><input type="text" name="subject" maxlength="100" required></td></tr>
<tr><th>Message:</th><td><input type="text" name="message" required /></td></tr> <tr><th>Message:</th><td><input type="text" name="message" required></td></tr>
<tr><th>Sender:</th><td><input type="email" name="sender" required /></td></tr> <tr><th>Sender:</th><td><input type="email" name="sender" required></td></tr>
<tr><th>Cc myself:</th><td><input type="checkbox" name="cc_myself" /></td></tr> <tr><th>Cc myself:</th><td><input type="checkbox" name="cc_myself"></td></tr>
>>> print(f.as_ul()) >>> print(f.as_ul())
<li>Subject: <input type="text" name="subject" maxlength="100" required /></li> <li>Subject: <input type="text" name="subject" maxlength="100" required></li>
<li>Message: <input type="text" name="message" required /></li> <li>Message: <input type="text" name="message" required></li>
<li>Sender: <input type="email" name="sender" required /></li> <li>Sender: <input type="email" name="sender" required></li>
<li>Cc myself: <input type="checkbox" name="cc_myself" /></li> <li>Cc myself: <input type="checkbox" name="cc_myself"></li>
>>> print(f.as_p()) >>> print(f.as_p())
<p>Subject: <input type="text" name="subject" maxlength="100" required /></p> <p>Subject: <input type="text" name="subject" maxlength="100" required></p>
<p>Message: <input type="text" name="message" required /></p> <p>Message: <input type="text" name="message" required></p>
<p>Sender: <input type="email" name="sender" required /></p> <p>Sender: <input type="email" name="sender" required></p>
<p>Cc myself: <input type="checkbox" name="cc_myself" /></p> <p>Cc myself: <input type="checkbox" name="cc_myself"></p>
If ``auto_id`` is set to ``True``, then the form output *will* include If ``auto_id`` is set to ``True``, then the form output *will* include
``<label>`` tags and will simply use the field name as its ``id`` for each form ``<label>`` tags and will simply use the field name as its ``id`` for each form
@ -639,20 +639,20 @@ field::
>>> f = ContactForm(auto_id=True) >>> f = ContactForm(auto_id=True)
>>> print(f.as_table()) >>> print(f.as_table())
<tr><th><label for="subject">Subject:</label></th><td><input id="subject" type="text" name="subject" maxlength="100" required /></td></tr> <tr><th><label for="subject">Subject:</label></th><td><input id="subject" type="text" name="subject" maxlength="100" required></td></tr>
<tr><th><label for="message">Message:</label></th><td><input type="text" name="message" id="message" required /></td></tr> <tr><th><label for="message">Message:</label></th><td><input type="text" name="message" id="message" required></td></tr>
<tr><th><label for="sender">Sender:</label></th><td><input type="email" name="sender" id="sender" required /></td></tr> <tr><th><label for="sender">Sender:</label></th><td><input type="email" name="sender" id="sender" required></td></tr>
<tr><th><label for="cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="cc_myself" /></td></tr> <tr><th><label for="cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="cc_myself"></td></tr>
>>> print(f.as_ul()) >>> print(f.as_ul())
<li><label for="subject">Subject:</label> <input id="subject" type="text" name="subject" maxlength="100" required /></li> <li><label for="subject">Subject:</label> <input id="subject" type="text" name="subject" maxlength="100" required></li>
<li><label for="message">Message:</label> <input type="text" name="message" id="message" required /></li> <li><label for="message">Message:</label> <input type="text" name="message" id="message" required></li>
<li><label for="sender">Sender:</label> <input type="email" name="sender" id="sender" required /></li> <li><label for="sender">Sender:</label> <input type="email" name="sender" id="sender" required></li>
<li><label for="cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="cc_myself" /></li> <li><label for="cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="cc_myself"></li>
>>> print(f.as_p()) >>> print(f.as_p())
<p><label for="subject">Subject:</label> <input id="subject" type="text" name="subject" maxlength="100" required /></p> <p><label for="subject">Subject:</label> <input id="subject" type="text" name="subject" maxlength="100" required></p>
<p><label for="message">Message:</label> <input type="text" name="message" id="message" required /></p> <p><label for="message">Message:</label> <input type="text" name="message" id="message" required></p>
<p><label for="sender">Sender:</label> <input type="email" name="sender" id="sender" required /></p> <p><label for="sender">Sender:</label> <input type="email" name="sender" id="sender" required></p>
<p><label for="cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="cc_myself" /></p> <p><label for="cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="cc_myself"></p>
If ``auto_id`` is set to a string containing the format character ``'%s'``, If ``auto_id`` is set to a string containing the format character ``'%s'``,
then the form output will include ``<label>`` tags, and will generate ``id`` then the form output will include ``<label>`` tags, and will generate ``id``
@ -662,20 +662,20 @@ attributes based on the format string. For example, for a format string
>>> f = ContactForm(auto_id='id_for_%s') >>> f = ContactForm(auto_id='id_for_%s')
>>> print(f.as_table()) >>> print(f.as_table())
<tr><th><label for="id_for_subject">Subject:</label></th><td><input id="id_for_subject" type="text" name="subject" maxlength="100" required /></td></tr> <tr><th><label for="id_for_subject">Subject:</label></th><td><input id="id_for_subject" type="text" name="subject" maxlength="100" required></td></tr>
<tr><th><label for="id_for_message">Message:</label></th><td><input type="text" name="message" id="id_for_message" required /></td></tr> <tr><th><label for="id_for_message">Message:</label></th><td><input type="text" name="message" id="id_for_message" required></td></tr>
<tr><th><label for="id_for_sender">Sender:</label></th><td><input type="email" name="sender" id="id_for_sender" required /></td></tr> <tr><th><label for="id_for_sender">Sender:</label></th><td><input type="email" name="sender" id="id_for_sender" required></td></tr>
<tr><th><label for="id_for_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></td></tr> <tr><th><label for="id_for_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_for_cc_myself"></td></tr>
>>> print(f.as_ul()) >>> print(f.as_ul())
<li><label for="id_for_subject">Subject:</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" required /></li> <li><label for="id_for_subject">Subject:</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" required></li>
<li><label for="id_for_message">Message:</label> <input type="text" name="message" id="id_for_message" required /></li> <li><label for="id_for_message">Message:</label> <input type="text" name="message" id="id_for_message" required></li>
<li><label for="id_for_sender">Sender:</label> <input type="email" name="sender" id="id_for_sender" required /></li> <li><label for="id_for_sender">Sender:</label> <input type="email" name="sender" id="id_for_sender" required></li>
<li><label for="id_for_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></li> <li><label for="id_for_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself"></li>
>>> print(f.as_p()) >>> print(f.as_p())
<p><label for="id_for_subject">Subject:</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" required /></p> <p><label for="id_for_subject">Subject:</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" required></p>
<p><label for="id_for_message">Message:</label> <input type="text" name="message" id="id_for_message" required /></p> <p><label for="id_for_message">Message:</label> <input type="text" name="message" id="id_for_message" required></p>
<p><label for="id_for_sender">Sender:</label> <input type="email" name="sender" id="id_for_sender" required /></p> <p><label for="id_for_sender">Sender:</label> <input type="email" name="sender" id="id_for_sender" required></p>
<p><label for="id_for_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></p> <p><label for="id_for_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself"></p>
If ``auto_id`` is set to any other true value -- such as a string that doesn't If ``auto_id`` is set to any other true value -- such as a string that doesn't
include ``%s`` -- then the library will act as if ``auto_id`` is ``True``. include ``%s`` -- then the library will act as if ``auto_id`` is ``True``.
@ -692,16 +692,16 @@ It's possible to customize that character, or omit it entirely, using the
>>> f = ContactForm(auto_id='id_for_%s', label_suffix='') >>> f = ContactForm(auto_id='id_for_%s', label_suffix='')
>>> print(f.as_ul()) >>> print(f.as_ul())
<li><label for="id_for_subject">Subject</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" required /></li> <li><label for="id_for_subject">Subject</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" required></li>
<li><label for="id_for_message">Message</label> <input type="text" name="message" id="id_for_message" required /></li> <li><label for="id_for_message">Message</label> <input type="text" name="message" id="id_for_message" required></li>
<li><label for="id_for_sender">Sender</label> <input type="email" name="sender" id="id_for_sender" required /></li> <li><label for="id_for_sender">Sender</label> <input type="email" name="sender" id="id_for_sender" required></li>
<li><label for="id_for_cc_myself">Cc myself</label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></li> <li><label for="id_for_cc_myself">Cc myself</label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself"></li>
>>> f = ContactForm(auto_id='id_for_%s', label_suffix=' ->') >>> f = ContactForm(auto_id='id_for_%s', label_suffix=' ->')
>>> print(f.as_ul()) >>> print(f.as_ul())
<li><label for="id_for_subject">Subject -></label> <input id="id_for_subject" type="text" name="subject" maxlength="100" required /></li> <li><label for="id_for_subject">Subject -></label> <input id="id_for_subject" type="text" name="subject" maxlength="100" required></li>
<li><label for="id_for_message">Message -></label> <input type="text" name="message" id="id_for_message" required /></li> <li><label for="id_for_message">Message -></label> <input type="text" name="message" id="id_for_message" required></li>
<li><label for="id_for_sender">Sender -></label> <input type="email" name="sender" id="id_for_sender" required /></li> <li><label for="id_for_sender">Sender -></label> <input type="email" name="sender" id="id_for_sender" required></li>
<li><label for="id_for_cc_myself">Cc myself -></label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></li> <li><label for="id_for_cc_myself">Cc myself -></label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself"></li>
Note that the label suffix is added only if the last character of the Note that the label suffix is added only if the last character of the
label isn't a punctuation character (in English, those are ``.``, ``!``, ``?`` label isn't a punctuation character (in English, those are ``.``, ``!``, ``?``
@ -788,22 +788,22 @@ method you're using::
... 'cc_myself': True} ... 'cc_myself': True}
>>> f = ContactForm(data, auto_id=False) >>> f = ContactForm(data, auto_id=False)
>>> print(f.as_table()) >>> print(f.as_table())
<tr><th>Subject:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="subject" maxlength="100" required /></td></tr> <tr><th>Subject:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="subject" maxlength="100" required></td></tr>
<tr><th>Message:</th><td><input type="text" name="message" value="Hi there" required /></td></tr> <tr><th>Message:</th><td><input type="text" name="message" value="Hi there" required></td></tr>
<tr><th>Sender:</th><td><ul class="errorlist"><li>Enter a valid email address.</li></ul><input type="email" name="sender" value="invalid email address" required /></td></tr> <tr><th>Sender:</th><td><ul class="errorlist"><li>Enter a valid email address.</li></ul><input type="email" name="sender" value="invalid email address" required></td></tr>
<tr><th>Cc myself:</th><td><input checked type="checkbox" name="cc_myself" /></td></tr> <tr><th>Cc myself:</th><td><input checked type="checkbox" name="cc_myself"></td></tr>
>>> print(f.as_ul()) >>> print(f.as_ul())
<li><ul class="errorlist"><li>This field is required.</li></ul>Subject: <input type="text" name="subject" maxlength="100" required /></li> <li><ul class="errorlist"><li>This field is required.</li></ul>Subject: <input type="text" name="subject" maxlength="100" required></li>
<li>Message: <input type="text" name="message" value="Hi there" required /></li> <li>Message: <input type="text" name="message" value="Hi there" required></li>
<li><ul class="errorlist"><li>Enter a valid email address.</li></ul>Sender: <input type="email" name="sender" value="invalid email address" required /></li> <li><ul class="errorlist"><li>Enter a valid email address.</li></ul>Sender: <input type="email" name="sender" value="invalid email address" required></li>
<li>Cc myself: <input checked type="checkbox" name="cc_myself" /></li> <li>Cc myself: <input checked type="checkbox" name="cc_myself"></li>
>>> print(f.as_p()) >>> print(f.as_p())
<p><ul class="errorlist"><li>This field is required.</li></ul></p> <p><ul class="errorlist"><li>This field is required.</li></ul></p>
<p>Subject: <input type="text" name="subject" maxlength="100" required /></p> <p>Subject: <input type="text" name="subject" maxlength="100" required></p>
<p>Message: <input type="text" name="message" value="Hi there" required /></p> <p>Message: <input type="text" name="message" value="Hi there" required></p>
<p><ul class="errorlist"><li>Enter a valid email address.</li></ul></p> <p><ul class="errorlist"><li>Enter a valid email address.</li></ul></p>
<p>Sender: <input type="email" name="sender" value="invalid email address" required /></p> <p>Sender: <input type="email" name="sender" value="invalid email address" required></p>
<p>Cc myself: <input checked type="checkbox" name="cc_myself" /></p> <p>Cc myself: <input checked type="checkbox" name="cc_myself"></p>
.. _ref-forms-error-list-format: .. _ref-forms-error-list-format:
@ -824,11 +824,11 @@ pass that in at construction time::
>>> f = ContactForm(data, auto_id=False, error_class=DivErrorList) >>> f = ContactForm(data, auto_id=False, error_class=DivErrorList)
>>> f.as_p() >>> f.as_p()
<div class="errorlist"><div class="error">This field is required.</div></div> <div class="errorlist"><div class="error">This field is required.</div></div>
<p>Subject: <input type="text" name="subject" maxlength="100" required /></p> <p>Subject: <input type="text" name="subject" maxlength="100" required></p>
<p>Message: <input type="text" name="message" value="Hi there" required /></p> <p>Message: <input type="text" name="message" value="Hi there" required></p>
<div class="errorlist"><div class="error">Enter a valid email address.</div></div> <div class="errorlist"><div class="error">Enter a valid email address.</div></div>
<p>Sender: <input type="email" name="sender" value="invalid email address" required /></p> <p>Sender: <input type="email" name="sender" value="invalid email address" required></p>
<p>Cc myself: <input checked type="checkbox" name="cc_myself" /></p> <p>Cc myself: <input checked type="checkbox" name="cc_myself"></p>
More granular output More granular output
==================== ====================
@ -848,25 +848,25 @@ using the field's name as the key::
>>> form = ContactForm() >>> form = ContactForm()
>>> print(form['subject']) >>> print(form['subject'])
<input id="id_subject" type="text" name="subject" maxlength="100" required /> <input id="id_subject" type="text" name="subject" maxlength="100" required>
To retrieve all ``BoundField`` objects, iterate the form:: To retrieve all ``BoundField`` objects, iterate the form::
>>> form = ContactForm() >>> form = ContactForm()
>>> for boundfield in form: print(boundfield) >>> for boundfield in form: print(boundfield)
<input id="id_subject" type="text" name="subject" maxlength="100" required /> <input id="id_subject" type="text" name="subject" maxlength="100" required>
<input type="text" name="message" id="id_message" required /> <input type="text" name="message" id="id_message" required>
<input type="email" name="sender" id="id_sender" required /> <input type="email" name="sender" id="id_sender" required>
<input type="checkbox" name="cc_myself" id="id_cc_myself" /> <input type="checkbox" name="cc_myself" id="id_cc_myself">
The field-specific output honors the form object's ``auto_id`` setting:: The field-specific output honors the form object's ``auto_id`` setting::
>>> f = ContactForm(auto_id=False) >>> f = ContactForm(auto_id=False)
>>> print(f['message']) >>> print(f['message'])
<input type="text" name="message" required /> <input type="text" name="message" required>
>>> f = ContactForm(auto_id='id_%s') >>> f = ContactForm(auto_id='id_%s')
>>> print(f['message']) >>> print(f['message'])
<input type="text" name="message" id="id_message" required /> <input type="text" name="message" id="id_message" required>
Attributes of ``BoundField`` Attributes of ``BoundField``
---------------------------- ----------------------------
@ -897,7 +897,7 @@ Attributes of ``BoundField``
>>> data = {'subject': 'hi', 'message': '', 'sender': '', 'cc_myself': ''} >>> data = {'subject': 'hi', 'message': '', 'sender': '', 'cc_myself': ''}
>>> f = ContactForm(data, auto_id=False) >>> f = ContactForm(data, auto_id=False)
>>> print(f['message']) >>> print(f['message'])
<input type="text" name="message" required /> <input type="text" name="message" required>
>>> f['message'].errors >>> f['message'].errors
['This field is required.'] ['This field is required.']
>>> print(f['message'].errors) >>> print(f['message'].errors)
@ -949,7 +949,7 @@ Attributes of ``BoundField``
.. code-block:: html .. code-block:: html
<label for="myFIELD">...</label><input id="myFIELD" type="text" name="my_field" required /> <label for="myFIELD">...</label><input id="myFIELD" type="text" name="my_field" required>
.. attribute:: BoundField.is_hidden .. attribute:: BoundField.is_hidden
@ -1168,11 +1168,11 @@ fields are ordered first::
... priority = forms.CharField() ... priority = forms.CharField()
>>> f = ContactFormWithPriority(auto_id=False) >>> f = ContactFormWithPriority(auto_id=False)
>>> print(f.as_ul()) >>> print(f.as_ul())
<li>Subject: <input type="text" name="subject" maxlength="100" required /></li> <li>Subject: <input type="text" name="subject" maxlength="100" required></li>
<li>Message: <input type="text" name="message" required /></li> <li>Message: <input type="text" name="message" required></li>
<li>Sender: <input type="email" name="sender" required /></li> <li>Sender: <input type="email" name="sender" required></li>
<li>Cc myself: <input type="checkbox" name="cc_myself" /></li> <li>Cc myself: <input type="checkbox" name="cc_myself"></li>
<li>Priority: <input type="text" name="priority" required /></li> <li>Priority: <input type="text" name="priority" required></li>
It's possible to subclass multiple forms, treating forms as mixins. In this It's possible to subclass multiple forms, treating forms as mixins. In this
example, ``BeatleForm`` subclasses both ``PersonForm`` and ``InstrumentForm`` example, ``BeatleForm`` subclasses both ``PersonForm`` and ``InstrumentForm``
@ -1189,10 +1189,10 @@ classes::
... haircut_type = forms.CharField() ... haircut_type = forms.CharField()
>>> b = BeatleForm(auto_id=False) >>> b = BeatleForm(auto_id=False)
>>> print(b.as_ul()) >>> print(b.as_ul())
<li>First name: <input type="text" name="first_name" required /></li> <li>First name: <input type="text" name="first_name" required></li>
<li>Last name: <input type="text" name="last_name" required /></li> <li>Last name: <input type="text" name="last_name" required></li>
<li>Instrument: <input type="text" name="instrument" required /></li> <li>Instrument: <input type="text" name="instrument" required></li>
<li>Haircut type: <input type="text" name="haircut_type" required /></li> <li>Haircut type: <input type="text" name="haircut_type" required></li>
It's possible to declaratively remove a ``Field`` inherited from a parent class It's possible to declaratively remove a ``Field`` inherited from a parent class
by setting the name of the field to ``None`` on the subclass. For example:: by setting the name of the field to ``None`` on the subclass. For example::
@ -1222,11 +1222,11 @@ You can put several Django forms inside one ``<form>`` tag. To give each
>>> mother = PersonForm(prefix="mother") >>> mother = PersonForm(prefix="mother")
>>> father = PersonForm(prefix="father") >>> father = PersonForm(prefix="father")
>>> print(mother.as_ul()) >>> print(mother.as_ul())
<li><label for="id_mother-first_name">First name:</label> <input type="text" name="mother-first_name" id="id_mother-first_name" required /></li> <li><label for="id_mother-first_name">First name:</label> <input type="text" name="mother-first_name" id="id_mother-first_name" required></li>
<li><label for="id_mother-last_name">Last name:</label> <input type="text" name="mother-last_name" id="id_mother-last_name" required /></li> <li><label for="id_mother-last_name">Last name:</label> <input type="text" name="mother-last_name" id="id_mother-last_name" required></li>
>>> print(father.as_ul()) >>> print(father.as_ul())
<li><label for="id_father-first_name">First name:</label> <input type="text" name="father-first_name" id="id_father-first_name" required /></li> <li><label for="id_father-first_name">First name:</label> <input type="text" name="father-first_name" id="id_father-first_name" required></li>
<li><label for="id_father-last_name">Last name:</label> <input type="text" name="father-last_name" id="id_father-last_name" required /></li> <li><label for="id_father-last_name">Last name:</label> <input type="text" name="father-last_name" id="id_father-last_name" required></li>
The prefix can also be specified on the form class:: The prefix can also be specified on the form class::

View File

@ -119,9 +119,9 @@ We've specified ``auto_id=False`` to simplify the output::
... comment = forms.CharField() ... comment = forms.CharField()
>>> f = CommentForm(auto_id=False) >>> f = CommentForm(auto_id=False)
>>> print(f) >>> print(f)
<tr><th>Your name:</th><td><input type="text" name="name" required /></td></tr> <tr><th>Your name:</th><td><input type="text" name="name" required></td></tr>
<tr><th>Your website:</th><td><input type="url" name="url" /></td></tr> <tr><th>Your website:</th><td><input type="url" name="url"></td></tr>
<tr><th>Comment:</th><td><input type="text" name="comment" required /></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" required></td></tr>
``label_suffix`` ``label_suffix``
---------------- ----------------
@ -137,9 +137,9 @@ The ``label_suffix`` argument lets you override the form's
... captcha_answer = forms.IntegerField(label='2 + 2', label_suffix=' =') ... captcha_answer = forms.IntegerField(label='2 + 2', label_suffix=' =')
>>> f = ContactForm(label_suffix='?') >>> f = ContactForm(label_suffix='?')
>>> print(f.as_p()) >>> print(f.as_p())
<p><label for="id_age">Age?</label> <input id="id_age" name="age" type="number" required /></p> <p><label for="id_age">Age?</label> <input id="id_age" name="age" type="number" required></p>
<p><label for="id_nationality">Nationality?</label> <input id="id_nationality" name="nationality" type="text" required /></p> <p><label for="id_nationality">Nationality?</label> <input id="id_nationality" name="nationality" type="text" required></p>
<p><label for="id_captcha_answer">2 + 2 =</label> <input id="id_captcha_answer" name="captcha_answer" type="number" required /></p> <p><label for="id_captcha_answer">2 + 2 =</label> <input id="id_captcha_answer" name="captcha_answer" type="number" required></p>
``initial`` ``initial``
----------- -----------
@ -161,9 +161,9 @@ field is initialized to a particular value. For example::
... comment = forms.CharField() ... comment = forms.CharField()
>>> f = CommentForm(auto_id=False) >>> f = CommentForm(auto_id=False)
>>> print(f) >>> print(f)
<tr><th>Name:</th><td><input type="text" name="name" value="Your name" required /></td></tr> <tr><th>Name:</th><td><input type="text" name="name" value="Your name" required></td></tr>
<tr><th>Url:</th><td><input type="url" name="url" value="http://" required /></td></tr> <tr><th>Url:</th><td><input type="url" name="url" value="http://" required></td></tr>
<tr><th>Comment:</th><td><input type="text" name="comment" required /></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" required></td></tr>
You may be thinking, why not just pass a dictionary of the initial values as You may be thinking, why not just pass a dictionary of the initial values as
data when displaying the form? Well, if you do that, you'll trigger validation, data when displaying the form? Well, if you do that, you'll trigger validation,
@ -176,9 +176,9 @@ and the HTML output will include any validation errors::
>>> default_data = {'name': 'Your name', 'url': 'http://'} >>> default_data = {'name': 'Your name', 'url': 'http://'}
>>> f = CommentForm(default_data, auto_id=False) >>> f = CommentForm(default_data, auto_id=False)
>>> print(f) >>> print(f)
<tr><th>Name:</th><td><input type="text" name="name" value="Your name" required /></td></tr> <tr><th>Name:</th><td><input type="text" name="name" value="Your name" required></td></tr>
<tr><th>Url:</th><td><ul class="errorlist"><li>Enter a valid URL.</li></ul><input type="url" name="url" value="http://" required /></td></tr> <tr><th>Url:</th><td><ul class="errorlist"><li>Enter a valid URL.</li></ul><input type="url" name="url" value="http://" required></td></tr>
<tr><th>Comment:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="comment" required /></td></tr> <tr><th>Comment:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="comment" required></td></tr>
This is why ``initial`` values are only displayed for unbound forms. For bound This is why ``initial`` values are only displayed for unbound forms. For bound
forms, the HTML output will use the bound data. forms, the HTML output will use the bound data.
@ -205,7 +205,7 @@ Instead of a constant, you can also pass any callable::
>>> class DateForm(forms.Form): >>> class DateForm(forms.Form):
... day = forms.DateField(initial=datetime.date.today) ... day = forms.DateField(initial=datetime.date.today)
>>> print(DateForm()) >>> print(DateForm())
<tr><th>Day:</th><td><input type="text" name="day" value="12/23/2008" required /><td></tr> <tr><th>Day:</th><td><input type="text" name="day" value="12/23/2008" required><td></tr>
The callable will be evaluated only when the unbound form is displayed, not when it is defined. The callable will be evaluated only when the unbound form is displayed, not when it is defined.
@ -241,20 +241,20 @@ fields. We've specified ``auto_id=False`` to simplify the output::
... cc_myself = forms.BooleanField(required=False) ... cc_myself = forms.BooleanField(required=False)
>>> f = HelpTextContactForm(auto_id=False) >>> f = HelpTextContactForm(auto_id=False)
>>> print(f.as_table()) >>> print(f.as_table())
<tr><th>Subject:</th><td><input type="text" name="subject" maxlength="100" required /><br /><span class="helptext">100 characters max.</span></td></tr> <tr><th>Subject:</th><td><input type="text" name="subject" maxlength="100" required><br><span class="helptext">100 characters max.</span></td></tr>
<tr><th>Message:</th><td><input type="text" name="message" required /></td></tr> <tr><th>Message:</th><td><input type="text" name="message" required></td></tr>
<tr><th>Sender:</th><td><input type="email" name="sender" required /><br />A valid email address, please.</td></tr> <tr><th>Sender:</th><td><input type="email" name="sender" required><br>A valid email address, please.</td></tr>
<tr><th>Cc myself:</th><td><input type="checkbox" name="cc_myself" /></td></tr> <tr><th>Cc myself:</th><td><input type="checkbox" name="cc_myself"></td></tr>
>>> print(f.as_ul())) >>> print(f.as_ul()))
<li>Subject: <input type="text" name="subject" maxlength="100" required /> <span class="helptext">100 characters max.</span></li> <li>Subject: <input type="text" name="subject" maxlength="100" required> <span class="helptext">100 characters max.</span></li>
<li>Message: <input type="text" name="message" required /></li> <li>Message: <input type="text" name="message" required></li>
<li>Sender: <input type="email" name="sender" required /> A valid email address, please.</li> <li>Sender: <input type="email" name="sender" required> A valid email address, please.</li>
<li>Cc myself: <input type="checkbox" name="cc_myself" /></li> <li>Cc myself: <input type="checkbox" name="cc_myself"></li>
>>> print(f.as_p()) >>> print(f.as_p())
<p>Subject: <input type="text" name="subject" maxlength="100" required /> <span class="helptext">100 characters max.</span></p> <p>Subject: <input type="text" name="subject" maxlength="100" required> <span class="helptext">100 characters max.</span></p>
<p>Message: <input type="text" name="message" required /></p> <p>Message: <input type="text" name="message" required></p>
<p>Sender: <input type="email" name="sender" required /> A valid email address, please.</p> <p>Sender: <input type="email" name="sender" required> A valid email address, please.</p>
<p>Cc myself: <input type="checkbox" name="cc_myself" /></p> <p>Cc myself: <input type="checkbox" name="cc_myself"></p>
``error_messages`` ``error_messages``
------------------ ------------------

View File

@ -142,9 +142,9 @@ provided for each widget will be rendered exactly the same::
>>> f = CommentForm(auto_id=False) >>> f = CommentForm(auto_id=False)
>>> f.as_table() >>> f.as_table()
<tr><th>Name:</th><td><input type="text" name="name" required /></td></tr> <tr><th>Name:</th><td><input type="text" name="name" required></td></tr>
<tr><th>Url:</th><td><input type="url" name="url" required /></td></tr> <tr><th>Url:</th><td><input type="url" name="url" required></td></tr>
<tr><th>Comment:</th><td><input type="text" name="comment" required /></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" required></td></tr>
On a real Web page, you probably don't want every widget to look the same. You On a real Web page, you probably don't want every widget to look the same. You
might want a larger input element for the comment, and you might want the might want a larger input element for the comment, and you might want the
@ -161,9 +161,9 @@ Django will then include the extra attributes in the rendered output:
>>> f = CommentForm(auto_id=False) >>> f = CommentForm(auto_id=False)
>>> f.as_table() >>> f.as_table()
<tr><th>Name:</th><td><input type="text" name="name" class="special" required /></td></tr> <tr><th>Name:</th><td><input type="text" name="name" class="special" required></td></tr>
<tr><th>Url:</th><td><input type="url" name="url" required /></td></tr> <tr><th>Url:</th><td><input type="url" name="url" required></td></tr>
<tr><th>Comment:</th><td><input type="text" name="comment" size="40" required /></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" size="40" required></td></tr>
You can also set the HTML ``id`` using :attr:`~Widget.attrs`. See You can also set the HTML ``id`` using :attr:`~Widget.attrs`. See
:attr:`BoundField.id_for_label` for an example. :attr:`BoundField.id_for_label` for an example.
@ -211,18 +211,18 @@ foundation for custom widgets.
>>> from django import forms >>> from django import forms
>>> name = forms.TextInput(attrs={'size': 10, 'title': 'Your name',}) >>> name = forms.TextInput(attrs={'size': 10, 'title': 'Your name',})
>>> name.render('name', 'A name') >>> name.render('name', 'A name')
'<input title="Your name" type="text" name="name" value="A name" size="10" required />' '<input title="Your name" type="text" name="name" value="A name" size="10" required>'
If you assign a value of ``True`` or ``False`` to an attribute, If you assign a value of ``True`` or ``False`` to an attribute,
it will be rendered as an HTML5 boolean attribute:: it will be rendered as an HTML5 boolean attribute::
>>> name = forms.TextInput(attrs={'required': True}) >>> name = forms.TextInput(attrs={'required': True})
>>> name.render('name', 'A name') >>> name.render('name', 'A name')
'<input name="name" type="text" value="A name" required />' '<input name="name" type="text" value="A name" required>'
>>> >>>
>>> name = forms.TextInput(attrs={'required': False}) >>> name = forms.TextInput(attrs={'required': False})
>>> name.render('name', 'A name') >>> name.render('name', 'A name')
'<input name="name" type="text" value="A name" />' '<input name="name" type="text" value="A name">'
.. attribute:: Widget.supports_microseconds .. attribute:: Widget.supports_microseconds
@ -701,16 +701,16 @@ that specifies the template used to render each choice. For example, for the
.. code-block:: html .. code-block:: html
<div class="myradio"> <div class="myradio">
<label for="id_beatles_0"><input id="id_beatles_0" name="beatles" type="radio" value="john" required /> John</label> <label for="id_beatles_0"><input id="id_beatles_0" name="beatles" type="radio" value="john" required> John</label>
</div> </div>
<div class="myradio"> <div class="myradio">
<label for="id_beatles_1"><input id="id_beatles_1" name="beatles" type="radio" value="paul" required /> Paul</label> <label for="id_beatles_1"><input id="id_beatles_1" name="beatles" type="radio" value="paul" required> Paul</label>
</div> </div>
<div class="myradio"> <div class="myradio">
<label for="id_beatles_2"><input id="id_beatles_2" name="beatles" type="radio" value="george" required /> George</label> <label for="id_beatles_2"><input id="id_beatles_2" name="beatles" type="radio" value="george" required> George</label>
</div> </div>
<div class="myradio"> <div class="myradio">
<label for="id_beatles_3"><input id="id_beatles_3" name="beatles" type="radio" value="ringo" required /> Ringo</label> <label for="id_beatles_3"><input id="id_beatles_3" name="beatles" type="radio" value="ringo" required> Ringo</label>
</div> </div>
That included the ``<label>`` tags. To get more granular, you can use each That included the ``<label>`` tags. To get more granular, you can use each
@ -732,22 +732,22 @@ that specifies the template used to render each choice. For example, for the
<label for="id_beatles_0"> <label for="id_beatles_0">
John John
<span class="radio"><input id="id_beatles_0" name="beatles" type="radio" value="john" required /></span> <span class="radio"><input id="id_beatles_0" name="beatles" type="radio" value="john" required></span>
</label> </label>
<label for="id_beatles_1"> <label for="id_beatles_1">
Paul Paul
<span class="radio"><input id="id_beatles_1" name="beatles" type="radio" value="paul" required /></span> <span class="radio"><input id="id_beatles_1" name="beatles" type="radio" value="paul" required></span>
</label> </label>
<label for="id_beatles_2"> <label for="id_beatles_2">
George George
<span class="radio"><input id="id_beatles_2" name="beatles" type="radio" value="george" required /></span> <span class="radio"><input id="id_beatles_2" name="beatles" type="radio" value="george" required></span>
</label> </label>
<label for="id_beatles_3"> <label for="id_beatles_3">
Ringo Ringo
<span class="radio"><input id="id_beatles_3" name="beatles" type="radio" value="ringo" required /></span> <span class="radio"><input id="id_beatles_3" name="beatles" type="radio" value="ringo" required></span>
</label> </label>
If you decide not to loop over the radio buttons -- e.g., if your template If you decide not to loop over the radio buttons -- e.g., if your template

View File

@ -124,7 +124,7 @@ All attributes should be considered read-only, unless stated otherwise.
.. attribute:: HttpRequest.FILES .. attribute:: HttpRequest.FILES
A dictionary-like object containing all uploaded files. Each key in A dictionary-like object containing all uploaded files. Each key in
``FILES`` is the ``name`` from the ``<input type="file" name="" />``. Each ``FILES`` is the ``name`` from the ``<input type="file" name="">``. Each
value in ``FILES`` is an :class:`~django.core.files.uploadedfile.UploadedFile`. value in ``FILES`` is an :class:`~django.core.files.uploadedfile.UploadedFile`.
See :doc:`/topics/files` for more information. See :doc:`/topics/files` for more information.

View File

@ -1192,7 +1192,7 @@ value to a maximum value, and then applies that ratio to a constant.
For example:: For example::
<img src="bar.png" alt="Bar" <img src="bar.png" alt="Bar"
height="10" width="{% widthratio this_value max_value max_width %}" /> height="10" width="{% widthratio this_value max_value max_width %}">
If ``this_value`` is 175, ``max_value`` is 200, and ``max_width`` is 100, the If ``this_value`` is 175, ``max_value`` is 200, and ``max_width`` is 100, the
image in the above example will be 88 pixels wide image in the above example will be 88 pixels wide
@ -1832,14 +1832,14 @@ If ``value`` is ``['a', 'b', 'c', 'd']`` or ``"abcd"``, the output will be
-------------- --------------
Replaces line breaks in plain text with appropriate HTML; a single Replaces line breaks in plain text with appropriate HTML; a single
newline becomes an HTML line break (``<br />``) and a new line newline becomes an HTML line break (``<br>``) and a new line
followed by a blank line becomes a paragraph break (``</p>``). followed by a blank line becomes a paragraph break (``</p>``).
For example:: For example::
{{ value|linebreaks }} {{ value|linebreaks }}
If ``value`` is ``Joel\nis a slug``, the output will be ``<p>Joel<br />is a If ``value`` is ``Joel\nis a slug``, the output will be ``<p>Joel<br>is a
slug</p>``. slug</p>``.
.. templatefilter:: linebreaksbr .. templatefilter:: linebreaksbr
@ -1848,13 +1848,13 @@ slug</p>``.
---------------- ----------------
Converts all newlines in a piece of plain text to HTML line breaks Converts all newlines in a piece of plain text to HTML line breaks
(``<br />``). (``<br>``).
For example:: For example::
{{ value|linebreaksbr }} {{ value|linebreaksbr }}
If ``value`` is ``Joel\nis a slug``, the output will be ``Joel<br />is a If ``value`` is ``Joel\nis a slug``, the output will be ``Joel<br>is a
slug``. slug``.
.. templatefilter:: linenumbers .. templatefilter:: linenumbers
@ -2531,20 +2531,20 @@ app is installed, the tag will serve files using ``url()`` method of the
storage specified by :setting:`STATICFILES_STORAGE`. For example:: storage specified by :setting:`STATICFILES_STORAGE`. For example::
{% load static %} {% load static %}
<img src="{% static "images/hi.jpg" %}" alt="Hi!" /> <img src="{% static "images/hi.jpg" %}" alt="Hi!">
It is also able to consume standard context variables, e.g. assuming a It is also able to consume standard context variables, e.g. assuming a
``user_stylesheet`` variable is passed to the template:: ``user_stylesheet`` variable is passed to the template::
{% load static %} {% load static %}
<link rel="stylesheet" href="{% static user_stylesheet %}" type="text/css" media="screen" /> <link rel="stylesheet" href="{% static user_stylesheet %}" type="text/css" media="screen">
If you'd like to retrieve a static URL without displaying it, you can use a If you'd like to retrieve a static URL without displaying it, you can use a
slightly different call:: slightly different call::
{% load static %} {% load static %}
{% static "images/hi.jpg" as myphoto %} {% static "images/hi.jpg" as myphoto %}
<img src="{{ myphoto }}"></img> <img src="{{ myphoto }}">
.. admonition:: Using Jinja2 templates? .. admonition:: Using Jinja2 templates?
@ -2561,7 +2561,7 @@ over exactly where and how :setting:`STATIC_URL` is injected into the template,
you can use the :ttag:`get_static_prefix` template tag:: you can use the :ttag:`get_static_prefix` template tag::
{% load static %} {% load static %}
<img src="{% get_static_prefix %}images/hi.jpg" alt="Hi!" /> <img src="{% get_static_prefix %}images/hi.jpg" alt="Hi!">
There's also a second form you can use to avoid extra processing if you need There's also a second form you can use to avoid extra processing if you need
the value multiple times:: the value multiple times::
@ -2569,8 +2569,8 @@ the value multiple times::
{% load static %} {% load static %}
{% get_static_prefix as STATIC_PREFIX %} {% get_static_prefix as STATIC_PREFIX %}
<img src="{{ STATIC_PREFIX }}images/hi.jpg" alt="Hi!" /> <img src="{{ STATIC_PREFIX }}images/hi.jpg" alt="Hi!">
<img src="{{ STATIC_PREFIX }}images/hi2.jpg" alt="Hello!" /> <img src="{{ STATIC_PREFIX }}images/hi2.jpg" alt="Hello!">
.. templatetag:: get_media_prefix .. templatetag:: get_media_prefix

View File

@ -291,7 +291,7 @@ It's easiest to understand template inheritance by starting with an example::
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<link rel="stylesheet" href="style.css" /> <link rel="stylesheet" href="style.css">
<title>{% block title %}My amazing site{% endblock %}</title> <title>{% block title %}My amazing site{% endblock %}</title>
</head> </head>
@ -344,7 +344,7 @@ like::
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<link rel="stylesheet" href="style.css" /> <link rel="stylesheet" href="style.css">
<title>My amazing blog</title> <title>My amazing blog</title>
</head> </head>

View File

@ -255,6 +255,10 @@ Miscellaneous
:class:`~django.forms.SelectMultiple` widget now uses HTML5 boolean syntax :class:`~django.forms.SelectMultiple` widget now uses HTML5 boolean syntax
rather than XHTML's ``multiple="multiple"``. rather than XHTML's ``multiple="multiple"``.
* HTML rendered by form widgets no longer includes a closing slash on void
elements, e.g. ``<br>``. This is incompatible within XHTML, although some
widgets already used aspects of HTML5 such as boolean attributes.
.. _deprecated-features-2.1: .. _deprecated-features-2.1:
Features deprecated in 2.1 Features deprecated in 2.1

View File

@ -1056,8 +1056,8 @@ implementation details see :ref:`using-the-views`.
</tr> </tr>
</table> </table>
<input type="submit" value="login" /> <input type="submit" value="login">
<input type="hidden" name="next" value="{{ next }}" /> <input type="hidden" name="next" value="{{ next }}">
</form> </form>
{# Assumes you setup the password_reset view in your URLconf #} {# Assumes you setup the password_reset view in your URLconf #}

View File

@ -29,8 +29,8 @@ would with a regular form::
>>> formset = ArticleFormSet() >>> formset = ArticleFormSet()
>>> for form in formset: >>> for form in formset:
... print(form.as_table()) ... print(form.as_table())
<tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" id="id_form-0-title" /></td></tr> <tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" id="id_form-0-title"></td></tr>
<tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" id="id_form-0-pub_date" /></td></tr> <tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" id="id_form-0-pub_date"></td></tr>
As you can see it only displayed one empty form. The number of empty forms As you can see it only displayed one empty form. The number of empty forms
that is displayed is controlled by the ``extra`` parameter. By default, that is displayed is controlled by the ``extra`` parameter. By default,
@ -69,12 +69,12 @@ example::
>>> for form in formset: >>> for form in formset:
... print(form.as_table()) ... print(form.as_table())
<tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" value="Django is now open source" id="id_form-0-title" /></td></tr> <tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" value="Django is now open source" id="id_form-0-title"></td></tr>
<tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" value="2008-05-12" id="id_form-0-pub_date" /></td></tr> <tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" value="2008-05-12" id="id_form-0-pub_date"></td></tr>
<tr><th><label for="id_form-1-title">Title:</label></th><td><input type="text" name="form-1-title" id="id_form-1-title" /></td></tr> <tr><th><label for="id_form-1-title">Title:</label></th><td><input type="text" name="form-1-title" id="id_form-1-title"></td></tr>
<tr><th><label for="id_form-1-pub_date">Pub date:</label></th><td><input type="text" name="form-1-pub_date" id="id_form-1-pub_date" /></td></tr> <tr><th><label for="id_form-1-pub_date">Pub date:</label></th><td><input type="text" name="form-1-pub_date" id="id_form-1-pub_date"></td></tr>
<tr><th><label for="id_form-2-title">Title:</label></th><td><input type="text" name="form-2-title" id="id_form-2-title" /></td></tr> <tr><th><label for="id_form-2-title">Title:</label></th><td><input type="text" name="form-2-title" id="id_form-2-title"></td></tr>
<tr><th><label for="id_form-2-pub_date">Pub date:</label></th><td><input type="text" name="form-2-pub_date" id="id_form-2-pub_date" /></td></tr> <tr><th><label for="id_form-2-pub_date">Pub date:</label></th><td><input type="text" name="form-2-pub_date" id="id_form-2-pub_date"></td></tr>
There are now a total of three forms showing above. One for the initial data There are now a total of three forms showing above. One for the initial data
that was passed in and two extra forms. Also note that we are passing in a that was passed in and two extra forms. Also note that we are passing in a
@ -103,8 +103,8 @@ gives you the ability to limit the number of forms the formset will display::
>>> formset = ArticleFormSet() >>> formset = ArticleFormSet()
>>> for form in formset: >>> for form in formset:
... print(form.as_table()) ... print(form.as_table())
<tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" id="id_form-0-title" /></td></tr> <tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" id="id_form-0-title"></td></tr>
<tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" id="id_form-0-pub_date" /></td></tr> <tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" id="id_form-0-pub_date"></td></tr>
If the value of ``max_num`` is greater than the number of existing items in the If the value of ``max_num`` is greater than the number of existing items in the
initial data, up to ``extra`` additional blank forms will be added to the initial data, up to ``extra`` additional blank forms will be added to the
@ -406,15 +406,15 @@ Lets you create a formset with the ability to order::
... ]) ... ])
>>> for form in formset: >>> for form in formset:
... print(form.as_table()) ... print(form.as_table())
<tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" value="Article #1" id="id_form-0-title" /></td></tr> <tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" value="Article #1" id="id_form-0-title"></td></tr>
<tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" value="2008-05-10" id="id_form-0-pub_date" /></td></tr> <tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" value="2008-05-10" id="id_form-0-pub_date"></td></tr>
<tr><th><label for="id_form-0-ORDER">Order:</label></th><td><input type="number" name="form-0-ORDER" value="1" id="id_form-0-ORDER" /></td></tr> <tr><th><label for="id_form-0-ORDER">Order:</label></th><td><input type="number" name="form-0-ORDER" value="1" id="id_form-0-ORDER"></td></tr>
<tr><th><label for="id_form-1-title">Title:</label></th><td><input type="text" name="form-1-title" value="Article #2" id="id_form-1-title" /></td></tr> <tr><th><label for="id_form-1-title">Title:</label></th><td><input type="text" name="form-1-title" value="Article #2" id="id_form-1-title"></td></tr>
<tr><th><label for="id_form-1-pub_date">Pub date:</label></th><td><input type="text" name="form-1-pub_date" value="2008-05-11" id="id_form-1-pub_date" /></td></tr> <tr><th><label for="id_form-1-pub_date">Pub date:</label></th><td><input type="text" name="form-1-pub_date" value="2008-05-11" id="id_form-1-pub_date"></td></tr>
<tr><th><label for="id_form-1-ORDER">Order:</label></th><td><input type="number" name="form-1-ORDER" value="2" id="id_form-1-ORDER" /></td></tr> <tr><th><label for="id_form-1-ORDER">Order:</label></th><td><input type="number" name="form-1-ORDER" value="2" id="id_form-1-ORDER"></td></tr>
<tr><th><label for="id_form-2-title">Title:</label></th><td><input type="text" name="form-2-title" id="id_form-2-title" /></td></tr> <tr><th><label for="id_form-2-title">Title:</label></th><td><input type="text" name="form-2-title" id="id_form-2-title"></td></tr>
<tr><th><label for="id_form-2-pub_date">Pub date:</label></th><td><input type="text" name="form-2-pub_date" id="id_form-2-pub_date" /></td></tr> <tr><th><label for="id_form-2-pub_date">Pub date:</label></th><td><input type="text" name="form-2-pub_date" id="id_form-2-pub_date"></td></tr>
<tr><th><label for="id_form-2-ORDER">Order:</label></th><td><input type="number" name="form-2-ORDER" id="id_form-2-ORDER" /></td></tr> <tr><th><label for="id_form-2-ORDER">Order:</label></th><td><input type="number" name="form-2-ORDER" id="id_form-2-ORDER"></td></tr>
This adds an additional field to each form. This new field is named ``ORDER`` This adds an additional field to each form. This new field is named ``ORDER``
and is an ``forms.IntegerField``. For the forms that came from the initial and is an ``forms.IntegerField``. For the forms that came from the initial
@ -466,15 +466,15 @@ Lets you create a formset with the ability to select forms for deletion::
... ]) ... ])
>>> for form in formset: >>> for form in formset:
... print(form.as_table()) ... print(form.as_table())
<tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" value="Article #1" id="id_form-0-title" /></td></tr> <tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" value="Article #1" id="id_form-0-title"></td></tr>
<tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" value="2008-05-10" id="id_form-0-pub_date" /></td></tr> <tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" value="2008-05-10" id="id_form-0-pub_date"></td></tr>
<tr><th><label for="id_form-0-DELETE">Delete:</label></th><td><input type="checkbox" name="form-0-DELETE" id="id_form-0-DELETE" /></td></tr> <tr><th><label for="id_form-0-DELETE">Delete:</label></th><td><input type="checkbox" name="form-0-DELETE" id="id_form-0-DELETE"></td></tr>
<tr><th><label for="id_form-1-title">Title:</label></th><td><input type="text" name="form-1-title" value="Article #2" id="id_form-1-title" /></td></tr> <tr><th><label for="id_form-1-title">Title:</label></th><td><input type="text" name="form-1-title" value="Article #2" id="id_form-1-title"></td></tr>
<tr><th><label for="id_form-1-pub_date">Pub date:</label></th><td><input type="text" name="form-1-pub_date" value="2008-05-11" id="id_form-1-pub_date" /></td></tr> <tr><th><label for="id_form-1-pub_date">Pub date:</label></th><td><input type="text" name="form-1-pub_date" value="2008-05-11" id="id_form-1-pub_date"></td></tr>
<tr><th><label for="id_form-1-DELETE">Delete:</label></th><td><input type="checkbox" name="form-1-DELETE" id="id_form-1-DELETE" /></td></tr> <tr><th><label for="id_form-1-DELETE">Delete:</label></th><td><input type="checkbox" name="form-1-DELETE" id="id_form-1-DELETE"></td></tr>
<tr><th><label for="id_form-2-title">Title:</label></th><td><input type="text" name="form-2-title" id="id_form-2-title" /></td></tr> <tr><th><label for="id_form-2-title">Title:</label></th><td><input type="text" name="form-2-title" id="id_form-2-title"></td></tr>
<tr><th><label for="id_form-2-pub_date">Pub date:</label></th><td><input type="text" name="form-2-pub_date" id="id_form-2-pub_date" /></td></tr> <tr><th><label for="id_form-2-pub_date">Pub date:</label></th><td><input type="text" name="form-2-pub_date" id="id_form-2-pub_date"></td></tr>
<tr><th><label for="id_form-2-DELETE">Delete:</label></th><td><input type="checkbox" name="form-2-DELETE" id="id_form-2-DELETE" /></td></tr> <tr><th><label for="id_form-2-DELETE">Delete:</label></th><td><input type="checkbox" name="form-2-DELETE" id="id_form-2-DELETE"></td></tr>
Similar to ``can_order`` this adds a new field to each form named ``DELETE`` Similar to ``can_order`` this adds a new field to each form named ``DELETE``
and is a ``forms.BooleanField``. When data comes through marking any of the and is a ``forms.BooleanField``. When data comes through marking any of the
@ -540,9 +540,9 @@ default fields/attributes of the order and deletion fields::
>>> formset = ArticleFormSet() >>> formset = ArticleFormSet()
>>> for form in formset: >>> for form in formset:
... print(form.as_table()) ... print(form.as_table())
<tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" id="id_form-0-title" /></td></tr> <tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" id="id_form-0-title"></td></tr>
<tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" id="id_form-0-pub_date" /></td></tr> <tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" id="id_form-0-pub_date"></td></tr>
<tr><th><label for="id_form-0-my_field">My field:</label></th><td><input type="text" name="form-0-my_field" id="id_form-0-my_field" /></td></tr> <tr><th><label for="id_form-0-my_field">My field:</label></th><td><input type="text" name="form-0-my_field" id="id_form-0-my_field"></td></tr>
.. _custom-formset-form-kwargs: .. _custom-formset-form-kwargs:
@ -592,14 +592,14 @@ For example, in the default case, you might see:
.. code-block:: html .. code-block:: html
<label for="id_form-0-title">Title:</label> <label for="id_form-0-title">Title:</label>
<input type="text" name="form-0-title" id="id_form-0-title" /> <input type="text" name="form-0-title" id="id_form-0-title">
But with ``ArticleFormset(prefix='article')`` that becomes: But with ``ArticleFormset(prefix='article')`` that becomes:
.. code-block:: html .. code-block:: html
<label for="id_article-0-title">Title:</label> <label for="id_article-0-title">Title:</label>
<input type="text" name="article-0-title" id="id_article-0-title" /> <input type="text" name="article-0-title" id="id_article-0-title">
This is useful if you want to :ref:`use more than one formset in a view This is useful if you want to :ref:`use more than one formset in a view
<multiple-formsets-in-view>`. <multiple-formsets-in-view>`.

View File

@ -259,7 +259,7 @@ The whole form, when rendered for the first time, will look like:
.. code-block:: html+django .. code-block:: html+django
<label for="your_name">Your name: </label> <label for="your_name">Your name: </label>
<input id="your_name" type="text" name="your_name" maxlength="100" required /> <input id="your_name" type="text" name="your_name" maxlength="100" required>
Note that it **does not** include the ``<form>`` tags, or a submit button. Note that it **does not** include the ``<form>`` tags, or a submit button.
We'll have to provide those ourselves in the template. We'll have to provide those ourselves in the template.
@ -334,7 +334,7 @@ is:
<form action="/your-name/" method="post"> <form action="/your-name/" method="post">
{% csrf_token %} {% csrf_token %}
{{ form }} {{ form }}
<input type="submit" value="Submit" /> <input type="submit" value="Submit">
</form> </form>
All the form's fields and their attributes will be unpacked into HTML markup All the form's fields and their attributes will be unpacked into HTML markup
@ -512,13 +512,13 @@ Here's the output of ``{{ form.as_p }}`` for our ``ContactForm`` instance:
.. code-block:: html+django .. code-block:: html+django
<p><label for="id_subject">Subject:</label> <p><label for="id_subject">Subject:</label>
<input id="id_subject" type="text" name="subject" maxlength="100" required /></p> <input id="id_subject" type="text" name="subject" maxlength="100" required></p>
<p><label for="id_message">Message:</label> <p><label for="id_message">Message:</label>
<textarea name="message" id="id_message" required></textarea></p> <textarea name="message" id="id_message" required></textarea></p>
<p><label for="id_sender">Sender:</label> <p><label for="id_sender">Sender:</label>
<input type="email" name="sender" id="id_sender" required /></p> <input type="email" name="sender" id="id_sender" required></p>
<p><label for="id_cc_myself">Cc myself:</label> <p><label for="id_cc_myself">Cc myself:</label>
<input type="checkbox" name="cc_myself" id="id_cc_myself" /></p> <input type="checkbox" name="cc_myself" id="id_cc_myself"></p>
Note that each form field has an ID attribute set to ``id_<field-name>``, which Note that each form field has an ID attribute set to ``id_<field-name>``, which
is referenced by the accompanying label tag. This is important in ensuring that is referenced by the accompanying label tag. This is important in ensuring that

View File

@ -71,7 +71,7 @@ can be retrieved through this property::
>>> w = CalendarWidget() >>> w = CalendarWidget()
>>> print(w.media) >>> print(w.media)
<link href="http://static.example.com/pretty.css" type="text/css" media="all" rel="stylesheet" /> <link href="http://static.example.com/pretty.css" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="http://static.example.com/animations.js"></script> <script type="text/javascript" src="http://static.example.com/animations.js"></script>
<script type="text/javascript" src="http://static.example.com/actions.js"></script> <script type="text/javascript" src="http://static.example.com/actions.js"></script>
@ -114,9 +114,9 @@ requirements::
If this last CSS definition were to be rendered, it would become the following HTML:: If this last CSS definition were to be rendered, it would become the following HTML::
<link href="http://static.example.com/pretty.css" type="text/css" media="screen" rel="stylesheet" /> <link href="http://static.example.com/pretty.css" type="text/css" media="screen" rel="stylesheet">
<link href="http://static.example.com/lo_res.css" type="text/css" media="tv,projector" rel="stylesheet" /> <link href="http://static.example.com/lo_res.css" type="text/css" media="tv,projector" rel="stylesheet">
<link href="http://static.example.com/newspaper.css" type="text/css" media="print" rel="stylesheet" /> <link href="http://static.example.com/newspaper.css" type="text/css" media="print" rel="stylesheet">
``js`` ``js``
------ ------
@ -145,8 +145,8 @@ example above::
>>> w = FancyCalendarWidget() >>> w = FancyCalendarWidget()
>>> print(w.media) >>> print(w.media)
<link href="http://static.example.com/pretty.css" type="text/css" media="all" rel="stylesheet" /> <link href="http://static.example.com/pretty.css" type="text/css" media="all" rel="stylesheet">
<link href="http://static.example.com/fancy.css" type="text/css" media="all" rel="stylesheet" /> <link href="http://static.example.com/fancy.css" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="http://static.example.com/animations.js"></script> <script type="text/javascript" src="http://static.example.com/animations.js"></script>
<script type="text/javascript" src="http://static.example.com/actions.js"></script> <script type="text/javascript" src="http://static.example.com/actions.js"></script>
<script type="text/javascript" src="http://static.example.com/whizbang.js"></script> <script type="text/javascript" src="http://static.example.com/whizbang.js"></script>
@ -165,7 +165,7 @@ an ``extend=False`` declaration to the ``Media`` declaration::
>>> w = FancyCalendarWidget() >>> w = FancyCalendarWidget()
>>> print(w.media) >>> print(w.media)
<link href="http://static.example.com/fancy.css" type="text/css" media="all" rel="stylesheet" /> <link href="http://static.example.com/fancy.css" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="http://static.example.com/whizbang.js"></script> <script type="text/javascript" src="http://static.example.com/whizbang.js"></script>
If you require even more control over inheritance, define your assets using a If you require even more control over inheritance, define your assets using a
@ -228,7 +228,7 @@ was ``None``::
>>> w = CalendarWidget() >>> w = CalendarWidget()
>>> print(w.media) >>> print(w.media)
<link href="/css/pretty.css" type="text/css" media="all" rel="stylesheet" /> <link href="/css/pretty.css" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="http://uploads.example.com/animations.js"></script> <script type="text/javascript" src="http://uploads.example.com/animations.js"></script>
<script type="text/javascript" src="http://othersite.com/actions.js"></script> <script type="text/javascript" src="http://othersite.com/actions.js"></script>
@ -236,7 +236,7 @@ But if :setting:`STATIC_URL` is ``'http://static.example.com/'``::
>>> w = CalendarWidget() >>> w = CalendarWidget()
>>> print(w.media) >>> print(w.media)
<link href="/css/pretty.css" type="text/css" media="all" rel="stylesheet" /> <link href="/css/pretty.css" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="http://static.example.com/animations.js"></script> <script type="text/javascript" src="http://static.example.com/animations.js"></script>
<script type="text/javascript" src="http://othersite.com/actions.js"></script> <script type="text/javascript" src="http://othersite.com/actions.js"></script>
@ -245,7 +245,7 @@ Or if :mod:`~django.contrib.staticfiles` is configured using the
>>> w = CalendarWidget() >>> w = CalendarWidget()
>>> print(w.media) >>> print(w.media)
<link href="/css/pretty.css" type="text/css" media="all" rel="stylesheet" /> <link href="/css/pretty.css" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="https://static.example.com/animations.27e20196a850.js"></script> <script type="text/javascript" src="https://static.example.com/animations.27e20196a850.js"></script>
<script type="text/javascript" src="http://othersite.com/actions.js"></script> <script type="text/javascript" src="http://othersite.com/actions.js"></script>
@ -268,12 +268,12 @@ operator to filter out a medium of interest. For example::
>>> w = CalendarWidget() >>> w = CalendarWidget()
>>> print(w.media) >>> print(w.media)
<link href="http://static.example.com/pretty.css" type="text/css" media="all" rel="stylesheet" /> <link href="http://static.example.com/pretty.css" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="http://static.example.com/animations.js"></script> <script type="text/javascript" src="http://static.example.com/animations.js"></script>
<script type="text/javascript" src="http://static.example.com/actions.js"></script> <script type="text/javascript" src="http://static.example.com/actions.js"></script>
>>> print(w.media['css']) >>> print(w.media['css'])
<link href="http://static.example.com/pretty.css" type="text/css" media="all" rel="stylesheet" /> <link href="http://static.example.com/pretty.css" type="text/css" media="all" rel="stylesheet">
When you use the subscript operator, the value that is returned is a When you use the subscript operator, the value that is returned is a
new ``Media`` object -- but one that only contains the media of interest. new ``Media`` object -- but one that only contains the media of interest.
@ -300,7 +300,7 @@ specified by both::
>>> w1 = CalendarWidget() >>> w1 = CalendarWidget()
>>> w2 = OtherWidget() >>> w2 = OtherWidget()
>>> print(w1.media + w2.media) >>> print(w1.media + w2.media)
<link href="http://static.example.com/pretty.css" type="text/css" media="all" rel="stylesheet" /> <link href="http://static.example.com/pretty.css" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="http://static.example.com/animations.js"></script> <script type="text/javascript" src="http://static.example.com/animations.js"></script>
<script type="text/javascript" src="http://static.example.com/actions.js"></script> <script type="text/javascript" src="http://static.example.com/actions.js"></script>
<script type="text/javascript" src="http://static.example.com/whizbang.js"></script> <script type="text/javascript" src="http://static.example.com/whizbang.js"></script>
@ -362,7 +362,7 @@ are part of the form::
>>> f = ContactForm() >>> f = ContactForm()
>>> f.media >>> f.media
<link href="http://static.example.com/pretty.css" type="text/css" media="all" rel="stylesheet" /> <link href="http://static.example.com/pretty.css" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="http://static.example.com/animations.js"></script> <script type="text/javascript" src="http://static.example.com/animations.js"></script>
<script type="text/javascript" src="http://static.example.com/actions.js"></script> <script type="text/javascript" src="http://static.example.com/actions.js"></script>
<script type="text/javascript" src="http://static.example.com/whizbang.js"></script> <script type="text/javascript" src="http://static.example.com/whizbang.js"></script>
@ -382,8 +382,8 @@ form::
>>> f = ContactForm() >>> f = ContactForm()
>>> f.media >>> f.media
<link href="http://static.example.com/pretty.css" type="text/css" media="all" rel="stylesheet" /> <link href="http://static.example.com/pretty.css" type="text/css" media="all" rel="stylesheet">
<link href="http://static.example.com/layout.css" type="text/css" media="all" rel="stylesheet" /> <link href="http://static.example.com/layout.css" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="http://static.example.com/animations.js"></script> <script type="text/javascript" src="http://static.example.com/animations.js"></script>
<script type="text/javascript" src="http://static.example.com/actions.js"></script> <script type="text/javascript" src="http://static.example.com/actions.js"></script>
<script type="text/javascript" src="http://static.example.com/whizbang.js"></script> <script type="text/javascript" src="http://static.example.com/whizbang.js"></script>

View File

@ -770,14 +770,14 @@ with the ``Author`` model. It works just like a regular formset::
>>> formset = AuthorFormSet() >>> formset = AuthorFormSet()
>>> print(formset) >>> print(formset)
<input type="hidden" name="form-TOTAL_FORMS" value="1" id="id_form-TOTAL_FORMS" /><input type="hidden" name="form-INITIAL_FORMS" value="0" id="id_form-INITIAL_FORMS" /><input type="hidden" name="form-MAX_NUM_FORMS" id="id_form-MAX_NUM_FORMS" /> <input type="hidden" name="form-TOTAL_FORMS" value="1" id="id_form-TOTAL_FORMS"><input type="hidden" name="form-INITIAL_FORMS" value="0" id="id_form-INITIAL_FORMS"><input type="hidden" name="form-MAX_NUM_FORMS" id="id_form-MAX_NUM_FORMS">
<tr><th><label for="id_form-0-name">Name:</label></th><td><input id="id_form-0-name" type="text" name="form-0-name" maxlength="100" /></td></tr> <tr><th><label for="id_form-0-name">Name:</label></th><td><input id="id_form-0-name" type="text" name="form-0-name" maxlength="100"></td></tr>
<tr><th><label for="id_form-0-title">Title:</label></th><td><select name="form-0-title" id="id_form-0-title"> <tr><th><label for="id_form-0-title">Title:</label></th><td><select name="form-0-title" id="id_form-0-title">
<option value="" selected>---------</option> <option value="" selected>---------</option>
<option value="MR">Mr.</option> <option value="MR">Mr.</option>
<option value="MRS">Mrs.</option> <option value="MRS">Mrs.</option>
<option value="MS">Ms.</option> <option value="MS">Ms.</option>
</select><input type="hidden" name="form-0-id" id="id_form-0-id" /></td></tr> </select><input type="hidden" name="form-0-id" id="id_form-0-id"></td></tr>
.. note:: .. note::
@ -959,10 +959,10 @@ so long as the total number of forms does not exceed ``max_num``::
>>> formset = AuthorFormSet(queryset=Author.objects.order_by('name')) >>> formset = AuthorFormSet(queryset=Author.objects.order_by('name'))
>>> for form in formset: >>> for form in formset:
... print(form.as_table()) ... print(form.as_table())
<tr><th><label for="id_form-0-name">Name:</label></th><td><input id="id_form-0-name" type="text" name="form-0-name" value="Charles Baudelaire" maxlength="100" /><input type="hidden" name="form-0-id" value="1" id="id_form-0-id" /></td></tr> <tr><th><label for="id_form-0-name">Name:</label></th><td><input id="id_form-0-name" type="text" name="form-0-name" value="Charles Baudelaire" maxlength="100"><input type="hidden" name="form-0-id" value="1" id="id_form-0-id"></td></tr>
<tr><th><label for="id_form-1-name">Name:</label></th><td><input id="id_form-1-name" type="text" name="form-1-name" value="Paul Verlaine" maxlength="100" /><input type="hidden" name="form-1-id" value="3" id="id_form-1-id" /></td></tr> <tr><th><label for="id_form-1-name">Name:</label></th><td><input id="id_form-1-name" type="text" name="form-1-name" value="Paul Verlaine" maxlength="100"><input type="hidden" name="form-1-id" value="3" id="id_form-1-id"></td></tr>
<tr><th><label for="id_form-2-name">Name:</label></th><td><input id="id_form-2-name" type="text" name="form-2-name" value="Walt Whitman" maxlength="100" /><input type="hidden" name="form-2-id" value="2" id="id_form-2-id" /></td></tr> <tr><th><label for="id_form-2-name">Name:</label></th><td><input id="id_form-2-name" type="text" name="form-2-name" value="Walt Whitman" maxlength="100"><input type="hidden" name="form-2-id" value="2" id="id_form-2-id"></td></tr>
<tr><th><label for="id_form-3-name">Name:</label></th><td><input id="id_form-3-name" type="text" name="form-3-name" maxlength="100" /><input type="hidden" name="form-3-id" id="id_form-3-id" /></td></tr> <tr><th><label for="id_form-3-name">Name:</label></th><td><input id="id_form-3-name" type="text" name="form-3-name" maxlength="100"><input type="hidden" name="form-3-id" id="id_form-3-id"></td></tr>
A ``max_num`` value of ``None`` (the default) puts a high limit on the number A ``max_num`` value of ``None`` (the default) puts a high limit on the number
of forms displayed (1000). In practice this is equivalent to no limit. of forms displayed (1000). In practice this is equivalent to no limit.

View File

@ -204,7 +204,7 @@ Include a form in ``template.html`` that will ``POST`` to this view:
<option value="{{ tz }}"{% if tz == TIME_ZONE %} selected{% endif %}>{{ tz }}</option> <option value="{{ tz }}"{% if tz == TIME_ZONE %} selected{% endif %}>{{ tz }}</option>
{% endfor %} {% endfor %}
</select> </select>
<input type="submit" value="Set" /> <input type="submit" value="Set">
</form> </form>
.. _time-zones-in-forms: .. _time-zones-in-forms:

View File

@ -610,7 +610,7 @@ filters::
</h1> </h1>
<p> <p>
{% for stage in tour_stages %} {% for stage in tour_stages %}
{% cycle start end %}: {{ stage }}{% if forloop.counter|divisibleby:2 %}<br />{% else %}, {% endif %} {% cycle start end %}: {{ stage }}{% if forloop.counter|divisibleby:2 %}<br>{% else %}, {% endif %}
{% endfor %} {% endfor %}
</p> </p>
@ -891,9 +891,9 @@ use the ``{% get_language_info %}`` tag::
You can then access the information:: You can then access the information::
Language code: {{ lang.code }}<br /> Language code: {{ lang.code }}<br>
Name of language: {{ lang.name_local }}<br /> Name of language: {{ lang.name_local }}<br>
Name in English: {{ lang.name }}<br /> Name in English: {{ lang.name }}<br>
Bi-directional: {{ lang.bidi }} Bi-directional: {{ lang.bidi }}
Name in the active language: {{ lang.name_translated }} Name in the active language: {{ lang.name_translated }}
@ -1788,7 +1788,7 @@ Here's example HTML template code:
{% load i18n %} {% load i18n %}
<form action="{% url 'set_language' %}" method="post">{% csrf_token %} <form action="{% url 'set_language' %}" method="post">{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}" /> <input name="next" type="hidden" value="{{ redirect_to }}">
<select name="language"> <select name="language">
{% get_current_language as LANGUAGE_CODE %} {% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %} {% get_available_languages as LANGUAGES %}
@ -1799,7 +1799,7 @@ Here's example HTML template code:
</option> </option>
{% endfor %} {% endfor %}
</select> </select>
<input type="submit" value="Go" /> <input type="submit" value="Go">
</form> </form>
In this example, Django looks up the URL of the page to which the user will be In this example, Django looks up the URL of the page to which the user will be

View File

@ -101,7 +101,7 @@ pages along with any interesting information from the objects themselves::
{% for contact in contacts %} {% for contact in contacts %}
{# Each "contact" is a Contact model object. #} {# Each "contact" is a Contact model object. #}
{{ contact.full_name|upper }}<br /> {{ contact.full_name|upper }}<br>
... ...
{% endfor %} {% endfor %}

View File

@ -1485,7 +1485,7 @@ your test suite.
self.assertHTMLEqual( self.assertHTMLEqual(
'<p>Hello <b>world!</p>', '<p>Hello <b>world!</p>',
'''<p> '''<p>
Hello <b>world! <b/> Hello <b>world! </b>
</p>''' </p>'''
) )
self.assertHTMLEqual( self.assertHTMLEqual(

View File

@ -39,7 +39,7 @@ def build_tbody_html(pk, href, extra_fields):
'<tbody><tr class="row1">' '<tbody><tr class="row1">'
'<td class="action-checkbox">' '<td class="action-checkbox">'
'<input type="checkbox" name="_selected_action" value="{}" ' '<input type="checkbox" name="_selected_action" value="{}" '
'class="action-select" /></td>' 'class="action-select"></td>'
'<th class="field-name"><a href="{}">name</a></th>' '<th class="field-name"><a href="{}">name</a></th>'
'{}</tr></tbody>' '{}</tr></tbody>'
).format(pk, href, extra_fields) ).format(pk, href, extra_fields)
@ -209,7 +209,7 @@ class ChangeListTests(TestCase):
# make sure that hidden fields are in the correct place # make sure that hidden fields are in the correct place
hiddenfields_div = ( hiddenfields_div = (
'<div class="hiddenfields">' '<div class="hiddenfields">'
'<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id" />' '<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id">'
'</div>' '</div>'
) % new_child.id ) % new_child.id
self.assertInHTML(hiddenfields_div, table_output, msg_prefix='Failed to find hidden fields') self.assertInHTML(hiddenfields_div, table_output, msg_prefix='Failed to find hidden fields')
@ -217,7 +217,7 @@ class ChangeListTests(TestCase):
# make sure that list editable fields are rendered in divs correctly # make sure that list editable fields are rendered in divs correctly
editable_name_field = ( editable_name_field = (
'<input name="form-0-name" value="name" class="vTextField" ' '<input name="form-0-name" value="name" class="vTextField" '
'maxlength="30" type="text" id="id_form-0-name" />' 'maxlength="30" type="text" id="id_form-0-name">'
) )
self.assertInHTML( self.assertInHTML(
'<td class="field-name">%s</td>' % editable_name_field, '<td class="field-name">%s</td>' % editable_name_field,

View File

@ -28,7 +28,7 @@ class AdminDocViewTests(TestDataMixin, AdminDocsTestCase):
self.client.logout() self.client.logout()
response = self.client.get(reverse('django-admindocs-docroot'), follow=True) response = self.client.get(reverse('django-admindocs-docroot'), follow=True)
# Should display the login screen # Should display the login screen
self.assertContains(response, '<input type="hidden" name="next" value="/admindocs/" />', html=True) self.assertContains(response, '<input type="hidden" name="next" value="/admindocs/">', html=True)
def test_bookmarklets(self): def test_bookmarklets(self):
response = self.client.get(reverse('django-admindocs-bookmarklets')) response = self.client.get(reverse('django-admindocs-bookmarklets'))

View File

@ -161,7 +161,7 @@ class TestInline(TestDataMixin, TestCase):
'<img src="/static/admin/img/icon-unknown.svg" ' '<img src="/static/admin/img/icon-unknown.svg" '
'class="help help-tooltip" width="10" height="10" ' 'class="help help-tooltip" width="10" height="10" '
'alt="(Awesome tabular help text is awesome.)" ' 'alt="(Awesome tabular help text is awesome.)" '
'title="Awesome tabular help text is awesome." />', 'title="Awesome tabular help text is awesome.">',
1 1
) )
# ReadOnly fields # ReadOnly fields
@ -171,7 +171,7 @@ class TestInline(TestDataMixin, TestCase):
'<img src="/static/admin/img/icon-unknown.svg" ' '<img src="/static/admin/img/icon-unknown.svg" '
'class="help help-tooltip" width="10" height="10" ' 'class="help help-tooltip" width="10" height="10" '
'alt="(Help text for ReadOnlyInline)" ' 'alt="(Help text for ReadOnlyInline)" '
'title="Help text for ReadOnlyInline" />', 'title="Help text for ReadOnlyInline">',
1 1
) )
@ -184,7 +184,7 @@ class TestInline(TestDataMixin, TestCase):
self.assertNotContains(response, '<td class="field-position">') self.assertNotContains(response, '<td class="field-position">')
self.assertInHTML( self.assertInHTML(
'<input id="id_somechildmodel_set-1-position" ' '<input id="id_somechildmodel_set-1-position" '
'name="somechildmodel_set-1-position" type="hidden" value="1" />', 'name="somechildmodel_set-1-position" type="hidden" value="1">',
response.rendered_content, response.rendered_content,
) )
@ -193,26 +193,26 @@ class TestInline(TestDataMixin, TestCase):
Multiple inlines with related_name='+' have correct form prefixes. Multiple inlines with related_name='+' have correct form prefixes.
""" """
response = self.client.get(reverse('admin:admin_inlines_capofamiglia_add')) response = self.client.get(reverse('admin:admin_inlines_capofamiglia_add'))
self.assertContains(response, '<input type="hidden" name="-1-0-id" id="id_-1-0-id" />', html=True) self.assertContains(response, '<input type="hidden" name="-1-0-id" id="id_-1-0-id">', html=True)
self.assertContains( self.assertContains(
response, response,
'<input type="hidden" name="-1-0-capo_famiglia" id="id_-1-0-capo_famiglia" />', '<input type="hidden" name="-1-0-capo_famiglia" id="id_-1-0-capo_famiglia">',
html=True html=True
) )
self.assertContains( self.assertContains(
response, response,
'<input id="id_-1-0-name" type="text" class="vTextField" name="-1-0-name" maxlength="100" />', '<input id="id_-1-0-name" type="text" class="vTextField" name="-1-0-name" maxlength="100">',
html=True html=True
) )
self.assertContains(response, '<input type="hidden" name="-2-0-id" id="id_-2-0-id" />', html=True) self.assertContains(response, '<input type="hidden" name="-2-0-id" id="id_-2-0-id">', html=True)
self.assertContains( self.assertContains(
response, response,
'<input type="hidden" name="-2-0-capo_famiglia" id="id_-2-0-capo_famiglia" />', '<input type="hidden" name="-2-0-capo_famiglia" id="id_-2-0-capo_famiglia">',
html=True html=True
) )
self.assertContains( self.assertContains(
response, response,
'<input id="id_-2-0-name" type="text" class="vTextField" name="-2-0-name" maxlength="100" />', '<input id="id_-2-0-name" type="text" class="vTextField" name="-2-0-name" maxlength="100">',
html=True html=True
) )
@ -265,12 +265,12 @@ class TestInline(TestDataMixin, TestCase):
# ModelAdmin # ModelAdmin
max_forms_input = ( max_forms_input = (
'<input id="id_binarytree_set-MAX_NUM_FORMS" ' '<input id="id_binarytree_set-MAX_NUM_FORMS" '
'name="binarytree_set-MAX_NUM_FORMS" type="hidden" value="%d" />' 'name="binarytree_set-MAX_NUM_FORMS" type="hidden" value="%d">'
) )
# The total number of forms will remain the same in either case # The total number of forms will remain the same in either case
total_forms_hidden = ( total_forms_hidden = (
'<input id="id_binarytree_set-TOTAL_FORMS" ' '<input id="id_binarytree_set-TOTAL_FORMS" '
'name="binarytree_set-TOTAL_FORMS" type="hidden" value="2" />' 'name="binarytree_set-TOTAL_FORMS" type="hidden" value="2">'
) )
response = self.client.get(reverse('admin:admin_inlines_binarytree_add')) response = self.client.get(reverse('admin:admin_inlines_binarytree_add'))
self.assertInHTML(max_forms_input % 3, response.rendered_content) self.assertInHTML(max_forms_input % 3, response.rendered_content)
@ -293,11 +293,11 @@ class TestInline(TestDataMixin, TestCase):
modeladmin.inlines = [MinNumInline] modeladmin.inlines = [MinNumInline]
min_forms = ( min_forms = (
'<input id="id_binarytree_set-MIN_NUM_FORMS" ' '<input id="id_binarytree_set-MIN_NUM_FORMS" '
'name="binarytree_set-MIN_NUM_FORMS" type="hidden" value="2" />' 'name="binarytree_set-MIN_NUM_FORMS" type="hidden" value="2">'
) )
total_forms = ( total_forms = (
'<input id="id_binarytree_set-TOTAL_FORMS" ' '<input id="id_binarytree_set-TOTAL_FORMS" '
'name="binarytree_set-TOTAL_FORMS" type="hidden" value="5" />' 'name="binarytree_set-TOTAL_FORMS" type="hidden" value="5">'
) )
request = self.factory.get(reverse('admin:admin_inlines_binarytree_add')) request = self.factory.get(reverse('admin:admin_inlines_binarytree_add'))
request.user = User(username='super', is_superuser=True) request.user = User(username='super', is_superuser=True)
@ -322,11 +322,11 @@ class TestInline(TestDataMixin, TestCase):
modeladmin.inlines = [MinNumInline] modeladmin.inlines = [MinNumInline]
min_forms = ( min_forms = (
'<input id="id_binarytree_set-MIN_NUM_FORMS" ' '<input id="id_binarytree_set-MIN_NUM_FORMS" '
'name="binarytree_set-MIN_NUM_FORMS" type="hidden" value="%d" />' 'name="binarytree_set-MIN_NUM_FORMS" type="hidden" value="%d">'
) )
total_forms = ( total_forms = (
'<input id="id_binarytree_set-TOTAL_FORMS" ' '<input id="id_binarytree_set-TOTAL_FORMS" '
'name="binarytree_set-TOTAL_FORMS" type="hidden" value="%d" />' 'name="binarytree_set-TOTAL_FORMS" type="hidden" value="%d">'
) )
request = self.factory.get(reverse('admin:admin_inlines_binarytree_add')) request = self.factory.get(reverse('admin:admin_inlines_binarytree_add'))
request.user = User(username='super', is_superuser=True) request.user = User(username='super', is_superuser=True)
@ -345,13 +345,13 @@ class TestInline(TestDataMixin, TestCase):
self.assertContains( self.assertContains(
response, response,
'<input id="id_nonautopkbook_set-0-rand_pk" ' '<input id="id_nonautopkbook_set-0-rand_pk" '
'name="nonautopkbook_set-0-rand_pk" type="hidden" />', 'name="nonautopkbook_set-0-rand_pk" type="hidden">',
html=True html=True
) )
self.assertContains( self.assertContains(
response, response,
'<input id="id_nonautopkbook_set-2-0-rand_pk" ' '<input id="id_nonautopkbook_set-2-0-rand_pk" '
'name="nonautopkbook_set-2-0-rand_pk" type="hidden" />', 'name="nonautopkbook_set-2-0-rand_pk" type="hidden">',
html=True html=True
) )
@ -360,13 +360,13 @@ class TestInline(TestDataMixin, TestCase):
self.assertContains( self.assertContains(
response, response,
'<input id="id_nonautopkbookchild_set-0-nonautopkbook_ptr" ' '<input id="id_nonautopkbookchild_set-0-nonautopkbook_ptr" '
'name="nonautopkbookchild_set-0-nonautopkbook_ptr" type="hidden" />', 'name="nonautopkbookchild_set-0-nonautopkbook_ptr" type="hidden">',
html=True html=True
) )
self.assertContains( self.assertContains(
response, response,
'<input id="id_nonautopkbookchild_set-2-nonautopkbook_ptr" ' '<input id="id_nonautopkbookchild_set-2-nonautopkbook_ptr" '
'name="nonautopkbookchild_set-2-nonautopkbook_ptr" type="hidden" />', 'name="nonautopkbookchild_set-2-nonautopkbook_ptr" type="hidden">',
html=True html=True
) )
@ -375,13 +375,13 @@ class TestInline(TestDataMixin, TestCase):
self.assertContains( self.assertContains(
response, response,
'<input class="vIntegerField" id="id_editablepkbook_set-0-manual_pk" ' '<input class="vIntegerField" id="id_editablepkbook_set-0-manual_pk" '
'name="editablepkbook_set-0-manual_pk" type="number" />', 'name="editablepkbook_set-0-manual_pk" type="number">',
html=True, count=1 html=True, count=1
) )
self.assertContains( self.assertContains(
response, response,
'<input class="vIntegerField" id="id_editablepkbook_set-2-0-manual_pk" ' '<input class="vIntegerField" id="id_editablepkbook_set-2-0-manual_pk" '
'name="editablepkbook_set-2-0-manual_pk" type="number" />', 'name="editablepkbook_set-2-0-manual_pk" type="number">',
html=True, count=1 html=True, count=1
) )
@ -614,7 +614,7 @@ class TestInlinePermissions(TestCase):
self.assertContains(response, '<h2>Inner2s</h2>') self.assertContains(response, '<h2>Inner2s</h2>')
self.assertContains(response, 'Add another Inner2') self.assertContains(response, 'Add another Inner2')
self.assertContains(response, '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" ' self.assertContains(response, '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" '
'value="3" name="inner2_set-TOTAL_FORMS" />', html=True) 'value="3" name="inner2_set-TOTAL_FORMS">', html=True)
def test_inline_change_m2m_add_perm(self): def test_inline_change_m2m_add_perm(self):
permission = Permission.objects.get(codename='add_book', content_type=self.book_ct) permission = Permission.objects.get(codename='add_book', content_type=self.book_ct)
@ -634,11 +634,11 @@ class TestInlinePermissions(TestCase):
self.assertContains(response, '<h2>Author-book relationships</h2>') self.assertContains(response, '<h2>Author-book relationships</h2>')
self.assertContains(response, 'Add another Author-book relationship') self.assertContains(response, 'Add another Author-book relationship')
self.assertContains(response, '<input type="hidden" id="id_Author_books-TOTAL_FORMS" ' self.assertContains(response, '<input type="hidden" id="id_Author_books-TOTAL_FORMS" '
'value="4" name="Author_books-TOTAL_FORMS" />', html=True) 'value="4" name="Author_books-TOTAL_FORMS">', html=True)
self.assertContains( self.assertContains(
response, response,
'<input type="hidden" id="id_Author_books-0-id" value="%i" ' '<input type="hidden" id="id_Author_books-0-id" value="%i" '
'name="Author_books-0-id" />' % self.author_book_auto_m2m_intermediate_id, 'name="Author_books-0-id">' % self.author_book_auto_m2m_intermediate_id,
html=True html=True
) )
self.assertContains(response, 'id="id_Author_books-0-DELETE"') self.assertContains(response, 'id="id_Author_books-0-DELETE"')
@ -654,12 +654,12 @@ class TestInlinePermissions(TestCase):
self.assertContains( self.assertContains(
response, response,
'<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="3" ' '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="3" '
'name="inner2_set-TOTAL_FORMS" />', 'name="inner2_set-TOTAL_FORMS">',
html=True html=True
) )
self.assertNotContains( self.assertNotContains(
response, response,
'<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id" />' % self.inner2_id, '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2_id,
html=True html=True
) )
@ -671,18 +671,18 @@ class TestInlinePermissions(TestCase):
self.assertContains(response, '<h2>Inner2s</h2>') self.assertContains(response, '<h2>Inner2s</h2>')
# Just the one form for existing instances # Just the one form for existing instances
self.assertContains( self.assertContains(
response, '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="1" name="inner2_set-TOTAL_FORMS" />', response, '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="1" name="inner2_set-TOTAL_FORMS">',
html=True html=True
) )
self.assertContains( self.assertContains(
response, response,
'<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id" />' % self.inner2_id, '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2_id,
html=True html=True
) )
# max-num 0 means we can't add new ones # max-num 0 means we can't add new ones
self.assertContains( self.assertContains(
response, response,
'<input type="hidden" id="id_inner2_set-MAX_NUM_FORMS" value="0" name="inner2_set-MAX_NUM_FORMS" />', '<input type="hidden" id="id_inner2_set-MAX_NUM_FORMS" value="0" name="inner2_set-MAX_NUM_FORMS">',
html=True html=True
) )
@ -696,12 +696,12 @@ class TestInlinePermissions(TestCase):
self.assertContains(response, '<h2>Inner2s</h2>') self.assertContains(response, '<h2>Inner2s</h2>')
# One form for existing instance and three extra for new # One form for existing instance and three extra for new
self.assertContains( self.assertContains(
response, '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="4" name="inner2_set-TOTAL_FORMS" />', response, '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="4" name="inner2_set-TOTAL_FORMS">',
html=True html=True
) )
self.assertContains( self.assertContains(
response, response,
'<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id" />' % self.inner2_id, '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2_id,
html=True html=True
) )
@ -716,12 +716,12 @@ class TestInlinePermissions(TestCase):
# One form for existing instance only, no new # One form for existing instance only, no new
self.assertContains( self.assertContains(
response, response,
'<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="1" name="inner2_set-TOTAL_FORMS" />', '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="1" name="inner2_set-TOTAL_FORMS">',
html=True html=True
) )
self.assertContains( self.assertContains(
response, response,
'<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id" />' % self.inner2_id, '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2_id,
html=True html=True
) )
self.assertContains(response, 'id="id_inner2_set-0-DELETE"') self.assertContains(response, 'id="id_inner2_set-0-DELETE"')
@ -739,12 +739,12 @@ class TestInlinePermissions(TestCase):
# One form for existing instance only, three for new # One form for existing instance only, three for new
self.assertContains( self.assertContains(
response, response,
'<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="4" name="inner2_set-TOTAL_FORMS" />', '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" value="4" name="inner2_set-TOTAL_FORMS">',
html=True html=True
) )
self.assertContains( self.assertContains(
response, response,
'<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id" />' % self.inner2_id, '<input type="hidden" id="id_inner2_set-0-id" value="%i" name="inner2_set-0-id">' % self.inner2_id,
html=True html=True
) )
self.assertContains(response, 'id="id_inner2_set-0-DELETE"') self.assertContains(response, 'id="id_inner2_set-0-DELETE"')

View File

@ -163,7 +163,7 @@ class UtilsTests(SimpleTestCase):
# Regression test for #13071: NullBooleanField has special # Regression test for #13071: NullBooleanField has special
# handling. # handling.
display_value = display_for_field(None, models.NullBooleanField(), self.empty_value) display_value = display_for_field(None, models.NullBooleanField(), self.empty_value)
expected = '<img src="%sadmin/img/icon-unknown.svg" alt="None" />' % settings.STATIC_URL expected = '<img src="%sadmin/img/icon-unknown.svg" alt="None">' % settings.STATIC_URL
self.assertHTMLEqual(display_value, expected) self.assertHTMLEqual(display_value, expected)
display_value = display_for_field(None, models.DecimalField(), self.empty_value) display_value = display_for_field(None, models.DecimalField(), self.empty_value)
@ -204,11 +204,11 @@ class UtilsTests(SimpleTestCase):
def test_list_display_for_value_boolean(self): def test_list_display_for_value_boolean(self):
self.assertEqual( self.assertEqual(
display_for_value(True, '', boolean=True), display_for_value(True, '', boolean=True),
'<img src="/static/admin/img/icon-yes.svg" alt="True" />' '<img src="/static/admin/img/icon-yes.svg" alt="True">'
) )
self.assertEqual( self.assertEqual(
display_for_value(False, '', boolean=True), display_for_value(False, '', boolean=True),
'<img src="/static/admin/img/icon-no.svg" alt="False" />' '<img src="/static/admin/img/icon-no.svg" alt="False">'
) )
self.assertEqual(display_for_value(True, ''), 'True') self.assertEqual(display_for_value(True, ''), 'True')
self.assertEqual(display_for_value(False, ''), 'False') self.assertEqual(display_for_value(False, ''), 'False')

View File

@ -1027,7 +1027,7 @@ class AdminCustomTemplateTests(AdminViewBasicTestCase):
# When a site has multiple passwords in the browser's password manager, # When a site has multiple passwords in the browser's password manager,
# a browser pop up asks which user the new password is for. To prevent # a browser pop up asks which user the new password is for. To prevent
# this, the username is added to the change password form. # this, the username is added to the change password form.
self.assertContains(response, '<input type="text" name="username" value="super" style="display: none" />') self.assertContains(response, '<input type="text" name="username" value="super" style="display: none">')
def test_extended_bodyclass_template_index(self): def test_extended_bodyclass_template_index(self):
""" """
@ -2969,8 +2969,8 @@ class AdminViewListEditable(TestCase):
self.assertContains( self.assertContains(
response, response,
'<div class="hiddenfields">\n' '<div class="hiddenfields">\n'
'<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id" />' '<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id">'
'<input type="hidden" name="form-1-id" value="%d" id="id_form-1-id" />\n</div>' '<input type="hidden" name="form-1-id" value="%d" id="id_form-1-id">\n</div>'
% (story2.id, story1.id), % (story2.id, story1.id),
html=True html=True
) )
@ -2999,8 +2999,8 @@ class AdminViewListEditable(TestCase):
self.assertContains( self.assertContains(
response, response,
'<div class="hiddenfields">\n' '<div class="hiddenfields">\n'
'<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id" />' '<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id">'
'<input type="hidden" name="form-1-id" value="%d" id="id_form-1-id" />\n</div>' '<input type="hidden" name="form-1-id" value="%d" id="id_form-1-id">\n</div>'
% (story2.id, story1.id), % (story2.id, story1.id),
html=True html=True
) )
@ -3057,7 +3057,7 @@ class AdminSearchTest(TestCase):
""" """
response = self.client.get(reverse('admin:auth_user_changelist') + '?q=joe&%s=id' % TO_FIELD_VAR) response = self.client.get(reverse('admin:auth_user_changelist') + '?q=joe&%s=id' % TO_FIELD_VAR)
self.assertContains(response, "\n1 user\n") self.assertContains(response, "\n1 user\n")
self.assertContains(response, '<input type="hidden" name="%s" value="id"/>' % TO_FIELD_VAR, html=True) self.assertContains(response, '<input type="hidden" name="%s" value="id">' % TO_FIELD_VAR, html=True)
def test_exact_matches(self): def test_exact_matches(self):
response = self.client.get(reverse('admin:admin_views_recommendation_changelist') + '?q=bar') response = self.client.get(reverse('admin:admin_views_recommendation_changelist') + '?q=bar')
@ -4388,10 +4388,10 @@ class ReadonlyTest(AdminFieldExtractionMixin, TestCase):
self.assertContains(response, "Unknown coolness.") self.assertContains(response, "Unknown coolness.")
self.assertContains(response, "foo") self.assertContains(response, "foo")
# Multiline text in a readonly field gets <br /> tags # Multiline text in a readonly field gets <br> tags
self.assertContains(response, 'Multiline<br />test<br />string') self.assertContains(response, 'Multiline<br>test<br>string')
self.assertContains(response, '<div class="readonly">Multiline<br />html<br />content</div>', html=True) self.assertContains(response, '<div class="readonly">Multiline<br>html<br>content</div>', html=True)
self.assertContains(response, 'InlineMultiline<br />test<br />string') self.assertContains(response, 'InlineMultiline<br>test<br>string')
self.assertContains(response, formats.localize(datetime.date.today() - datetime.timedelta(days=7))) self.assertContains(response, formats.localize(datetime.date.today() - datetime.timedelta(days=7)))
@ -4432,9 +4432,9 @@ class ReadonlyTest(AdminFieldExtractionMixin, TestCase):
) )
response = self.client.get(reverse('admin:admin_views_post_change', args=(p.pk,))) response = self.client.get(reverse('admin:admin_views_post_change', args=(p.pk,)))
# Checking readonly field. # Checking readonly field.
self.assertContains(response, 'test<br /><br />test<br /><br />test<br /><br />test') self.assertContains(response, 'test<br><br>test<br><br>test<br><br>test')
# Checking readonly field in inline. # Checking readonly field in inline.
self.assertContains(response, 'test<br />link') self.assertContains(response, 'test<br>link')
def test_readonly_post(self): def test_readonly_post(self):
data = { data = {
@ -5267,7 +5267,7 @@ class AdminViewLogoutTests(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'admin/login.html') self.assertTemplateUsed(response, 'admin/login.html')
self.assertEqual(response.request['PATH_INFO'], reverse('admin:login')) self.assertEqual(response.request['PATH_INFO'], reverse('admin:login'))
self.assertContains(response, '<input type="hidden" name="next" value="%s" />' % reverse('admin:index')) self.assertContains(response, '<input type="hidden" name="next" value="%s">' % reverse('admin:index'))
@override_settings(ROOT_URLCONF='admin_views.urls') @override_settings(ROOT_URLCONF='admin_views.urls')

View File

@ -274,13 +274,13 @@ class AdminDateWidgetTest(SimpleTestCase):
w = widgets.AdminDateWidget() w = widgets.AdminDateWidget()
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('test', datetime(2007, 12, 1, 9, 30)), w.render('test', datetime(2007, 12, 1, 9, 30)),
'<input value="2007-12-01" type="text" class="vDateField" name="test" size="10" />', '<input value="2007-12-01" type="text" class="vDateField" name="test" size="10">',
) )
# pass attrs to widget # pass attrs to widget
w = widgets.AdminDateWidget(attrs={'size': 20, 'class': 'myDateField'}) w = widgets.AdminDateWidget(attrs={'size': 20, 'class': 'myDateField'})
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('test', datetime(2007, 12, 1, 9, 30)), w.render('test', datetime(2007, 12, 1, 9, 30)),
'<input value="2007-12-01" type="text" class="myDateField" name="test" size="20" />', '<input value="2007-12-01" type="text" class="myDateField" name="test" size="20">',
) )
@ -289,13 +289,13 @@ class AdminTimeWidgetTest(SimpleTestCase):
w = widgets.AdminTimeWidget() w = widgets.AdminTimeWidget()
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('test', datetime(2007, 12, 1, 9, 30)), w.render('test', datetime(2007, 12, 1, 9, 30)),
'<input value="09:30:00" type="text" class="vTimeField" name="test" size="8" />', '<input value="09:30:00" type="text" class="vTimeField" name="test" size="8">',
) )
# pass attrs to widget # pass attrs to widget
w = widgets.AdminTimeWidget(attrs={'size': 20, 'class': 'myTimeField'}) w = widgets.AdminTimeWidget(attrs={'size': 20, 'class': 'myTimeField'})
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('test', datetime(2007, 12, 1, 9, 30)), w.render('test', datetime(2007, 12, 1, 9, 30)),
'<input value="09:30:00" type="text" class="myTimeField" name="test" size="20" />', '<input value="09:30:00" type="text" class="myTimeField" name="test" size="20">',
) )
@ -306,9 +306,9 @@ class AdminSplitDateTimeWidgetTest(SimpleTestCase):
w.render('test', datetime(2007, 12, 1, 9, 30)), w.render('test', datetime(2007, 12, 1, 9, 30)),
'<p class="datetime">' '<p class="datetime">'
'Date: <input value="2007-12-01" type="text" class="vDateField" ' 'Date: <input value="2007-12-01" type="text" class="vDateField" '
'name="test_0" size="10" /><br />' 'name="test_0" size="10"><br>'
'Time: <input value="09:30:00" type="text" class="vTimeField" ' 'Time: <input value="09:30:00" type="text" class="vTimeField" '
'name="test_1" size="8" /></p>' 'name="test_1" size="8"></p>'
) )
def test_localization(self): def test_localization(self):
@ -320,9 +320,9 @@ class AdminSplitDateTimeWidgetTest(SimpleTestCase):
w.render('test', datetime(2007, 12, 1, 9, 30)), w.render('test', datetime(2007, 12, 1, 9, 30)),
'<p class="datetime">' '<p class="datetime">'
'Datum: <input value="01.12.2007" type="text" ' 'Datum: <input value="01.12.2007" type="text" '
'class="vDateField" name="test_0"size="10" /><br />' 'class="vDateField" name="test_0"size="10"><br>'
'Zeit: <input value="09:30:00" type="text" class="vTimeField" ' 'Zeit: <input value="09:30:00" type="text" class="vTimeField" '
'name="test_1" size="8" /></p>' 'name="test_1" size="8"></p>'
) )
@ -331,14 +331,14 @@ class AdminURLWidgetTest(SimpleTestCase):
w = widgets.AdminURLFieldWidget() w = widgets.AdminURLFieldWidget()
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('test', ''), w.render('test', ''),
'<input class="vURLField" name="test" type="url" />' '<input class="vURLField" name="test" type="url">'
) )
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('test', 'http://example.com'), w.render('test', 'http://example.com'),
'<p class="url">Currently:<a href="http://example.com">' '<p class="url">Currently:<a href="http://example.com">'
'http://example.com</a><br />' 'http://example.com</a><br>'
'Change:<input class="vURLField" name="test" type="url" ' 'Change:<input class="vURLField" name="test" type="url" '
'value="http://example.com" /></p>' 'value="http://example.com"></p>'
) )
def test_render_idn(self): def test_render_idn(self):
@ -346,9 +346,9 @@ class AdminURLWidgetTest(SimpleTestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('test', 'http://example-äüö.com'), w.render('test', 'http://example-äüö.com'),
'<p class="url">Currently: <a href="http://xn--example--7za4pnc.com">' '<p class="url">Currently: <a href="http://xn--example--7za4pnc.com">'
'http://example-äüö.com</a><br />' 'http://example-äüö.com</a><br>'
'Change:<input class="vURLField" name="test" type="url" ' 'Change:<input class="vURLField" name="test" type="url" '
'value="http://example-äüö.com" /></p>' 'value="http://example-äüö.com"></p>'
) )
def test_render_quoting(self): def test_render_quoting(self):
@ -420,15 +420,15 @@ class AdminFileWidgetTests(TestDataMixin, TestCase):
'<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/' '<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/'
r'hybrid_theory.jpg">albums\hybrid_theory.jpg</a> ' r'hybrid_theory.jpg">albums\hybrid_theory.jpg</a> '
'<span class="clearable-file-input">' '<span class="clearable-file-input">'
'<input type="checkbox" name="test-clear" id="test-clear_id" /> ' '<input type="checkbox" name="test-clear" id="test-clear_id"> '
'<label for="test-clear_id">Clear</label></span><br />' '<label for="test-clear_id">Clear</label></span><br>'
'Change: <input type="file" name="test" /></p>' % { 'Change: <input type="file" name="test"></p>' % {
'STORAGE_URL': default_storage.url(''), 'STORAGE_URL': default_storage.url(''),
}, },
) )
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('test', SimpleUploadedFile('test', b'content')), w.render('test', SimpleUploadedFile('test', b'content')),
'<input type="file" name="test" />', '<input type="file" name="test">',
) )
def test_render_required(self): def test_render_required(self):
@ -437,8 +437,8 @@ class AdminFileWidgetTests(TestDataMixin, TestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
widget.render('test', self.album.cover_art), widget.render('test', self.album.cover_art),
'<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/' '<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/'
r'hybrid_theory.jpg">albums\hybrid_theory.jpg</a><br />' r'hybrid_theory.jpg">albums\hybrid_theory.jpg</a><br>'
'Change: <input type="file" name="test" /></p>' % { 'Change: <input type="file" name="test"></p>' % {
'STORAGE_URL': default_storage.url(''), 'STORAGE_URL': default_storage.url(''),
}, },
) )
@ -457,7 +457,7 @@ class AdminFileWidgetTests(TestDataMixin, TestCase):
) )
self.assertNotContains( self.assertNotContains(
response, response,
'<input type="file" name="cover_art" id="id_cover_art" />', '<input type="file" name="cover_art" id="id_cover_art">',
html=True, html=True,
) )
response = self.client.get(reverse('admin:admin_widgets_album_add')) response = self.client.get(reverse('admin:admin_widgets_album_add'))
@ -482,7 +482,7 @@ class ForeignKeyRawIdWidgetTest(TestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('test', band.pk, attrs={}), w.render('test', band.pk, attrs={}),
'<input type="text" name="test" value="%(bandpk)s" ' '<input type="text" name="test" value="%(bandpk)s" '
'class="vForeignKeyRawIdAdminField" />' 'class="vForeignKeyRawIdAdminField">'
'<a href="/admin_widgets/band/?_to_field=id" class="related-lookup" ' '<a href="/admin_widgets/band/?_to_field=id" class="related-lookup" '
'id="lookup_id_test" title="Lookup"></a>&nbsp;<strong>' 'id="lookup_id_test" title="Lookup"></a>&nbsp;<strong>'
'<a href="/admin_widgets/band/%(bandpk)s/change/">Linkin Park</a>' '<a href="/admin_widgets/band/%(bandpk)s/change/">Linkin Park</a>'
@ -502,7 +502,7 @@ class ForeignKeyRawIdWidgetTest(TestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('test', core.parent_id, attrs={}), w.render('test', core.parent_id, attrs={}),
'<input type="text" name="test" value="86" ' '<input type="text" name="test" value="86" '
'class="vForeignKeyRawIdAdminField" />' 'class="vForeignKeyRawIdAdminField">'
'<a href="/admin_widgets/inventory/?_to_field=barcode" ' '<a href="/admin_widgets/inventory/?_to_field=barcode" '
'class="related-lookup" id="lookup_id_test" title="Lookup"></a>' 'class="related-lookup" id="lookup_id_test" title="Lookup"></a>'
'&nbsp;<strong><a href="/admin_widgets/inventory/%(pk)s/change/">' '&nbsp;<strong><a href="/admin_widgets/inventory/%(pk)s/change/">'
@ -519,7 +519,7 @@ class ForeignKeyRawIdWidgetTest(TestCase):
w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site) w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site)
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('honeycomb_widget', big_honeycomb.pk, attrs={}), w.render('honeycomb_widget', big_honeycomb.pk, attrs={}),
'<input type="text" name="honeycomb_widget" value="%(hcombpk)s" />' '<input type="text" name="honeycomb_widget" value="%(hcombpk)s">'
'&nbsp;<strong>%(hcomb)s</strong>' '&nbsp;<strong>%(hcomb)s</strong>'
% {'hcombpk': big_honeycomb.pk, 'hcomb': big_honeycomb} % {'hcombpk': big_honeycomb.pk, 'hcomb': big_honeycomb}
) )
@ -534,7 +534,7 @@ class ForeignKeyRawIdWidgetTest(TestCase):
w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site) w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site)
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('individual_widget', subject1.pk, attrs={}), w.render('individual_widget', subject1.pk, attrs={}),
'<input type="text" name="individual_widget" value="%(subj1pk)s" />' '<input type="text" name="individual_widget" value="%(subj1pk)s">'
'&nbsp;<strong>%(subj1)s</strong>' '&nbsp;<strong>%(subj1)s</strong>'
% {'subj1pk': subject1.pk, 'subj1': subject1} % {'subj1pk': subject1.pk, 'subj1': subject1}
) )
@ -552,7 +552,7 @@ class ForeignKeyRawIdWidgetTest(TestCase):
) )
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('test', child_of_hidden.parent_id, attrs={}), w.render('test', child_of_hidden.parent_id, attrs={}),
'<input type="text" name="test" value="93" class="vForeignKeyRawIdAdminField" />' '<input type="text" name="test" value="93" class="vForeignKeyRawIdAdminField">'
'<a href="/admin_widgets/inventory/?_to_field=barcode" ' '<a href="/admin_widgets/inventory/?_to_field=barcode" '
'class="related-lookup" id="lookup_id_test" title="Lookup"></a>' 'class="related-lookup" id="lookup_id_test" title="Lookup"></a>'
'&nbsp;<strong><a href="/admin_widgets/inventory/%(pk)s/change/">' '&nbsp;<strong><a href="/admin_widgets/inventory/%(pk)s/change/">'
@ -574,7 +574,7 @@ class ManyToManyRawIdWidgetTest(TestCase):
w = widgets.ManyToManyRawIdWidget(rel, widget_admin_site) w = widgets.ManyToManyRawIdWidget(rel, widget_admin_site)
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('test', [m1.pk, m2.pk], attrs={}), ( w.render('test', [m1.pk, m2.pk], attrs={}), (
'<input type="text" name="test" value="%(m1pk)s,%(m2pk)s" class="vManyToManyRawIdAdminField" />' '<input type="text" name="test" value="%(m1pk)s,%(m2pk)s" class="vManyToManyRawIdAdminField">'
'<a href="/admin_widgets/member/" class="related-lookup" id="lookup_id_test" title="Lookup"></a>' '<a href="/admin_widgets/member/" class="related-lookup" id="lookup_id_test" title="Lookup"></a>'
) % {'m1pk': m1.pk, 'm2pk': m2.pk} ) % {'m1pk': m1.pk, 'm2pk': m2.pk}
) )
@ -599,12 +599,12 @@ class ManyToManyRawIdWidgetTest(TestCase):
w = widgets.ManyToManyRawIdWidget(rel, widget_admin_site) w = widgets.ManyToManyRawIdWidget(rel, widget_admin_site)
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('company_widget1', [c1.pk, c2.pk], attrs={}), w.render('company_widget1', [c1.pk, c2.pk], attrs={}),
'<input type="text" name="company_widget1" value="%(c1pk)s,%(c2pk)s" />' % {'c1pk': c1.pk, 'c2pk': c2.pk} '<input type="text" name="company_widget1" value="%(c1pk)s,%(c2pk)s">' % {'c1pk': c1.pk, 'c2pk': c2.pk}
) )
self.assertHTMLEqual( self.assertHTMLEqual(
w.render('company_widget2', [c1.pk]), w.render('company_widget2', [c1.pk]),
'<input type="text" name="company_widget2" value="%(c1pk)s" />' % {'c1pk': c1.pk} '<input type="text" name="company_widget2" value="%(c1pk)s">' % {'c1pk': c1.pk}
) )

View File

@ -8,7 +8,7 @@ from django.views.decorators.csrf import ensure_csrf_cookie
def post_form_view(request): def post_form_view(request):
"""Return a POST form (without a token).""" """Return a POST form (without a token)."""
return HttpResponse(content=""" return HttpResponse(content="""
<html><body><h1>\u00a1Unicode!<form method="post"><input type="text" /></form></body></html> <html><body><h1>\u00a1Unicode!<form method="post"><input type="text"></form></body></html>
""", mimetype='text/html') """, mimetype='text/html')

View File

@ -145,7 +145,7 @@ class CharFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
def test_charfield_disabled(self): def test_charfield_disabled(self):
f = CharField(disabled=True) f = CharField(disabled=True)
self.assertWidgetRendersTo(f, '<input type="text" name="f" id="id_f" disabled required />') self.assertWidgetRendersTo(f, '<input type="text" name="f" id="id_f" disabled required>')
def test_null_characters_prohibited(self): def test_null_characters_prohibited(self):
f = CharField() f = CharField()

View File

@ -22,7 +22,7 @@ class DateFieldTest(SimpleTestCase):
# accept the input from the "as_hidden" rendering as well. # accept the input from the "as_hidden" rendering as well.
self.assertHTMLEqual( self.assertHTMLEqual(
a['mydate'].as_hidden(), a['mydate'].as_hidden(),
'<input type="hidden" name="mydate" value="2008-4-1" id="id_mydate" />', '<input type="hidden" name="mydate" value="2008-4-1" id="id_mydate">',
) )
b = GetDate({'mydate': '2008-4-1'}) b = GetDate({'mydate': '2008-4-1'})

View File

@ -11,7 +11,7 @@ class DecimalFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
def test_decimalfield_1(self): def test_decimalfield_1(self):
f = DecimalField(max_digits=4, decimal_places=2) f = DecimalField(max_digits=4, decimal_places=2)
self.assertWidgetRendersTo(f, '<input id="id_f" step="0.01" type="number" name="f" required />') self.assertWidgetRendersTo(f, '<input id="id_f" step="0.01" type="number" name="f" required>')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"): with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean('') f.clean('')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"): with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
@ -78,7 +78,7 @@ class DecimalFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
) )
self.assertWidgetRendersTo( self.assertWidgetRendersTo(
f, f,
'<input step="0.01" name="f" min="0.5" max="1.5" type="number" id="id_f" required />', '<input step="0.01" name="f" min="0.5" max="1.5" type="number" id="id_f" required>',
) )
with self.assertRaisesMessage(ValidationError, "'Ensure this value is less than or equal to 1.5.'"): with self.assertRaisesMessage(ValidationError, "'Ensure this value is less than or equal to 1.5.'"):
f.clean('1.6') f.clean('1.6')
@ -136,7 +136,7 @@ class DecimalFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
f = DecimalField(max_digits=20) f = DecimalField(max_digits=20)
self.assertEqual(f.widget_attrs(NumberInput()), {'step': 'any'}) self.assertEqual(f.widget_attrs(NumberInput()), {'step': 'any'})
f = DecimalField(max_digits=6, widget=NumberInput(attrs={'step': '0.01'})) f = DecimalField(max_digits=6, widget=NumberInput(attrs={'step': '0.01'}))
self.assertWidgetRendersTo(f, '<input step="0.01" name="f" type="number" id="id_f" required />') self.assertWidgetRendersTo(f, '<input step="0.01" name="f" type="number" id="id_f" required>')
def test_decimalfield_localized(self): def test_decimalfield_localized(self):
""" """
@ -144,7 +144,7 @@ class DecimalFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
number input specific attributes. number input specific attributes.
""" """
f = DecimalField(localize=True) f = DecimalField(localize=True)
self.assertWidgetRendersTo(f, '<input id="id_f" name="f" type="text" required />') self.assertWidgetRendersTo(f, '<input id="id_f" name="f" type="text" required>')
def test_decimalfield_changed(self): def test_decimalfield_changed(self):
f = DecimalField(max_digits=2, decimal_places=2) f = DecimalField(max_digits=2, decimal_places=2)

View File

@ -8,7 +8,7 @@ class EmailFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
def test_emailfield_1(self): def test_emailfield_1(self):
f = EmailField() f = EmailField()
self.assertWidgetRendersTo(f, '<input type="email" name="f" id="id_f" required />') self.assertWidgetRendersTo(f, '<input type="email" name="f" id="id_f" required>')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"): with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean('') f.clean('')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"): with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
@ -41,7 +41,7 @@ class EmailFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
f = EmailField(min_length=10, max_length=15) f = EmailField(min_length=10, max_length=15)
self.assertWidgetRendersTo( self.assertWidgetRendersTo(
f, f,
'<input id="id_f" type="email" name="f" maxlength="15" minlength="10" required />', '<input id="id_f" type="email" name="f" maxlength="15" minlength="10" required>',
) )
with self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 10 characters (it has 9).'"): with self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 10 characters (it has 9).'"):
f.clean('a@foo.com') f.clean('a@foo.com')

View File

@ -10,7 +10,7 @@ class FloatFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
def test_floatfield_1(self): def test_floatfield_1(self):
f = FloatField() f = FloatField()
self.assertWidgetRendersTo(f, '<input step="any" type="number" name="f" id="id_f" required />') self.assertWidgetRendersTo(f, '<input step="any" type="number" name="f" id="id_f" required>')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"): with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean('') f.clean('')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"): with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
@ -49,7 +49,7 @@ class FloatFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
f = FloatField(max_value=1.5, min_value=0.5) f = FloatField(max_value=1.5, min_value=0.5)
self.assertWidgetRendersTo( self.assertWidgetRendersTo(
f, f,
'<input step="any" name="f" min="0.5" max="1.5" type="number" id="id_f" required />', '<input step="any" name="f" min="0.5" max="1.5" type="number" id="id_f" required>',
) )
with self.assertRaisesMessage(ValidationError, "'Ensure this value is less than or equal to 1.5.'"): with self.assertRaisesMessage(ValidationError, "'Ensure this value is less than or equal to 1.5.'"):
f.clean('1.6') f.clean('1.6')
@ -64,7 +64,7 @@ class FloatFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
f = FloatField(widget=NumberInput(attrs={'step': 0.01, 'max': 1.0, 'min': 0.0})) f = FloatField(widget=NumberInput(attrs={'step': 0.01, 'max': 1.0, 'min': 0.0}))
self.assertWidgetRendersTo( self.assertWidgetRendersTo(
f, f,
'<input step="0.01" name="f" min="0.0" max="1.0" type="number" id="id_f" required />', '<input step="0.01" name="f" min="0.0" max="1.0" type="number" id="id_f" required>',
) )
def test_floatfield_localized(self): def test_floatfield_localized(self):
@ -73,7 +73,7 @@ class FloatFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
number input specific attributes. number input specific attributes.
""" """
f = FloatField(localize=True) f = FloatField(localize=True)
self.assertWidgetRendersTo(f, '<input id="id_f" name="f" type="text" required />') self.assertWidgetRendersTo(f, '<input id="id_f" name="f" type="text" required>')
def test_floatfield_changed(self): def test_floatfield_changed(self):
f = FloatField() f = FloatField()

View File

@ -8,7 +8,7 @@ class IntegerFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
def test_integerfield_1(self): def test_integerfield_1(self):
f = IntegerField() f = IntegerField()
self.assertWidgetRendersTo(f, '<input type="number" name="f" id="id_f" required />') self.assertWidgetRendersTo(f, '<input type="number" name="f" id="id_f" required>')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"): with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean('') f.clean('')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"): with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
@ -50,7 +50,7 @@ class IntegerFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
def test_integerfield_3(self): def test_integerfield_3(self):
f = IntegerField(max_value=10) f = IntegerField(max_value=10)
self.assertWidgetRendersTo(f, '<input max="10" type="number" name="f" id="id_f" required />') self.assertWidgetRendersTo(f, '<input max="10" type="number" name="f" id="id_f" required>')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"): with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean(None) f.clean(None)
self.assertEqual(1, f.clean(1)) self.assertEqual(1, f.clean(1))
@ -65,7 +65,7 @@ class IntegerFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
def test_integerfield_4(self): def test_integerfield_4(self):
f = IntegerField(min_value=10) f = IntegerField(min_value=10)
self.assertWidgetRendersTo(f, '<input id="id_f" type="number" name="f" min="10" required />') self.assertWidgetRendersTo(f, '<input id="id_f" type="number" name="f" min="10" required>')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"): with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean(None) f.clean(None)
with self.assertRaisesMessage(ValidationError, "'Ensure this value is greater than or equal to 10.'"): with self.assertRaisesMessage(ValidationError, "'Ensure this value is greater than or equal to 10.'"):
@ -79,7 +79,7 @@ class IntegerFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
def test_integerfield_5(self): def test_integerfield_5(self):
f = IntegerField(min_value=10, max_value=20) f = IntegerField(min_value=10, max_value=20)
self.assertWidgetRendersTo(f, '<input id="id_f" max="20" type="number" name="f" min="10" required />') self.assertWidgetRendersTo(f, '<input id="id_f" max="20" type="number" name="f" min="10" required>')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"): with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean(None) f.clean(None)
with self.assertRaisesMessage(ValidationError, "'Ensure this value is greater than or equal to 10.'"): with self.assertRaisesMessage(ValidationError, "'Ensure this value is greater than or equal to 10.'"):
@ -100,7 +100,7 @@ class IntegerFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
number input specific attributes. number input specific attributes.
""" """
f1 = IntegerField(localize=True) f1 = IntegerField(localize=True)
self.assertWidgetRendersTo(f1, '<input id="id_f" name="f" type="text" required />') self.assertWidgetRendersTo(f1, '<input id="id_f" name="f" type="text" required>')
def test_integerfield_float(self): def test_integerfield_float(self):
f = IntegerField() f = IntegerField()

View File

@ -128,15 +128,15 @@ class MultiValueFieldTest(SimpleTestCase):
form.as_table(), form.as_table(),
""" """
<tr><th><label for="id_field1_0">Field1:</label></th> <tr><th><label for="id_field1_0">Field1:</label></th>
<td><input type="text" name="field1_0" id="id_field1_0" required /> <td><input type="text" name="field1_0" id="id_field1_0" required>
<select multiple name="field1_1" id="id_field1_1" required> <select multiple name="field1_1" id="id_field1_1" required>
<option value="J">John</option> <option value="J">John</option>
<option value="P">Paul</option> <option value="P">Paul</option>
<option value="G">George</option> <option value="G">George</option>
<option value="R">Ringo</option> <option value="R">Ringo</option>
</select> </select>
<input type="text" name="field1_2_0" id="id_field1_2_0" required /> <input type="text" name="field1_2_0" id="id_field1_2_0" required>
<input type="text" name="field1_2_1" id="id_field1_2_1" required /></td></tr> <input type="text" name="field1_2_1" id="id_field1_2_1" required></td></tr>
""", """,
) )
@ -151,15 +151,15 @@ class MultiValueFieldTest(SimpleTestCase):
form.as_table(), form.as_table(),
""" """
<tr><th><label for="id_field1_0">Field1:</label></th> <tr><th><label for="id_field1_0">Field1:</label></th>
<td><input type="text" name="field1_0" value="some text" id="id_field1_0" required /> <td><input type="text" name="field1_0" value="some text" id="id_field1_0" required>
<select multiple name="field1_1" id="id_field1_1" required> <select multiple name="field1_1" id="id_field1_1" required>
<option value="J" selected>John</option> <option value="J" selected>John</option>
<option value="P" selected>Paul</option> <option value="P" selected>Paul</option>
<option value="G">George</option> <option value="G">George</option>
<option value="R">Ringo</option> <option value="R">Ringo</option>
</select> </select>
<input type="text" name="field1_2_0" value="2007-04-25" id="id_field1_2_0" required /> <input type="text" name="field1_2_0" value="2007-04-25" id="id_field1_2_0" required>
<input type="text" name="field1_2_1" value="06:24:00" id="id_field1_2_1" required /></td></tr> <input type="text" name="field1_2_1" value="06:24:00" id="id_field1_2_1" required></td></tr>
""", """,
) )

View File

@ -27,8 +27,8 @@ class NullBooleanFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
hidden_nullbool2 = NullBooleanField(widget=HiddenInput, initial=False) hidden_nullbool2 = NullBooleanField(widget=HiddenInput, initial=False)
f = HiddenNullBooleanForm() f = HiddenNullBooleanForm()
self.assertHTMLEqual( self.assertHTMLEqual(
'<input type="hidden" name="hidden_nullbool1" value="True" id="id_hidden_nullbool1" />' '<input type="hidden" name="hidden_nullbool1" value="True" id="id_hidden_nullbool1">'
'<input type="hidden" name="hidden_nullbool2" value="False" id="id_hidden_nullbool2" />', '<input type="hidden" name="hidden_nullbool2" value="False" id="id_hidden_nullbool2">',
str(f) str(f)
) )

View File

@ -8,7 +8,7 @@ class URLFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
def test_urlfield_1(self): def test_urlfield_1(self):
f = URLField() f = URLField()
self.assertWidgetRendersTo(f, '<input type="url" name="f" id="id_f" required />') self.assertWidgetRendersTo(f, '<input type="url" name="f" id="id_f" required>')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"): with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean('') f.clean('')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"): with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
@ -88,7 +88,7 @@ class URLFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
def test_urlfield_5(self): def test_urlfield_5(self):
f = URLField(min_length=15, max_length=20) f = URLField(min_length=15, max_length=20)
self.assertWidgetRendersTo(f, '<input id="id_f" type="url" name="f" maxlength="20" minlength="15" required />') self.assertWidgetRendersTo(f, '<input id="id_f" type="url" name="f" maxlength="20" minlength="15" required>')
with self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 15 characters (it has 12).'"): with self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 15 characters (it has 12).'"):
f.clean('http://f.com') f.clean('http://f.com')
self.assertEqual('http://example.com', f.clean('http://example.com')) self.assertEqual('http://example.com', f.clean('http://example.com'))

File diff suppressed because it is too large Load Diff

View File

@ -87,12 +87,12 @@ class FormsFormsetTestCase(SimpleTestCase):
formset = self.make_choiceformset() formset = self.make_choiceformset()
self.assertHTMLEqual( self.assertHTMLEqual(
str(formset), str(formset),
"""<input type="hidden" name="choices-TOTAL_FORMS" value="1" /> """<input type="hidden" name="choices-TOTAL_FORMS" value="1">
<input type="hidden" name="choices-INITIAL_FORMS" value="0" /> <input type="hidden" name="choices-INITIAL_FORMS" value="0">
<input type="hidden" name="choices-MIN_NUM_FORMS" value="0" /> <input type="hidden" name="choices-MIN_NUM_FORMS" value="0">
<input type="hidden" name="choices-MAX_NUM_FORMS" value="1000" /> <input type="hidden" name="choices-MAX_NUM_FORMS" value="1000">
<tr><th>Choice:</th><td><input type="text" name="choices-0-choice" /></td></tr> <tr><th>Choice:</th><td><input type="text" name="choices-0-choice"></td></tr>
<tr><th>Votes:</th><td><input type="number" name="choices-0-votes" /></td></tr>""" <tr><th>Votes:</th><td><input type="number" name="choices-0-votes"></td></tr>"""
) )
# FormSet are treated similarly to Forms. FormSet has an is_valid() # FormSet are treated similarly to Forms. FormSet has an is_valid()
# method, and a cleaned_data or errors attribute depending on whether # method, and a cleaned_data or errors attribute depending on whether
@ -199,10 +199,10 @@ class FormsFormsetTestCase(SimpleTestCase):
form_output.append(form.as_ul()) form_output.append(form.as_ul())
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico"></li>
<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> <li>Votes: <input type="number" name="choices-0-votes" value="100"></li>
<li>Choice: <input type="text" name="choices-1-choice" /></li> <li>Choice: <input type="text" name="choices-1-choice"></li>
<li>Votes: <input type="number" name="choices-1-votes" /></li>""" <li>Votes: <input type="number" name="choices-1-votes"></li>"""
) )
def test_blank_form_unfilled(self): def test_blank_form_unfilled(self):
@ -244,12 +244,12 @@ class FormsFormsetTestCase(SimpleTestCase):
form_output.append(form.as_ul()) form_output.append(form.as_ul())
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<li>Choice: <input type="text" name="choices-0-choice" /></li> """<li>Choice: <input type="text" name="choices-0-choice"></li>
<li>Votes: <input type="number" name="choices-0-votes" /></li> <li>Votes: <input type="number" name="choices-0-votes"></li>
<li>Choice: <input type="text" name="choices-1-choice" /></li> <li>Choice: <input type="text" name="choices-1-choice"></li>
<li>Votes: <input type="number" name="choices-1-votes" /></li> <li>Votes: <input type="number" name="choices-1-votes"></li>
<li>Choice: <input type="text" name="choices-2-choice" /></li> <li>Choice: <input type="text" name="choices-2-choice"></li>
<li>Votes: <input type="number" name="choices-2-votes" /></li>""" <li>Votes: <input type="number" name="choices-2-votes"></li>"""
) )
# Since every form was displayed as blank, they are also accepted as # Since every form was displayed as blank, they are also accepted as
# blank. This may seem a little strange, but min_num is used to require # blank. This may seem a little strange, but min_num is used to require
@ -285,10 +285,10 @@ class FormsFormsetTestCase(SimpleTestCase):
self.assertTrue(formset.forms[1].empty_permitted) self.assertTrue(formset.forms[1].empty_permitted)
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<li>Choice: <input type="text" name="choices-0-choice" /></li> """<li>Choice: <input type="text" name="choices-0-choice"></li>
<li>Votes: <input type="number" name="choices-0-votes" /></li> <li>Votes: <input type="number" name="choices-0-votes"></li>
<li>Choice: <input type="text" name="choices-1-choice" /></li> <li>Choice: <input type="text" name="choices-1-choice"></li>
<li>Votes: <input type="number" name="choices-1-votes" /></li>""" <li>Votes: <input type="number" name="choices-1-votes"></li>"""
) )
def test_min_num_displaying_more_than_one_blank_form_with_zero_extra(self): def test_min_num_displaying_more_than_one_blank_form_with_zero_extra(self):
@ -300,12 +300,12 @@ class FormsFormsetTestCase(SimpleTestCase):
form_output.append(form.as_ul()) form_output.append(form.as_ul())
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<li>Choice: <input type="text" name="choices-0-choice" /></li> """<li>Choice: <input type="text" name="choices-0-choice"></li>
<li>Votes: <input type="number" name="choices-0-votes" /></li> <li>Votes: <input type="number" name="choices-0-votes"></li>
<li>Choice: <input type="text" name="choices-1-choice" /></li> <li>Choice: <input type="text" name="choices-1-choice"></li>
<li>Votes: <input type="number" name="choices-1-votes" /></li> <li>Votes: <input type="number" name="choices-1-votes"></li>
<li>Choice: <input type="text" name="choices-2-choice" /></li> <li>Choice: <input type="text" name="choices-2-choice"></li>
<li>Votes: <input type="number" name="choices-2-votes" /></li>""" <li>Votes: <input type="number" name="choices-2-votes"></li>"""
) )
def test_single_form_completed(self): def test_single_form_completed(self):
@ -439,21 +439,21 @@ class FormsFormsetTestCase(SimpleTestCase):
form_output.append(form.as_ul()) form_output.append(form.as_ul())
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico"></li>
<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> <li>Votes: <input type="number" name="choices-0-votes" value="100"></li>
<li>Choice: <input type="text" name="choices-1-choice" /></li> <li>Choice: <input type="text" name="choices-1-choice"></li>
<li>Votes: <input type="number" name="choices-1-votes" /></li> <li>Votes: <input type="number" name="choices-1-votes"></li>
<li>Choice: <input type="text" name="choices-2-choice" /></li> <li>Choice: <input type="text" name="choices-2-choice"></li>
<li>Votes: <input type="number" name="choices-2-votes" /></li> <li>Votes: <input type="number" name="choices-2-votes"></li>
<li>Choice: <input type="text" name="choices-3-choice" /></li> <li>Choice: <input type="text" name="choices-3-choice"></li>
<li>Votes: <input type="number" name="choices-3-votes" /></li>""" <li>Votes: <input type="number" name="choices-3-votes"></li>"""
) )
# Retrieving an empty form works. Tt shows up in the form list. # Retrieving an empty form works. Tt shows up in the form list.
self.assertTrue(formset.empty_form.empty_permitted) self.assertTrue(formset.empty_form.empty_permitted)
self.assertHTMLEqual( self.assertHTMLEqual(
formset.empty_form.as_ul(), formset.empty_form.as_ul(),
"""<li>Choice: <input type="text" name="choices-__prefix__-choice" /></li> """<li>Choice: <input type="text" name="choices-__prefix__-choice"></li>
<li>Votes: <input type="number" name="choices-__prefix__-votes" /></li>""" <li>Votes: <input type="number" name="choices-__prefix__-votes"></li>"""
) )
def test_formset_with_deletion(self): def test_formset_with_deletion(self):
@ -470,15 +470,15 @@ class FormsFormsetTestCase(SimpleTestCase):
form_output.append(form.as_ul()) form_output.append(form.as_ul())
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico"></li>
<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> <li>Votes: <input type="number" name="choices-0-votes" value="100"></li>
<li>Delete: <input type="checkbox" name="choices-0-DELETE" /></li> <li>Delete: <input type="checkbox" name="choices-0-DELETE"></li>
<li>Choice: <input type="text" name="choices-1-choice" value="Fergie" /></li> <li>Choice: <input type="text" name="choices-1-choice" value="Fergie"></li>
<li>Votes: <input type="number" name="choices-1-votes" value="900" /></li> <li>Votes: <input type="number" name="choices-1-votes" value="900"></li>
<li>Delete: <input type="checkbox" name="choices-1-DELETE" /></li> <li>Delete: <input type="checkbox" name="choices-1-DELETE"></li>
<li>Choice: <input type="text" name="choices-2-choice" /></li> <li>Choice: <input type="text" name="choices-2-choice"></li>
<li>Votes: <input type="number" name="choices-2-votes" /></li> <li>Votes: <input type="number" name="choices-2-votes"></li>
<li>Delete: <input type="checkbox" name="choices-2-DELETE" /></li>""" <li>Delete: <input type="checkbox" name="choices-2-DELETE"></li>"""
) )
# To delete something, set that form's special delete field to 'on'. # To delete something, set that form's special delete field to 'on'.
# Let's go ahead and delete Fergie. # Let's go ahead and delete Fergie.
@ -580,15 +580,15 @@ class FormsFormsetTestCase(SimpleTestCase):
form_output.append(form.as_ul()) form_output.append(form.as_ul())
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico"></li>
<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> <li>Votes: <input type="number" name="choices-0-votes" value="100"></li>
<li>Order: <input type="number" name="choices-0-ORDER" value="1" /></li> <li>Order: <input type="number" name="choices-0-ORDER" value="1"></li>
<li>Choice: <input type="text" name="choices-1-choice" value="Fergie" /></li> <li>Choice: <input type="text" name="choices-1-choice" value="Fergie"></li>
<li>Votes: <input type="number" name="choices-1-votes" value="900" /></li> <li>Votes: <input type="number" name="choices-1-votes" value="900"></li>
<li>Order: <input type="number" name="choices-1-ORDER" value="2" /></li> <li>Order: <input type="number" name="choices-1-ORDER" value="2"></li>
<li>Choice: <input type="text" name="choices-2-choice" /></li> <li>Choice: <input type="text" name="choices-2-choice"></li>
<li>Votes: <input type="number" name="choices-2-votes" /></li> <li>Votes: <input type="number" name="choices-2-votes"></li>
<li>Order: <input type="number" name="choices-2-ORDER" /></li>""" <li>Order: <input type="number" name="choices-2-ORDER"></li>"""
) )
data = { data = {
'choices-TOTAL_FORMS': '3', # the number of forms rendered 'choices-TOTAL_FORMS': '3', # the number of forms rendered
@ -684,22 +684,22 @@ class FormsFormsetTestCase(SimpleTestCase):
form_output.append(form.as_ul()) form_output.append(form.as_ul())
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico"></li>
<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> <li>Votes: <input type="number" name="choices-0-votes" value="100"></li>
<li>Order: <input type="number" name="choices-0-ORDER" value="1" /></li> <li>Order: <input type="number" name="choices-0-ORDER" value="1"></li>
<li>Delete: <input type="checkbox" name="choices-0-DELETE" /></li> <li>Delete: <input type="checkbox" name="choices-0-DELETE"></li>
<li>Choice: <input type="text" name="choices-1-choice" value="Fergie" /></li> <li>Choice: <input type="text" name="choices-1-choice" value="Fergie"></li>
<li>Votes: <input type="number" name="choices-1-votes" value="900" /></li> <li>Votes: <input type="number" name="choices-1-votes" value="900"></li>
<li>Order: <input type="number" name="choices-1-ORDER" value="2" /></li> <li>Order: <input type="number" name="choices-1-ORDER" value="2"></li>
<li>Delete: <input type="checkbox" name="choices-1-DELETE" /></li> <li>Delete: <input type="checkbox" name="choices-1-DELETE"></li>
<li>Choice: <input type="text" name="choices-2-choice" value="The Decemberists" /></li> <li>Choice: <input type="text" name="choices-2-choice" value="The Decemberists"></li>
<li>Votes: <input type="number" name="choices-2-votes" value="500" /></li> <li>Votes: <input type="number" name="choices-2-votes" value="500"></li>
<li>Order: <input type="number" name="choices-2-ORDER" value="3" /></li> <li>Order: <input type="number" name="choices-2-ORDER" value="3"></li>
<li>Delete: <input type="checkbox" name="choices-2-DELETE" /></li> <li>Delete: <input type="checkbox" name="choices-2-DELETE"></li>
<li>Choice: <input type="text" name="choices-3-choice" /></li> <li>Choice: <input type="text" name="choices-3-choice"></li>
<li>Votes: <input type="number" name="choices-3-votes" /></li> <li>Votes: <input type="number" name="choices-3-votes"></li>
<li>Order: <input type="number" name="choices-3-ORDER" /></li> <li>Order: <input type="number" name="choices-3-ORDER"></li>
<li>Delete: <input type="checkbox" name="choices-3-DELETE" /></li>""" <li>Delete: <input type="checkbox" name="choices-3-DELETE"></li>"""
) )
# Let's delete Fergie, and put The Decemberists ahead of Calexico. # Let's delete Fergie, and put The Decemberists ahead of Calexico.
data = { data = {
@ -803,11 +803,11 @@ class FormsFormsetTestCase(SimpleTestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<tr><th><label for="id_form-0-name">Name:</label></th> """<tr><th><label for="id_form-0-name">Name:</label></th>
<td><input type="text" name="form-0-name" id="id_form-0-name" /></td></tr> <td><input type="text" name="form-0-name" id="id_form-0-name"></td></tr>
<tr><th><label for="id_form-1-name">Name:</label></th> <tr><th><label for="id_form-1-name">Name:</label></th>
<td><input type="text" name="form-1-name" id="id_form-1-name" /></td></tr> <td><input type="text" name="form-1-name" id="id_form-1-name"></td></tr>
<tr><th><label for="id_form-2-name">Name:</label></th> <tr><th><label for="id_form-2-name">Name:</label></th>
<td><input type="text" name="form-2-name" id="id_form-2-name" /></td></tr>""" <td><input type="text" name="form-2-name" id="id_form-2-name"></td></tr>"""
) )
# If max_num is 0 then no form is rendered at all. # If max_num is 0 then no form is rendered at all.
LimitedFavoriteDrinkFormSet = formset_factory(FavoriteDrinkForm, extra=3, max_num=0) LimitedFavoriteDrinkFormSet = formset_factory(FavoriteDrinkForm, extra=3, max_num=0)
@ -826,9 +826,9 @@ class FormsFormsetTestCase(SimpleTestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<tr><th><label for="id_form-0-name">Name:</label></th><td> """<tr><th><label for="id_form-0-name">Name:</label></th><td>
<input type="text" name="form-0-name" id="id_form-0-name" /></td></tr> <input type="text" name="form-0-name" id="id_form-0-name"></td></tr>
<tr><th><label for="id_form-1-name">Name:</label></th> <tr><th><label for="id_form-1-name">Name:</label></th>
<td><input type="text" name="form-1-name" id="id_form-1-name" /></td></tr>""" <td><input type="text" name="form-1-name" id="id_form-1-name"></td></tr>"""
) )
def test_limiting_extra_lest_than_max_num(self): def test_limiting_extra_lest_than_max_num(self):
@ -841,7 +841,7 @@ class FormsFormsetTestCase(SimpleTestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<tr><th><label for="id_form-0-name">Name:</label></th> """<tr><th><label for="id_form-0-name">Name:</label></th>
<td><input type="text" name="form-0-name" id="id_form-0-name" /></td></tr>""" <td><input type="text" name="form-0-name" id="id_form-0-name"></td></tr>"""
) )
def test_max_num_with_initial_data(self): def test_max_num_with_initial_data(self):
@ -860,9 +860,9 @@ class FormsFormsetTestCase(SimpleTestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<tr><th><label for="id_form-0-name">Name:</label></th> """<tr><th><label for="id_form-0-name">Name:</label></th>
<td><input type="text" name="form-0-name" value="Fernet and Coke" id="id_form-0-name" /></td></tr> <td><input type="text" name="form-0-name" value="Fernet and Coke" id="id_form-0-name"></td></tr>
<tr><th><label for="id_form-1-name">Name:</label></th> <tr><th><label for="id_form-1-name">Name:</label></th>
<td><input type="text" name="form-1-name" id="id_form-1-name" /></td></tr>""" <td><input type="text" name="form-1-name" id="id_form-1-name"></td></tr>"""
) )
def test_max_num_zero(self): def test_max_num_zero(self):
@ -891,9 +891,9 @@ class FormsFormsetTestCase(SimpleTestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<tr><th><label for="id_form-0-name">Name:</label></th> """<tr><th><label for="id_form-0-name">Name:</label></th>
<td><input id="id_form-0-name" name="form-0-name" type="text" value="Fernet and Coke" /></td></tr> <td><input id="id_form-0-name" name="form-0-name" type="text" value="Fernet and Coke"></td></tr>
<tr><th><label for="id_form-1-name">Name:</label></th> <tr><th><label for="id_form-1-name">Name:</label></th>
<td><input id="id_form-1-name" name="form-1-name" type="text" value="Bloody Mary" /></td></tr>""" <td><input id="id_form-1-name" name="form-1-name" type="text" value="Bloody Mary"></td></tr>"""
) )
def test_more_initial_than_max_num(self): def test_more_initial_than_max_num(self):
@ -914,11 +914,11 @@ class FormsFormsetTestCase(SimpleTestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<tr><th><label for="id_form-0-name">Name:</label></th> """<tr><th><label for="id_form-0-name">Name:</label></th>
<td><input id="id_form-0-name" name="form-0-name" type="text" value="Gin Tonic" /></td></tr> <td><input id="id_form-0-name" name="form-0-name" type="text" value="Gin Tonic"></td></tr>
<tr><th><label for="id_form-1-name">Name:</label></th> <tr><th><label for="id_form-1-name">Name:</label></th>
<td><input id="id_form-1-name" name="form-1-name" type="text" value="Bloody Mary" /></td></tr> <td><input id="id_form-1-name" name="form-1-name" type="text" value="Bloody Mary"></td></tr>
<tr><th><label for="id_form-2-name">Name:</label></th> <tr><th><label for="id_form-2-name">Name:</label></th>
<td><input id="id_form-2-name" name="form-2-name" type="text" value="Jack and Coke" /></td></tr>""" <td><input id="id_form-2-name" name="form-2-name" type="text" value="Jack and Coke"></td></tr>"""
) )
def test_more_initial_form_result_in_one(self): def test_more_initial_form_result_in_one(self):
@ -937,9 +937,9 @@ class FormsFormsetTestCase(SimpleTestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
'\n'.join(form_output), '\n'.join(form_output),
"""<tr><th><label for="id_form-0-name">Name:</label></th> """<tr><th><label for="id_form-0-name">Name:</label></th>
<td><input type="text" name="form-0-name" value="Gin Tonic" id="id_form-0-name" /></td></tr> <td><input type="text" name="form-0-name" value="Gin Tonic" id="id_form-0-name"></td></tr>
<tr><th><label for="id_form-1-name">Name:</label></th> <tr><th><label for="id_form-1-name">Name:</label></th>
<td><input type="text" name="form-1-name" id="id_form-1-name" /></td></tr>""" <td><input type="text" name="form-1-name" id="id_form-1-name"></td></tr>"""
) )
def test_management_form_prefix(self): def test_management_form_prefix(self):
@ -1195,36 +1195,36 @@ class FormsetAsFooTests(SimpleTestCase):
formset = ChoiceFormSet(data, auto_id=False, prefix='choices') formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
self.assertHTMLEqual( self.assertHTMLEqual(
formset.as_table(), formset.as_table(),
"""<input type="hidden" name="choices-TOTAL_FORMS" value="1" /> """<input type="hidden" name="choices-TOTAL_FORMS" value="1">
<input type="hidden" name="choices-INITIAL_FORMS" value="0" /> <input type="hidden" name="choices-INITIAL_FORMS" value="0">
<input type="hidden" name="choices-MIN_NUM_FORMS" value="0" /> <input type="hidden" name="choices-MIN_NUM_FORMS" value="0">
<input type="hidden" name="choices-MAX_NUM_FORMS" value="0" /> <input type="hidden" name="choices-MAX_NUM_FORMS" value="0">
<tr><th>Choice:</th><td><input type="text" name="choices-0-choice" value="Calexico" /></td></tr> <tr><th>Choice:</th><td><input type="text" name="choices-0-choice" value="Calexico"></td></tr>
<tr><th>Votes:</th><td><input type="number" name="choices-0-votes" value="100" /></td></tr>""" <tr><th>Votes:</th><td><input type="number" name="choices-0-votes" value="100"></td></tr>"""
) )
def test_as_p(self): def test_as_p(self):
formset = ChoiceFormSet(data, auto_id=False, prefix='choices') formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
self.assertHTMLEqual( self.assertHTMLEqual(
formset.as_p(), formset.as_p(),
"""<input type="hidden" name="choices-TOTAL_FORMS" value="1" /> """<input type="hidden" name="choices-TOTAL_FORMS" value="1">
<input type="hidden" name="choices-INITIAL_FORMS" value="0" /> <input type="hidden" name="choices-INITIAL_FORMS" value="0">
<input type="hidden" name="choices-MIN_NUM_FORMS" value="0" /> <input type="hidden" name="choices-MIN_NUM_FORMS" value="0">
<input type="hidden" name="choices-MAX_NUM_FORMS" value="0" /> <input type="hidden" name="choices-MAX_NUM_FORMS" value="0">
<p>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></p> <p>Choice: <input type="text" name="choices-0-choice" value="Calexico"></p>
<p>Votes: <input type="number" name="choices-0-votes" value="100" /></p>""" <p>Votes: <input type="number" name="choices-0-votes" value="100"></p>"""
) )
def test_as_ul(self): def test_as_ul(self):
formset = ChoiceFormSet(data, auto_id=False, prefix='choices') formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
self.assertHTMLEqual( self.assertHTMLEqual(
formset.as_ul(), formset.as_ul(),
"""<input type="hidden" name="choices-TOTAL_FORMS" value="1" /> """<input type="hidden" name="choices-TOTAL_FORMS" value="1">
<input type="hidden" name="choices-INITIAL_FORMS" value="0" /> <input type="hidden" name="choices-INITIAL_FORMS" value="0">
<input type="hidden" name="choices-MIN_NUM_FORMS" value="0" /> <input type="hidden" name="choices-MIN_NUM_FORMS" value="0">
<input type="hidden" name="choices-MAX_NUM_FORMS" value="0" /> <input type="hidden" name="choices-MAX_NUM_FORMS" value="0">
<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> <li>Choice: <input type="text" name="choices-0-choice" value="Calexico"></li>
<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li>""" <li>Votes: <input type="number" name="choices-0-votes" value="100"></li>"""
) )

View File

@ -15,7 +15,7 @@ class FormsI18nTests(SimpleTestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
f.as_p(), f.as_p(),
'<p><label for="id_username">username:</label>' '<p><label for="id_username">username:</label>'
'<input id="id_username" type="text" name="username" maxlength="10" required /></p>' '<input id="id_username" type="text" name="username" maxlength="10" required></p>'
) )
# Translations are done at rendering time, so multi-lingual apps can define forms) # Translations are done at rendering time, so multi-lingual apps can define forms)
@ -23,13 +23,13 @@ class FormsI18nTests(SimpleTestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
f.as_p(), f.as_p(),
'<p><label for="id_username">Benutzername:</label>' '<p><label for="id_username">Benutzername:</label>'
'<input id="id_username" type="text" name="username" maxlength="10" required /></p>' '<input id="id_username" type="text" name="username" maxlength="10" required></p>'
) )
with translation.override('pl'): with translation.override('pl'):
self.assertHTMLEqual( self.assertHTMLEqual(
f.as_p(), f.as_p(),
'<p><label for="id_username">u\u017cytkownik:</label>' '<p><label for="id_username">u\u017cytkownik:</label>'
'<input id="id_username" type="text" name="username" maxlength="10" required /></p>' '<input id="id_username" type="text" name="username" maxlength="10" required></p>'
) )
def test_non_ascii_label(self): def test_non_ascii_label(self):
@ -59,12 +59,12 @@ class FormsI18nTests(SimpleTestCase):
'<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label>' '<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label>'
'<ul id="id_somechoice">\n' '<ul id="id_somechoice">\n'
'<li><label for="id_somechoice_0">' '<li><label for="id_somechoice_0">'
'<input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" required /> ' '<input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" required> '
'En tied\xe4</label></li>\n' 'En tied\xe4</label></li>\n'
'<li><label for="id_somechoice_1">' '<li><label for="id_somechoice_1">'
'<input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" required /> ' '<input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" required> '
'Mies</label></li>\n<li><label for="id_somechoice_2">' 'Mies</label></li>\n<li><label for="id_somechoice_2">'
'<input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" required /> ' '<input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" required> '
'Nainen</label></li>\n</ul></p>' 'Nainen</label></li>\n</ul></p>'
) )
@ -78,12 +78,12 @@ class FormsI18nTests(SimpleTestCase):
'\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n' '\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n'
'<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label>' '<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label>'
' <ul id="id_somechoice">\n<li><label for="id_somechoice_0">' ' <ul id="id_somechoice">\n<li><label for="id_somechoice_0">'
'<input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" required /> ' '<input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" required> '
'En tied\xe4</label></li>\n' 'En tied\xe4</label></li>\n'
'<li><label for="id_somechoice_1">' '<li><label for="id_somechoice_1">'
'<input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" required /> ' '<input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" required> '
'Mies</label></li>\n<li><label for="id_somechoice_2">' 'Mies</label></li>\n<li><label for="id_somechoice_2">'
'<input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" required /> ' '<input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" required> '
'Nainen</label></li>\n</ul></p>' 'Nainen</label></li>\n</ul></p>'
) )

View File

@ -19,8 +19,8 @@ class FormsMediaTestCase(SimpleTestCase):
) )
self.assertEqual( self.assertEqual(
str(m), str(m),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script> <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""" <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
@ -40,8 +40,8 @@ class FormsMediaTestCase(SimpleTestCase):
m3 = Media(Foo) m3 = Media(Foo)
self.assertEqual( self.assertEqual(
str(m3), str(m3),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script> <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""" <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
@ -72,8 +72,8 @@ class FormsMediaTestCase(SimpleTestCase):
w1 = MyWidget1() w1 = MyWidget1()
self.assertEqual( self.assertEqual(
str(w1.media), str(w1.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script> <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""" <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
@ -82,8 +82,8 @@ class FormsMediaTestCase(SimpleTestCase):
# Media objects can be interrogated by media type # Media objects can be interrogated by media type
self.assertEqual( self.assertEqual(
str(w1.media['css']), str(w1.media['css']),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />""" <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">"""
) )
self.assertEqual( self.assertEqual(
@ -122,9 +122,9 @@ class FormsMediaTestCase(SimpleTestCase):
w3 = MyWidget3() w3 = MyWidget3()
self.assertEqual( self.assertEqual(
str(w1.media + w2.media + w3.media), str(w1.media + w2.media + w3.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script> <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
@ -134,8 +134,8 @@ class FormsMediaTestCase(SimpleTestCase):
# media addition hasn't affected the original objects # media addition hasn't affected the original objects
self.assertEqual( self.assertEqual(
str(w1.media), str(w1.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script> <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""" <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
@ -150,7 +150,7 @@ class FormsMediaTestCase(SimpleTestCase):
js = ('/path/to/js1', '/path/to/js1') js = ('/path/to/js1', '/path/to/js1')
w4 = MyWidget4() w4 = MyWidget4()
self.assertEqual(str(w4.media), """<link href="/path/to/css1" type="text/css" media="all" rel="stylesheet" /> self.assertEqual(str(w4.media), """<link href="/path/to/css1" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script>""") <script type="text/javascript" src="/path/to/js1"></script>""")
def test_media_property(self): def test_media_property(self):
@ -165,7 +165,7 @@ class FormsMediaTestCase(SimpleTestCase):
media = property(_media) media = property(_media)
w4 = MyWidget4() w4 = MyWidget4()
self.assertEqual(str(w4.media), """<link href="/some/path" type="text/css" media="all" rel="stylesheet" /> self.assertEqual(str(w4.media), """<link href="/some/path" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/some/js"></script>""") <script type="text/javascript" src="/some/js"></script>""")
# Media properties can reference the media of their parents # Media properties can reference the media of their parents
@ -175,8 +175,8 @@ class FormsMediaTestCase(SimpleTestCase):
media = property(_media) media = property(_media)
w5 = MyWidget5() w5 = MyWidget5()
self.assertEqual(str(w5.media), """<link href="/some/path" type="text/css" media="all" rel="stylesheet" /> self.assertEqual(str(w5.media), """<link href="/some/path" type="text/css" media="all" rel="stylesheet">
<link href="/other/path" type="text/css" media="all" rel="stylesheet" /> <link href="/other/path" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/some/js"></script> <script type="text/javascript" src="/some/js"></script>
<script type="text/javascript" src="/other/js"></script>""") <script type="text/javascript" src="/other/js"></script>""")
@ -198,9 +198,9 @@ class FormsMediaTestCase(SimpleTestCase):
w6 = MyWidget6() w6 = MyWidget6()
self.assertEqual( self.assertEqual(
str(w6.media), str(w6.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<link href="/other/path" type="text/css" media="all" rel="stylesheet" /> <link href="/other/path" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script> <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
@ -226,8 +226,8 @@ class FormsMediaTestCase(SimpleTestCase):
w7 = MyWidget7() w7 = MyWidget7()
self.assertEqual( self.assertEqual(
str(w7.media), str(w7.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script> <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""" <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
@ -244,9 +244,9 @@ class FormsMediaTestCase(SimpleTestCase):
w8 = MyWidget8() w8 = MyWidget8()
self.assertEqual( self.assertEqual(
str(w8.media), str(w8.media),
"""<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" /> """<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet">
<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script> <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
@ -278,8 +278,8 @@ class FormsMediaTestCase(SimpleTestCase):
w9 = MyWidget9() w9 = MyWidget9()
self.assertEqual( self.assertEqual(
str(w9.media), str(w9.media),
"""<link href="/some/path" type="text/css" media="all" rel="stylesheet" /> """<link href="/some/path" type="text/css" media="all" rel="stylesheet">
<link href="/other/path" type="text/css" media="all" rel="stylesheet" /> <link href="/other/path" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/some/js"></script> <script type="text/javascript" src="/some/js"></script>
<script type="text/javascript" src="/other/js"></script>""" <script type="text/javascript" src="/other/js"></script>"""
) )
@ -294,8 +294,8 @@ class FormsMediaTestCase(SimpleTestCase):
js = ('/path/to/js1', '/path/to/js4') js = ('/path/to/js1', '/path/to/js4')
w10 = MyWidget10() w10 = MyWidget10()
self.assertEqual(str(w10.media), """<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" /> self.assertEqual(str(w10.media), """<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet">
<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="/path/to/js4"></script>""") <script type="text/javascript" src="/path/to/js4"></script>""")
@ -319,9 +319,9 @@ class FormsMediaTestCase(SimpleTestCase):
w11 = MyWidget11() w11 = MyWidget11()
self.assertEqual( self.assertEqual(
str(w11.media), str(w11.media),
"""<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" /> """<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet">
<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script> <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
@ -348,9 +348,9 @@ class FormsMediaTestCase(SimpleTestCase):
w12 = MyWidget12() w12 = MyWidget12()
self.assertEqual( self.assertEqual(
str(w12.media), str(w12.media),
"""<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" /> """<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet">
<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="/path/to/js4"></script>""" <script type="text/javascript" src="/path/to/js4"></script>"""
) )
@ -373,10 +373,10 @@ class FormsMediaTestCase(SimpleTestCase):
multimedia = MultimediaWidget() multimedia = MultimediaWidget()
self.assertEqual( self.assertEqual(
str(multimedia.media), str(multimedia.media),
"""<link href="/file4" type="text/css" media="print" rel="stylesheet" /> """<link href="/file4" type="text/css" media="print" rel="stylesheet">
<link href="/file3" type="text/css" media="screen" rel="stylesheet" /> <link href="/file3" type="text/css" media="screen" rel="stylesheet">
<link href="/file1" type="text/css" media="screen, print" rel="stylesheet" /> <link href="/file1" type="text/css" media="screen, print" rel="stylesheet">
<link href="/file2" type="text/css" media="screen, print" rel="stylesheet" /> <link href="/file2" type="text/css" media="screen, print" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="/path/to/js4"></script>""" <script type="text/javascript" src="/path/to/js4"></script>"""
) )
@ -417,9 +417,9 @@ class FormsMediaTestCase(SimpleTestCase):
mymulti = MyMultiWidget() mymulti = MyMultiWidget()
self.assertEqual( self.assertEqual(
str(mymulti.media), str(mymulti.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script> <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
@ -459,9 +459,9 @@ class FormsMediaTestCase(SimpleTestCase):
f1 = MyForm() f1 = MyForm()
self.assertEqual( self.assertEqual(
str(f1.media), str(f1.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script> <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
@ -474,9 +474,9 @@ class FormsMediaTestCase(SimpleTestCase):
f2 = AnotherForm() f2 = AnotherForm()
self.assertEqual( self.assertEqual(
str(f1.media + f2.media), str(f1.media + f2.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script> <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
@ -496,10 +496,10 @@ class FormsMediaTestCase(SimpleTestCase):
f3 = FormWithMedia() f3 = FormWithMedia()
self.assertEqual( self.assertEqual(
str(f3.media), str(f3.media),
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet">
<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" /> <link href="/some/form/css" type="text/css" media="all" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script> <script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script> <script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
@ -515,10 +515,10 @@ class FormsMediaTestCase(SimpleTestCase):
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
<script type="text/javascript" src="/path/to/js4"></script> <script type="text/javascript" src="/path/to/js4"></script>
<script type="text/javascript" src="/some/form/javascript"></script>""" <script type="text/javascript" src="/some/form/javascript"></script>"""
"""<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" /> """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet">
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" /> <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet">
<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />""" <link href="/some/form/css" type="text/css" media="all" rel="stylesheet">"""
) )
def test_html_safe(self): def test_html_safe(self):

View File

@ -109,24 +109,24 @@ class ModelFormCallableModelDefault(TestCase):
<option value="1" selected>ChoiceOption 1</option> <option value="1" selected>ChoiceOption 1</option>
<option value="2">ChoiceOption 2</option> <option value="2">ChoiceOption 2</option>
<option value="3">ChoiceOption 3</option> <option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-choice" value="1" id="initial-id_choice" /></p> </select><input type="hidden" name="initial-choice" value="1" id="initial-id_choice"></p>
<p><label for="id_choice_int">Choice int:</label> <select name="choice_int" id="id_choice_int"> <p><label for="id_choice_int">Choice int:</label> <select name="choice_int" id="id_choice_int">
<option value="1" selected>ChoiceOption 1</option> <option value="1" selected>ChoiceOption 1</option>
<option value="2">ChoiceOption 2</option> <option value="2">ChoiceOption 2</option>
<option value="3">ChoiceOption 3</option> <option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-choice_int" value="1" id="initial-id_choice_int" /></p> </select><input type="hidden" name="initial-choice_int" value="1" id="initial-id_choice_int"></p>
<p><label for="id_multi_choice">Multi choice:</label> <p><label for="id_multi_choice">Multi choice:</label>
<select multiple name="multi_choice" id="id_multi_choice" required> <select multiple name="multi_choice" id="id_multi_choice" required>
<option value="1" selected>ChoiceOption 1</option> <option value="1" selected>ChoiceOption 1</option>
<option value="2">ChoiceOption 2</option> <option value="2">ChoiceOption 2</option>
<option value="3">ChoiceOption 3</option> <option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-multi_choice" value="1" id="initial-id_multi_choice_0" /></p> </select><input type="hidden" name="initial-multi_choice" value="1" id="initial-id_multi_choice_0"></p>
<p><label for="id_multi_choice_int">Multi choice int:</label> <p><label for="id_multi_choice_int">Multi choice int:</label>
<select multiple name="multi_choice_int" id="id_multi_choice_int" required> <select multiple name="multi_choice_int" id="id_multi_choice_int" required>
<option value="1" selected>ChoiceOption 1</option> <option value="1" selected>ChoiceOption 1</option>
<option value="2">ChoiceOption 2</option> <option value="2">ChoiceOption 2</option>
<option value="3">ChoiceOption 3</option> <option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-multi_choice_int" value="1" id="initial-id_multi_choice_int_0" /></p>""" </select><input type="hidden" name="initial-multi_choice_int" value="1" id="initial-id_multi_choice_int_0"></p>"""
) )
def test_initial_instance_value(self): def test_initial_instance_value(self):
@ -145,26 +145,26 @@ class ModelFormCallableModelDefault(TestCase):
<option value="1">ChoiceOption 1</option> <option value="1">ChoiceOption 1</option>
<option value="2" selected>ChoiceOption 2</option> <option value="2" selected>ChoiceOption 2</option>
<option value="3">ChoiceOption 3</option> <option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-choice" value="2" id="initial-id_choice" /></p> </select><input type="hidden" name="initial-choice" value="2" id="initial-id_choice"></p>
<p><label for="id_choice_int">Choice int:</label> <select name="choice_int" id="id_choice_int"> <p><label for="id_choice_int">Choice int:</label> <select name="choice_int" id="id_choice_int">
<option value="1">ChoiceOption 1</option> <option value="1">ChoiceOption 1</option>
<option value="2" selected>ChoiceOption 2</option> <option value="2" selected>ChoiceOption 2</option>
<option value="3">ChoiceOption 3</option> <option value="3">ChoiceOption 3</option>
</select><input type="hidden" name="initial-choice_int" value="2" id="initial-id_choice_int" /></p> </select><input type="hidden" name="initial-choice_int" value="2" id="initial-id_choice_int"></p>
<p><label for="id_multi_choice">Multi choice:</label> <p><label for="id_multi_choice">Multi choice:</label>
<select multiple name="multi_choice" id="id_multi_choice" required> <select multiple name="multi_choice" id="id_multi_choice" required>
<option value="1">ChoiceOption 1</option> <option value="1">ChoiceOption 1</option>
<option value="2" selected>ChoiceOption 2</option> <option value="2" selected>ChoiceOption 2</option>
<option value="3" selected>ChoiceOption 3</option> <option value="3" selected>ChoiceOption 3</option>
</select><input type="hidden" name="initial-multi_choice" value="2" id="initial-id_multi_choice_0" /> </select><input type="hidden" name="initial-multi_choice" value="2" id="initial-id_multi_choice_0">
<input type="hidden" name="initial-multi_choice" value="3" id="initial-id_multi_choice_1" /></p> <input type="hidden" name="initial-multi_choice" value="3" id="initial-id_multi_choice_1"></p>
<p><label for="id_multi_choice_int">Multi choice int:</label> <p><label for="id_multi_choice_int">Multi choice int:</label>
<select multiple name="multi_choice_int" id="id_multi_choice_int" required> <select multiple name="multi_choice_int" id="id_multi_choice_int" required>
<option value="1">ChoiceOption 1</option> <option value="1">ChoiceOption 1</option>
<option value="2" selected>ChoiceOption 2</option> <option value="2" selected>ChoiceOption 2</option>
<option value="3" selected>ChoiceOption 3</option> <option value="3" selected>ChoiceOption 3</option>
</select><input type="hidden" name="initial-multi_choice_int" value="2" id="initial-id_multi_choice_int_0" /> </select><input type="hidden" name="initial-multi_choice_int" value="2" id="initial-id_multi_choice_int_0">
<input type="hidden" name="initial-multi_choice_int" value="3" id="initial-id_multi_choice_int_1" /></p>""" <input type="hidden" name="initial-multi_choice_int" value="3" id="initial-id_multi_choice_int_1"></p>"""
) )
@ -308,7 +308,7 @@ class EmptyLabelTestCase(TestCase):
f = EmptyCharLabelChoiceForm() f = EmptyCharLabelChoiceForm()
self.assertHTMLEqual( self.assertHTMLEqual(
f.as_p(), f.as_p(),
"""<p><label for="id_name">Name:</label> <input id="id_name" maxlength="10" name="name" type="text" required /></p> """<p><label for="id_name">Name:</label> <input id="id_name" maxlength="10" name="name" type="text" required></p>
<p><label for="id_choice">Choice:</label> <select id="id_choice" name="choice"> <p><label for="id_choice">Choice:</label> <select id="id_choice" name="choice">
<option value="" selected>No Preference</option> <option value="" selected>No Preference</option>
<option value="f">Foo</option> <option value="f">Foo</option>
@ -320,7 +320,7 @@ class EmptyLabelTestCase(TestCase):
f = EmptyCharLabelNoneChoiceForm() f = EmptyCharLabelNoneChoiceForm()
self.assertHTMLEqual( self.assertHTMLEqual(
f.as_p(), f.as_p(),
"""<p><label for="id_name">Name:</label> <input id="id_name" maxlength="10" name="name" type="text" required /></p> """<p><label for="id_name">Name:</label> <input id="id_name" maxlength="10" name="name" type="text" required></p>
<p><label for="id_choice_string_w_none">Choice string w none:</label> <p><label for="id_choice_string_w_none">Choice string w none:</label>
<select id="id_choice_string_w_none" name="choice_string_w_none"> <select id="id_choice_string_w_none" name="choice_string_w_none">
<option value="" selected>No Preference</option> <option value="" selected>No Preference</option>
@ -350,7 +350,7 @@ class EmptyLabelTestCase(TestCase):
f = EmptyIntegerLabelChoiceForm() f = EmptyIntegerLabelChoiceForm()
self.assertHTMLEqual( self.assertHTMLEqual(
f.as_p(), f.as_p(),
"""<p><label for="id_name">Name:</label> <input id="id_name" maxlength="10" name="name" type="text" required /></p> """<p><label for="id_name">Name:</label> <input id="id_name" maxlength="10" name="name" type="text" required></p>
<p><label for="id_choice_integer">Choice integer:</label> <p><label for="id_choice_integer">Choice integer:</label>
<select id="id_choice_integer" name="choice_integer"> <select id="id_choice_integer" name="choice_integer">
<option value="" selected>No Preference</option> <option value="" selected>No Preference</option>
@ -370,7 +370,7 @@ class EmptyLabelTestCase(TestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
f.as_p(), f.as_p(),
"""<p><label for="id_name">Name:</label> """<p><label for="id_name">Name:</label>
<input id="id_name" maxlength="10" name="name" type="text" value="none-test" required /></p> <input id="id_name" maxlength="10" name="name" type="text" value="none-test" required></p>
<p><label for="id_choice_integer">Choice integer:</label> <p><label for="id_choice_integer">Choice integer:</label>
<select id="id_choice_integer" name="choice_integer"> <select id="id_choice_integer" name="choice_integer">
<option value="" selected>No Preference</option> <option value="" selected>No Preference</option>
@ -384,7 +384,7 @@ class EmptyLabelTestCase(TestCase):
self.assertHTMLEqual( self.assertHTMLEqual(
f.as_p(), f.as_p(),
"""<p><label for="id_name">Name:</label> """<p><label for="id_name">Name:</label>
<input id="id_name" maxlength="10" name="name" type="text" value="foo-test" required /></p> <input id="id_name" maxlength="10" name="name" type="text" value="foo-test" required></p>
<p><label for="id_choice_integer">Choice integer:</label> <p><label for="id_choice_integer">Choice integer:</label>
<select id="id_choice_integer" name="choice_integer"> <select id="id_choice_integer" name="choice_integer">
<option value="">No Preference</option> <option value="">No Preference</option>

View File

@ -7,18 +7,18 @@ class CheckboxInputTest(WidgetTest):
widget = CheckboxInput() widget = CheckboxInput()
def test_render_empty(self): def test_render_empty(self):
self.check_html(self.widget, 'is_cool', '', html='<input type="checkbox" name="is_cool" />') self.check_html(self.widget, 'is_cool', '', html='<input type="checkbox" name="is_cool">')
def test_render_none(self): def test_render_none(self):
self.check_html(self.widget, 'is_cool', None, html='<input type="checkbox" name="is_cool" />') self.check_html(self.widget, 'is_cool', None, html='<input type="checkbox" name="is_cool">')
def test_render_false(self): def test_render_false(self):
self.check_html(self.widget, 'is_cool', False, html='<input type="checkbox" name="is_cool" />') self.check_html(self.widget, 'is_cool', False, html='<input type="checkbox" name="is_cool">')
def test_render_true(self): def test_render_true(self):
self.check_html( self.check_html(
self.widget, 'is_cool', True, self.widget, 'is_cool', True,
html='<input checked type="checkbox" name="is_cool" />' html='<input checked type="checkbox" name="is_cool">'
) )
def test_render_value(self): def test_render_value(self):
@ -28,7 +28,7 @@ class CheckboxInputTest(WidgetTest):
""" """
self.check_html( self.check_html(
self.widget, 'is_cool', 'foo', self.widget, 'is_cool', 'foo',
html='<input checked type="checkbox" name="is_cool" value="foo" />', html='<input checked type="checkbox" name="is_cool" value="foo">',
) )
def test_render_int(self): def test_render_int(self):
@ -37,11 +37,11 @@ class CheckboxInputTest(WidgetTest):
""" """
self.check_html( self.check_html(
self.widget, 'is_cool', 0, self.widget, 'is_cool', 0,
html='<input checked type="checkbox" name="is_cool" value="0" />', html='<input checked type="checkbox" name="is_cool" value="0">',
) )
self.check_html( self.check_html(
self.widget, 'is_cool', 1, self.widget, 'is_cool', 1,
html='<input checked type="checkbox" name="is_cool" value="1" />', html='<input checked type="checkbox" name="is_cool" value="1">',
) )
def test_render_check_test(self): def test_render_check_test(self):
@ -51,16 +51,16 @@ class CheckboxInputTest(WidgetTest):
""" """
widget = CheckboxInput(check_test=lambda value: value.startswith('hello')) widget = CheckboxInput(check_test=lambda value: value.startswith('hello'))
self.check_html(widget, 'greeting', '', html=( self.check_html(widget, 'greeting', '', html=(
'<input type="checkbox" name="greeting" />' '<input type="checkbox" name="greeting">'
)) ))
self.check_html(widget, 'greeting', 'hello', html=( self.check_html(widget, 'greeting', 'hello', html=(
'<input checked type="checkbox" name="greeting" value="hello" />' '<input checked type="checkbox" name="greeting" value="hello">'
)) ))
self.check_html(widget, 'greeting', 'hello there', html=( self.check_html(widget, 'greeting', 'hello there', html=(
'<input checked type="checkbox" name="greeting" value="hello there" />' '<input checked type="checkbox" name="greeting" value="hello there">'
)) ))
self.check_html(widget, 'greeting', 'hello & goodbye', html=( self.check_html(widget, 'greeting', 'hello & goodbye', html=(
'<input checked type="checkbox" name="greeting" value="hello &amp; goodbye" />' '<input checked type="checkbox" name="greeting" value="hello &amp; goodbye">'
)) ))
def test_render_check_exception(self): def test_render_check_exception(self):

View File

@ -13,20 +13,20 @@ class CheckboxSelectMultipleTest(WidgetTest):
def test_render_value(self): def test_render_value(self):
self.check_html(self.widget(choices=self.beatles), 'beatles', ['J'], html=( self.check_html(self.widget(choices=self.beatles), 'beatles', ['J'], html=(
"""<ul> """<ul>
<li><label><input checked type="checkbox" name="beatles" value="J" /> John</label></li> <li><label><input checked type="checkbox" name="beatles" value="J"> John</label></li>
<li><label><input type="checkbox" name="beatles" value="P" /> Paul</label></li> <li><label><input type="checkbox" name="beatles" value="P"> Paul</label></li>
<li><label><input type="checkbox" name="beatles" value="G" /> George</label></li> <li><label><input type="checkbox" name="beatles" value="G"> George</label></li>
<li><label><input type="checkbox" name="beatles" value="R" /> Ringo</label></li> <li><label><input type="checkbox" name="beatles" value="R"> Ringo</label></li>
</ul>""" </ul>"""
)) ))
def test_render_value_multiple(self): def test_render_value_multiple(self):
self.check_html(self.widget(choices=self.beatles), 'beatles', ['J', 'P'], html=( self.check_html(self.widget(choices=self.beatles), 'beatles', ['J', 'P'], html=(
"""<ul> """<ul>
<li><label><input checked type="checkbox" name="beatles" value="J" /> John</label></li> <li><label><input checked type="checkbox" name="beatles" value="J"> John</label></li>
<li><label><input checked type="checkbox" name="beatles" value="P" /> Paul</label></li> <li><label><input checked type="checkbox" name="beatles" value="P"> Paul</label></li>
<li><label><input type="checkbox" name="beatles" value="G" /> George</label></li> <li><label><input type="checkbox" name="beatles" value="G"> George</label></li>
<li><label><input type="checkbox" name="beatles" value="R" /> Ringo</label></li> <li><label><input type="checkbox" name="beatles" value="R"> Ringo</label></li>
</ul>""" </ul>"""
)) ))
@ -36,10 +36,10 @@ class CheckboxSelectMultipleTest(WidgetTest):
""" """
self.check_html(self.widget(choices=self.beatles), 'beatles', None, html=( self.check_html(self.widget(choices=self.beatles), 'beatles', None, html=(
"""<ul> """<ul>
<li><label><input type="checkbox" name="beatles" value="J" /> John</label></li> <li><label><input type="checkbox" name="beatles" value="J"> John</label></li>
<li><label><input type="checkbox" name="beatles" value="P" /> Paul</label></li> <li><label><input type="checkbox" name="beatles" value="P"> Paul</label></li>
<li><label><input type="checkbox" name="beatles" value="G" /> George</label></li> <li><label><input type="checkbox" name="beatles" value="G"> George</label></li>
<li><label><input type="checkbox" name="beatles" value="R" /> Ringo</label></li> <li><label><input type="checkbox" name="beatles" value="R"> Ringo</label></li>
</ul>""" </ul>"""
)) ))
@ -52,25 +52,25 @@ class CheckboxSelectMultipleTest(WidgetTest):
html = """ html = """
<ul id="media"> <ul id="media">
<li> <li>
<label for="media_0"><input id="media_0" name="nestchoice" type="checkbox" value="unknown" /> Unknown</label> <label for="media_0"><input id="media_0" name="nestchoice" type="checkbox" value="unknown"> Unknown</label>
</li> </li>
<li>Audio<ul id="media_1"> <li>Audio<ul id="media_1">
<li> <li>
<label for="media_1_0"> <label for="media_1_0">
<input checked id="media_1_0" name="nestchoice" type="checkbox" value="vinyl" /> Vinyl <input checked id="media_1_0" name="nestchoice" type="checkbox" value="vinyl"> Vinyl
</label> </label>
</li> </li>
<li> <li>
<label for="media_1_1"><input id="media_1_1" name="nestchoice" type="checkbox" value="cd" /> CD</label> <label for="media_1_1"><input id="media_1_1" name="nestchoice" type="checkbox" value="cd"> CD</label>
</li> </li>
</ul></li> </ul></li>
<li>Video<ul id="media_2"> <li>Video<ul id="media_2">
<li> <li>
<label for="media_2_0"><input id="media_2_0" name="nestchoice" type="checkbox" value="vhs" /> VHS</label> <label for="media_2_0"><input id="media_2_0" name="nestchoice" type="checkbox" value="vhs"> VHS</label>
</li> </li>
<li> <li>
<label for="media_2_1"> <label for="media_2_1">
<input checked id="media_2_1" name="nestchoice" type="checkbox" value="dvd" /> DVD <input checked id="media_2_1" name="nestchoice" type="checkbox" value="dvd"> DVD
</label> </label>
</li> </li>
</ul></li> </ul></li>
@ -90,25 +90,25 @@ class CheckboxSelectMultipleTest(WidgetTest):
html = """ html = """
<ul> <ul>
<li> <li>
<label><input name="nestchoice" type="checkbox" value="unknown" /> Unknown</label> <label><input name="nestchoice" type="checkbox" value="unknown"> Unknown</label>
</li> </li>
<li>Audio<ul> <li>Audio<ul>
<li> <li>
<label> <label>
<input checked name="nestchoice" type="checkbox" value="vinyl" /> Vinyl <input checked name="nestchoice" type="checkbox" value="vinyl"> Vinyl
</label> </label>
</li> </li>
<li> <li>
<label><input name="nestchoice" type="checkbox" value="cd" /> CD</label> <label><input name="nestchoice" type="checkbox" value="cd"> CD</label>
</li> </li>
</ul></li> </ul></li>
<li>Video<ul> <li>Video<ul>
<li> <li>
<label><input name="nestchoice" type="checkbox" value="vhs" /> VHS</label> <label><input name="nestchoice" type="checkbox" value="vhs"> VHS</label>
</li> </li>
<li> <li>
<label> <label>
<input checked name="nestchoice" type="checkbox" value="dvd" /> DVD <input checked name="nestchoice" type="checkbox" value="dvd"> DVD
</label> </label>
</li> </li>
</ul></li> </ul></li>
@ -124,11 +124,11 @@ class CheckboxSelectMultipleTest(WidgetTest):
html = """ html = """
<ul id="abc"> <ul id="abc">
<li> <li>
<label for="abc_0"><input checked type="checkbox" name="letters" value="a" id="abc_0" /> A</label> <label for="abc_0"><input checked type="checkbox" name="letters" value="a" id="abc_0"> A</label>
</li> </li>
<li><label for="abc_1"><input type="checkbox" name="letters" value="b" id="abc_1" /> B</label></li> <li><label for="abc_1"><input type="checkbox" name="letters" value="b" id="abc_1"> B</label></li>
<li> <li>
<label for="abc_2"><input checked type="checkbox" name="letters" value="c" id="abc_2" /> C</label> <label for="abc_2"><input checked type="checkbox" name="letters" value="c" id="abc_2"> C</label>
</li> </li>
</ul> </ul>
""" """
@ -142,11 +142,11 @@ class CheckboxSelectMultipleTest(WidgetTest):
html = """ html = """
<ul id="abc"> <ul id="abc">
<li> <li>
<label for="abc_0"><input checked type="checkbox" name="letters" value="a" id="abc_0" /> A</label> <label for="abc_0"><input checked type="checkbox" name="letters" value="a" id="abc_0"> A</label>
</li> </li>
<li><label for="abc_1"><input type="checkbox" name="letters" value="b" id="abc_1" /> B</label></li> <li><label for="abc_1"><input type="checkbox" name="letters" value="b" id="abc_1"> B</label></li>
<li> <li>
<label for="abc_2"><input checked type="checkbox" name="letters" value="c" id="abc_2" /> C</label> <label for="abc_2"><input checked type="checkbox" name="letters" value="c" id="abc_2"> C</label>
</li> </li>
</ul> </ul>
""" """
@ -161,9 +161,9 @@ class CheckboxSelectMultipleTest(WidgetTest):
] ]
html = """ html = """
<ul> <ul>
<li><label><input type="checkbox" name="numbers" value="1" /> One</label></li> <li><label><input type="checkbox" name="numbers" value="1"> One</label></li>
<li><label><input type="checkbox" name="numbers" value="1000" /> One thousand</label></li> <li><label><input type="checkbox" name="numbers" value="1000"> One thousand</label></li>
<li><label><input type="checkbox" name="numbers" value="1000000" /> One million</label></li> <li><label><input type="checkbox" name="numbers" value="1000000"> One million</label></li>
</ul> </ul>
""" """
self.check_html(self.widget(choices=choices), 'numbers', None, html=html) self.check_html(self.widget(choices=choices), 'numbers', None, html=html)
@ -174,8 +174,8 @@ class CheckboxSelectMultipleTest(WidgetTest):
] ]
html = """ html = """
<ul> <ul>
<li><label><input type="checkbox" name="times" value="00:00:00" /> midnight</label></li> <li><label><input type="checkbox" name="times" value="00:00:00"> midnight</label></li>
<li><label><input type="checkbox" name="times" value="12:00:00" /> noon</label></li> <li><label><input type="checkbox" name="times" value="12:00:00"> noon</label></li>
</ul> </ul>
""" """
self.check_html(self.widget(choices=choices), 'times', None, html=html) self.check_html(self.widget(choices=choices), 'times', None, html=html)

View File

@ -26,9 +26,9 @@ class ClearableFileInputTest(WidgetTest):
self.check_html(self.widget, 'myfile', FakeFieldFile(), html=( self.check_html(self.widget, 'myfile', FakeFieldFile(), html=(
""" """
Currently: <a href="something">something</a> Currently: <a href="something">something</a>
<input type="checkbox" name="myfile-clear" id="myfile-clear_id" /> <input type="checkbox" name="myfile-clear" id="myfile-clear_id">
<label for="myfile-clear_id">Clear</label><br /> <label for="myfile-clear_id">Clear</label><br>
Change: <input type="file" name="myfile" /> Change: <input type="file" name="myfile">
""" """
)) ))
@ -47,9 +47,9 @@ class ClearableFileInputTest(WidgetTest):
""" """
Currently: <a href="something?chapter=1&amp;sect=2&amp;copy=3&amp;lang=en"> Currently: <a href="something?chapter=1&amp;sect=2&amp;copy=3&amp;lang=en">
something&lt;div onclick=&quot;alert(&#39;oops&#39;)&quot;&gt;.jpg</a> something&lt;div onclick=&quot;alert(&#39;oops&#39;)&quot;&gt;.jpg</a>
<input type="checkbox" name="my&lt;div&gt;file-clear" id="my&lt;div&gt;file-clear_id" /> <input type="checkbox" name="my&lt;div&gt;file-clear" id="my&lt;div&gt;file-clear_id">
<label for="my&lt;div&gt;file-clear_id">Clear</label><br /> <label for="my&lt;div&gt;file-clear_id">Clear</label><br>
Change: <input type="file" name="my&lt;div&gt;file" /> Change: <input type="file" name="my&lt;div&gt;file">
""" """
)) ))
@ -62,8 +62,8 @@ class ClearableFileInputTest(WidgetTest):
widget.is_required = True widget.is_required = True
self.check_html(widget, 'myfile', FakeFieldFile(), html=( self.check_html(widget, 'myfile', FakeFieldFile(), html=(
""" """
Currently: <a href="something">something</a> <br /> Currently: <a href="something">something</a> <br>
Change: <input type="file" name="myfile" /> Change: <input type="file" name="myfile">
""" """
)) ))
@ -72,7 +72,7 @@ class ClearableFileInputTest(WidgetTest):
A ClearableFileInput instantiated with no initial value does not render A ClearableFileInput instantiated with no initial value does not render
a clear checkbox. a clear checkbox.
""" """
self.check_html(self.widget, 'myfile', None, html='<input type="file" name="myfile" />') self.check_html(self.widget, 'myfile', None, html='<input type="file" name="myfile">')
def test_render_as_subwidget(self): def test_render_as_subwidget(self):
"""A ClearableFileInput as a subwidget of MultiWidget.""" """A ClearableFileInput as a subwidget of MultiWidget."""
@ -80,9 +80,9 @@ class ClearableFileInputTest(WidgetTest):
self.check_html(widget, 'myfile', [FakeFieldFile()], html=( self.check_html(widget, 'myfile', [FakeFieldFile()], html=(
""" """
Currently: <a href="something">something</a> Currently: <a href="something">something</a>
<input type="checkbox" name="myfile_0-clear" id="myfile_0-clear_id" /> <input type="checkbox" name="myfile_0-clear" id="myfile_0-clear_id">
<label for="myfile_0-clear_id">Clear</label><br /> <label for="myfile_0-clear_id">Clear</label><br>
Change: <input type="file" name="myfile_0" /> Change: <input type="file" name="myfile_0">
""" """
)) ))
@ -148,7 +148,7 @@ class ClearableFileInputTest(WidgetTest):
return 'value' return 'value'
html = self.widget.render('myfile', NoURLFieldFile()) html = self.widget.render('myfile', NoURLFieldFile())
self.assertHTMLEqual(html, '<input name="myfile" type="file" />') self.assertHTMLEqual(html, '<input name="myfile" type="file">')
def test_use_required_attribute(self): def test_use_required_attribute(self):
# False when initial data exists. The file input is left blank by the # False when initial data exists. The file input is left blank by the

View File

@ -11,15 +11,15 @@ class DateInputTest(WidgetTest):
widget = DateInput() widget = DateInput()
def test_render_none(self): def test_render_none(self):
self.check_html(self.widget, 'date', None, html='<input type="text" name="date" />') self.check_html(self.widget, 'date', None, html='<input type="text" name="date">')
def test_render_value(self): def test_render_value(self):
d = date(2007, 9, 17) d = date(2007, 9, 17)
self.assertEqual(str(d), '2007-09-17') self.assertEqual(str(d), '2007-09-17')
self.check_html(self.widget, 'date', d, html='<input type="text" name="date" value="2007-09-17" />') self.check_html(self.widget, 'date', d, html='<input type="text" name="date" value="2007-09-17">')
self.check_html(self.widget, 'date', date(2007, 9, 17), html=( self.check_html(self.widget, 'date', date(2007, 9, 17), html=(
'<input type="text" name="date" value="2007-09-17" />' '<input type="text" name="date" value="2007-09-17">'
)) ))
def test_string(self): def test_string(self):
@ -27,7 +27,7 @@ class DateInputTest(WidgetTest):
Should be able to initialize from a string value. Should be able to initialize from a string value.
""" """
self.check_html(self.widget, 'date', '2007-09-17', html=( self.check_html(self.widget, 'date', '2007-09-17', html=(
'<input type="text" name="date" value="2007-09-17" />' '<input type="text" name="date" value="2007-09-17">'
)) ))
def test_format(self): def test_format(self):
@ -36,12 +36,12 @@ class DateInputTest(WidgetTest):
""" """
d = date(2007, 9, 17) d = date(2007, 9, 17)
widget = DateInput(format='%d/%m/%Y', attrs={'type': 'date'}) widget = DateInput(format='%d/%m/%Y', attrs={'type': 'date'})
self.check_html(widget, 'date', d, html='<input type="date" name="date" value="17/09/2007" />') self.check_html(widget, 'date', d, html='<input type="date" name="date" value="17/09/2007">')
@override_settings(USE_L10N=True) @override_settings(USE_L10N=True)
@translation.override('de-at') @translation.override('de-at')
def test_l10n(self): def test_l10n(self):
self.check_html( self.check_html(
self.widget, 'date', date(2007, 9, 17), self.widget, 'date', date(2007, 9, 17),
html='<input type="text" name="date" value="17.09.2007" />', html='<input type="text" name="date" value="17.09.2007">',
) )

View File

@ -11,7 +11,7 @@ class DateTimeInputTest(WidgetTest):
widget = DateTimeInput() widget = DateTimeInput()
def test_render_none(self): def test_render_none(self):
self.check_html(self.widget, 'date', None, '<input type="text" name="date" />') self.check_html(self.widget, 'date', None, '<input type="text" name="date">')
def test_render_value(self): def test_render_value(self):
""" """
@ -20,13 +20,13 @@ class DateTimeInputTest(WidgetTest):
d = datetime(2007, 9, 17, 12, 51, 34, 482548) d = datetime(2007, 9, 17, 12, 51, 34, 482548)
self.assertEqual(str(d), '2007-09-17 12:51:34.482548') self.assertEqual(str(d), '2007-09-17 12:51:34.482548')
self.check_html(self.widget, 'date', d, html=( self.check_html(self.widget, 'date', d, html=(
'<input type="text" name="date" value="2007-09-17 12:51:34" />' '<input type="text" name="date" value="2007-09-17 12:51:34">'
)) ))
self.check_html(self.widget, 'date', datetime(2007, 9, 17, 12, 51, 34), html=( self.check_html(self.widget, 'date', datetime(2007, 9, 17, 12, 51, 34), html=(
'<input type="text" name="date" value="2007-09-17 12:51:34" />' '<input type="text" name="date" value="2007-09-17 12:51:34">'
)) ))
self.check_html(self.widget, 'date', datetime(2007, 9, 17, 12, 51), html=( self.check_html(self.widget, 'date', datetime(2007, 9, 17, 12, 51), html=(
'<input type="text" name="date" value="2007-09-17 12:51:00" />' '<input type="text" name="date" value="2007-09-17 12:51:00">'
)) ))
def test_render_formatted(self): def test_render_formatted(self):
@ -37,14 +37,14 @@ class DateTimeInputTest(WidgetTest):
format='%d/%m/%Y %H:%M', attrs={'type': 'datetime'}, format='%d/%m/%Y %H:%M', attrs={'type': 'datetime'},
) )
d = datetime(2007, 9, 17, 12, 51, 34, 482548) d = datetime(2007, 9, 17, 12, 51, 34, 482548)
self.check_html(widget, 'date', d, html='<input type="datetime" name="date" value="17/09/2007 12:51" />') self.check_html(widget, 'date', d, html='<input type="datetime" name="date" value="17/09/2007 12:51">')
@override_settings(USE_L10N=True) @override_settings(USE_L10N=True)
@translation.override('de-at') @translation.override('de-at')
def test_l10n(self): def test_l10n(self):
d = datetime(2007, 9, 17, 12, 51, 34, 482548) d = datetime(2007, 9, 17, 12, 51, 34, 482548)
self.check_html(self.widget, 'date', d, html=( self.check_html(self.widget, 'date', d, html=(
'<input type="text" name="date" value="17.09.2007 12:51:34" />' '<input type="text" name="date" value="17.09.2007 12:51:34">'
)) ))
@override_settings(USE_L10N=True) @override_settings(USE_L10N=True)
@ -54,10 +54,10 @@ class DateTimeInputTest(WidgetTest):
with self.settings(USE_L10N=False): with self.settings(USE_L10N=False):
self.check_html( self.check_html(
self.widget, 'date', d, self.widget, 'date', d,
html='<input type="text" name="date" value="2007-09-17 12:51:34" />', html='<input type="text" name="date" value="2007-09-17 12:51:34">',
) )
with translation.override('es'): with translation.override('es'):
self.check_html( self.check_html(
self.widget, 'date', d, self.widget, 'date', d,
html='<input type="text" name="date" value="17/09/2007 12:51:34" />', html='<input type="text" name="date" value="17/09/2007 12:51:34">',
) )

View File

@ -11,9 +11,9 @@ class FileInputTest(WidgetTest):
FileInput widgets never render the value attribute. The old value FileInput widgets never render the value attribute. The old value
isn't useful if a form is updated or an error occurred. isn't useful if a form is updated or an error occurred.
""" """
self.check_html(self.widget, 'email', 'test@example.com', html='<input type="file" name="email" />') self.check_html(self.widget, 'email', 'test@example.com', html='<input type="file" name="email">')
self.check_html(self.widget, 'email', '', html='<input type="file" name="email" />') self.check_html(self.widget, 'email', '', html='<input type="file" name="email">')
self.check_html(self.widget, 'email', None, html='<input type="file" name="email" />') self.check_html(self.widget, 'email', None, html='<input type="file" name="email">')
def test_value_omitted_from_data(self): def test_value_omitted_from_data(self):
self.assertIs(self.widget.value_omitted_from_data({}, {}, 'field'), True) self.assertIs(self.widget.value_omitted_from_data({}, {}, 'field'), True)

View File

@ -7,7 +7,7 @@ class HiddenInputTest(WidgetTest):
widget = HiddenInput() widget = HiddenInput()
def test_render(self): def test_render(self):
self.check_html(self.widget, 'email', '', html='<input type="hidden" name="email" />') self.check_html(self.widget, 'email', '', html='<input type="hidden" name="email">')
def test_use_required_attribute(self): def test_use_required_attribute(self):
# Always False to avoid browser validation on inputs hidden from the # Always False to avoid browser validation on inputs hidden from the

View File

@ -8,8 +8,8 @@ class InputTests(WidgetTest):
def test_attrs_with_type(self): def test_attrs_with_type(self):
attrs = {'type': 'date'} attrs = {'type': 'date'}
widget = Input(attrs) widget = Input(attrs)
self.check_html(widget, 'name', 'value', '<input type="date" name="name" value="value" />') self.check_html(widget, 'name', 'value', '<input type="date" name="name" value="value">')
# reuse the same attrs for another widget # reuse the same attrs for another widget
self.check_html(Input(attrs), 'name', 'value', '<input type="date" name="name" value="value" />') self.check_html(Input(attrs), 'name', 'value', '<input type="date" name="name" value="value">')
attrs['type'] = 'number' # shouldn't change the widget type attrs['type'] = 'number' # shouldn't change the widget type
self.check_html(widget, 'name', 'value', '<input type="date" name="name" value="value" />') self.check_html(widget, 'name', 'value', '<input type="date" name="name" value="value">')

View File

@ -9,30 +9,30 @@ class MultipleHiddenInputTest(WidgetTest):
def test_render_single(self): def test_render_single(self):
self.check_html( self.check_html(
self.widget, 'email', ['test@example.com'], self.widget, 'email', ['test@example.com'],
html='<input type="hidden" name="email" value="test@example.com" />', html='<input type="hidden" name="email" value="test@example.com">',
) )
def test_render_multiple(self): def test_render_multiple(self):
self.check_html( self.check_html(
self.widget, 'email', ['test@example.com', 'foo@example.com'], self.widget, 'email', ['test@example.com', 'foo@example.com'],
html=( html=(
'<input type="hidden" name="email" value="test@example.com" />\n' '<input type="hidden" name="email" value="test@example.com">\n'
'<input type="hidden" name="email" value="foo@example.com" />' '<input type="hidden" name="email" value="foo@example.com">'
), ),
) )
def test_render_attrs(self): def test_render_attrs(self):
self.check_html( self.check_html(
self.widget, 'email', ['test@example.com'], attrs={'class': 'fun'}, self.widget, 'email', ['test@example.com'], attrs={'class': 'fun'},
html='<input type="hidden" name="email" value="test@example.com" class="fun" />', html='<input type="hidden" name="email" value="test@example.com" class="fun">',
) )
def test_render_attrs_multiple(self): def test_render_attrs_multiple(self):
self.check_html( self.check_html(
self.widget, 'email', ['test@example.com', 'foo@example.com'], attrs={'class': 'fun'}, self.widget, 'email', ['test@example.com', 'foo@example.com'], attrs={'class': 'fun'},
html=( html=(
'<input type="hidden" name="email" value="test@example.com" class="fun" />\n' '<input type="hidden" name="email" value="test@example.com" class="fun">\n'
'<input type="hidden" name="email" value="foo@example.com" class="fun" />' '<input type="hidden" name="email" value="foo@example.com" class="fun">'
), ),
) )
@ -41,18 +41,18 @@ class MultipleHiddenInputTest(WidgetTest):
self.check_html(widget, 'email', [], '') self.check_html(widget, 'email', [], '')
self.check_html( self.check_html(
widget, 'email', ['foo@example.com'], widget, 'email', ['foo@example.com'],
html='<input type="hidden" class="fun" value="foo@example.com" name="email" />', html='<input type="hidden" class="fun" value="foo@example.com" name="email">',
) )
self.check_html( self.check_html(
widget, 'email', ['foo@example.com', 'test@example.com'], widget, 'email', ['foo@example.com', 'test@example.com'],
html=( html=(
'<input type="hidden" class="fun" value="foo@example.com" name="email" />\n' '<input type="hidden" class="fun" value="foo@example.com" name="email">\n'
'<input type="hidden" class="fun" value="test@example.com" name="email" />' '<input type="hidden" class="fun" value="test@example.com" name="email">'
), ),
) )
self.check_html( self.check_html(
widget, 'email', ['foo@example.com'], attrs={'class': 'special'}, widget, 'email', ['foo@example.com'], attrs={'class': 'special'},
html='<input type="hidden" class="special" value="foo@example.com" name="email" />', html='<input type="hidden" class="special" value="foo@example.com" name="email">',
) )
def test_render_empty(self): def test_render_empty(self):
@ -68,8 +68,8 @@ class MultipleHiddenInputTest(WidgetTest):
self.check_html( self.check_html(
self.widget, 'letters', ['a', 'b', 'c'], attrs={'id': 'hideme'}, self.widget, 'letters', ['a', 'b', 'c'], attrs={'id': 'hideme'},
html=( html=(
'<input type="hidden" name="letters" value="a" id="hideme_0" />\n' '<input type="hidden" name="letters" value="a" id="hideme_0">\n'
'<input type="hidden" name="letters" value="b" id="hideme_1" />\n' '<input type="hidden" name="letters" value="b" id="hideme_1">\n'
'<input type="hidden" name="letters" value="c" id="hideme_2" />' '<input type="hidden" name="letters" value="c" id="hideme_2">'
), ),
) )

View File

@ -88,16 +88,16 @@ class MultiWidgetTest(WidgetTest):
) )
) )
self.check_html(widget, 'name', ['john', 'lennon'], html=( self.check_html(widget, 'name', ['john', 'lennon'], html=(
'<input type="text" class="big" value="john" name="name_0" />' '<input type="text" class="big" value="john" name="name_0">'
'<input type="text" class="small" value="lennon" name="name_1" />' '<input type="text" class="small" value="lennon" name="name_1">'
)) ))
self.check_html(widget, 'name', 'john__lennon', html=( self.check_html(widget, 'name', 'john__lennon', html=(
'<input type="text" class="big" value="john" name="name_0" />' '<input type="text" class="big" value="john" name="name_0">'
'<input type="text" class="small" value="lennon" name="name_1" />' '<input type="text" class="small" value="lennon" name="name_1">'
)) ))
self.check_html(widget, 'name', 'john__lennon', attrs={'id': 'foo'}, html=( self.check_html(widget, 'name', 'john__lennon', attrs={'id': 'foo'}, html=(
'<input id="foo_0" type="text" class="big" value="john" name="name_0" />' '<input id="foo_0" type="text" class="big" value="john" name="name_0">'
'<input id="foo_1" type="text" class="small" value="lennon" name="name_1" />' '<input id="foo_1" type="text" class="small" value="lennon" name="name_1">'
)) ))
def test_constructor_attrs(self): def test_constructor_attrs(self):
@ -109,21 +109,21 @@ class MultiWidgetTest(WidgetTest):
attrs={'id': 'bar'}, attrs={'id': 'bar'},
) )
self.check_html(widget, 'name', ['john', 'lennon'], html=( self.check_html(widget, 'name', ['john', 'lennon'], html=(
'<input id="bar_0" type="text" class="big" value="john" name="name_0" />' '<input id="bar_0" type="text" class="big" value="john" name="name_0">'
'<input id="bar_1" type="text" class="small" value="lennon" name="name_1" />' '<input id="bar_1" type="text" class="small" value="lennon" name="name_1">'
)) ))
def test_constructor_attrs_with_type(self): def test_constructor_attrs_with_type(self):
attrs = {'type': 'number'} attrs = {'type': 'number'}
widget = MyMultiWidget(widgets=(TextInput, TextInput()), attrs=attrs) widget = MyMultiWidget(widgets=(TextInput, TextInput()), attrs=attrs)
self.check_html(widget, 'code', ['1', '2'], html=( self.check_html(widget, 'code', ['1', '2'], html=(
'<input type="number" value="1" name="code_0" />' '<input type="number" value="1" name="code_0">'
'<input type="number" value="2" name="code_1" />' '<input type="number" value="2" name="code_1">'
)) ))
widget = MyMultiWidget(widgets=(TextInput(attrs), TextInput(attrs)), attrs={'class': 'bar'}) widget = MyMultiWidget(widgets=(TextInput(attrs), TextInput(attrs)), attrs={'class': 'bar'})
self.check_html(widget, 'code', ['1', '2'], html=( self.check_html(widget, 'code', ['1', '2'], html=(
'<input type="number" value="1" name="code_0" class="bar" />' '<input type="number" value="1" name="code_0" class="bar">'
'<input type="number" value="2" name="code_1" class="bar" />' '<input type="number" value="2" name="code_1" class="bar">'
)) ))
def test_value_omitted_from_data(self): def test_value_omitted_from_data(self):
@ -154,23 +154,23 @@ class MultiWidgetTest(WidgetTest):
widget = ComplexMultiWidget() widget = ComplexMultiWidget()
self.check_html(widget, 'name', 'some text,JP,2007-04-25 06:24:00', html=( self.check_html(widget, 'name', 'some text,JP,2007-04-25 06:24:00', html=(
""" """
<input type="text" name="name_0" value="some text" /> <input type="text" name="name_0" value="some text">
<select multiple name="name_1"> <select multiple name="name_1">
<option value="J" selected>John</option> <option value="J" selected>John</option>
<option value="P" selected>Paul</option> <option value="P" selected>Paul</option>
<option value="G">George</option> <option value="G">George</option>
<option value="R">Ringo</option> <option value="R">Ringo</option>
</select> </select>
<input type="text" name="name_2_0" value="2007-04-25" /> <input type="text" name="name_2_0" value="2007-04-25">
<input type="text" name="name_2_1" value="06:24:00" /> <input type="text" name="name_2_1" value="06:24:00">
""" """
)) ))
def test_no_whitespace_between_widgets(self): def test_no_whitespace_between_widgets(self):
widget = MyMultiWidget(widgets=(TextInput, TextInput())) widget = MyMultiWidget(widgets=(TextInput, TextInput()))
self.check_html(widget, 'code', None, html=( self.check_html(widget, 'code', None, html=(
'<input type="text" name="code_0" />' '<input type="text" name="code_0">'
'<input type="text" name="code_1" />' '<input type="text" name="code_1">'
), strict=True) ), strict=True)
def test_deepcopy(self): def test_deepcopy(self):

View File

@ -11,5 +11,5 @@ class NumberInputTests(WidgetTest):
widget = NumberInput(attrs={'max': 12345, 'min': 1234, 'step': 9999}) widget = NumberInput(attrs={'max': 12345, 'min': 1234, 'step': 9999})
self.check_html( self.check_html(
widget, 'name', 'value', widget, 'name', 'value',
'<input type="number" name="name" value="value" max="12345" min="1234" step="9999" />' '<input type="number" name="name" value="value" max="12345" min="1234" step="9999">'
) )

View File

@ -7,10 +7,10 @@ class PasswordInputTest(WidgetTest):
widget = PasswordInput() widget = PasswordInput()
def test_render(self): def test_render(self):
self.check_html(self.widget, 'password', '', html='<input type="password" name="password" />') self.check_html(self.widget, 'password', '', html='<input type="password" name="password">')
def test_render_ignore_value(self): def test_render_ignore_value(self):
self.check_html(self.widget, 'password', 'secret', html='<input type="password" name="password" />') self.check_html(self.widget, 'password', 'secret', html='<input type="password" name="password">')
def test_render_value_true(self): def test_render_value_true(self):
""" """
@ -18,9 +18,9 @@ class PasswordInputTest(WidgetTest):
render its value. For security reasons, this is off by default. render its value. For security reasons, this is off by default.
""" """
widget = PasswordInput(render_value=True) widget = PasswordInput(render_value=True)
self.check_html(widget, 'password', '', html='<input type="password" name="password" />') self.check_html(widget, 'password', '', html='<input type="password" name="password">')
self.check_html(widget, 'password', None, html='<input type="password" name="password" />') self.check_html(widget, 'password', None, html='<input type="password" name="password">')
self.check_html( self.check_html(
widget, 'password', 'test@example.com', widget, 'password', 'test@example.com',
html='<input type="password" name="password" value="test@example.com" />', html='<input type="password" name="password" value="test@example.com">',
) )

View File

@ -13,11 +13,11 @@ class RadioSelectTest(WidgetTest):
choices = (('', '------'),) + self.beatles choices = (('', '------'),) + self.beatles
self.check_html(self.widget(choices=choices), 'beatle', 'J', html=( self.check_html(self.widget(choices=choices), 'beatle', 'J', html=(
"""<ul> """<ul>
<li><label><input type="radio" name="beatle" value="" /> ------</label></li> <li><label><input type="radio" name="beatle" value=""> ------</label></li>
<li><label><input checked type="radio" name="beatle" value="J" /> John</label></li> <li><label><input checked type="radio" name="beatle" value="J"> John</label></li>
<li><label><input type="radio" name="beatle" value="P" /> Paul</label></li> <li><label><input type="radio" name="beatle" value="P"> Paul</label></li>
<li><label><input type="radio" name="beatle" value="G" /> George</label></li> <li><label><input type="radio" name="beatle" value="G"> George</label></li>
<li><label><input type="radio" name="beatle" value="R" /> Ringo</label></li> <li><label><input type="radio" name="beatle" value="R"> Ringo</label></li>
</ul>""" </ul>"""
)) ))
@ -30,19 +30,19 @@ class RadioSelectTest(WidgetTest):
html = """ html = """
<ul id="media"> <ul id="media">
<li> <li>
<label for="media_0"><input id="media_0" name="nestchoice" type="radio" value="unknown" /> Unknown</label> <label for="media_0"><input id="media_0" name="nestchoice" type="radio" value="unknown"> Unknown</label>
</li> </li>
<li>Audio<ul id="media_1"> <li>Audio<ul id="media_1">
<li> <li>
<label for="media_1_0"><input id="media_1_0" name="nestchoice" type="radio" value="vinyl" /> Vinyl</label> <label for="media_1_0"><input id="media_1_0" name="nestchoice" type="radio" value="vinyl"> Vinyl</label>
</li> </li>
<li><label for="media_1_1"><input id="media_1_1" name="nestchoice" type="radio" value="cd" /> CD</label></li> <li><label for="media_1_1"><input id="media_1_1" name="nestchoice" type="radio" value="cd"> CD</label></li>
</ul></li> </ul></li>
<li>Video<ul id="media_2"> <li>Video<ul id="media_2">
<li><label for="media_2_0"><input id="media_2_0" name="nestchoice" type="radio" value="vhs" /> VHS</label></li> <li><label for="media_2_0"><input id="media_2_0" name="nestchoice" type="radio" value="vhs"> VHS</label></li>
<li> <li>
<label for="media_2_1"> <label for="media_2_1">
<input checked id="media_2_1" name="nestchoice" type="radio" value="dvd" /> DVD <input checked id="media_2_1" name="nestchoice" type="radio" value="dvd"> DVD
</label> </label>
</li> </li>
</ul></li> </ul></li>
@ -62,11 +62,11 @@ class RadioSelectTest(WidgetTest):
html = """ html = """
<ul id="foo"> <ul id="foo">
<li> <li>
<label for="foo_0"><input checked type="radio" id="foo_0" value="J" name="beatle" /> John</label> <label for="foo_0"><input checked type="radio" id="foo_0" value="J" name="beatle"> John</label>
</li> </li>
<li><label for="foo_1"><input type="radio" id="foo_1" value="P" name="beatle" /> Paul</label></li> <li><label for="foo_1"><input type="radio" id="foo_1" value="P" name="beatle"> Paul</label></li>
<li><label for="foo_2"><input type="radio" id="foo_2" value="G" name="beatle" /> George</label></li> <li><label for="foo_2"><input type="radio" id="foo_2" value="G" name="beatle"> George</label></li>
<li><label for="foo_3"><input type="radio" id="foo_3" value="R" name="beatle" /> Ringo</label></li> <li><label for="foo_3"><input type="radio" id="foo_3" value="R" name="beatle"> Ringo</label></li>
</ul> </ul>
""" """
self.check_html(widget, 'beatle', 'J', html=html) self.check_html(widget, 'beatle', 'J', html=html)
@ -79,11 +79,11 @@ class RadioSelectTest(WidgetTest):
html = """ html = """
<ul id="bar"> <ul id="bar">
<li> <li>
<label for="bar_0"><input checked type="radio" id="bar_0" value="J" name="beatle" /> John</label> <label for="bar_0"><input checked type="radio" id="bar_0" value="J" name="beatle"> John</label>
</li> </li>
<li><label for="bar_1"><input type="radio" id="bar_1" value="P" name="beatle" /> Paul</label></li> <li><label for="bar_1"><input type="radio" id="bar_1" value="P" name="beatle"> Paul</label></li>
<li><label for="bar_2"><input type="radio" id="bar_2" value="G" name="beatle" /> George</label></li> <li><label for="bar_2"><input type="radio" id="bar_2" value="G" name="beatle"> George</label></li>
<li><label for="bar_3"><input type="radio" id="bar_3" value="R" name="beatle" /> Ringo</label></li> <li><label for="bar_3"><input type="radio" id="bar_3" value="R" name="beatle"> Ringo</label></li>
</ul> </ul>
""" """
self.check_html(self.widget(choices=self.beatles), 'beatle', 'J', attrs={'id': 'bar'}, html=html) self.check_html(self.widget(choices=self.beatles), 'beatle', 'J', attrs={'id': 'bar'}, html=html)
@ -95,10 +95,10 @@ class RadioSelectTest(WidgetTest):
""" """
html = """ html = """
<ul class="bar"> <ul class="bar">
<li><label><input checked type="radio" class="bar" value="J" name="beatle" /> John</label></li> <li><label><input checked type="radio" class="bar" value="J" name="beatle"> John</label></li>
<li><label><input type="radio" class="bar" value="P" name="beatle" /> Paul</label></li> <li><label><input type="radio" class="bar" value="P" name="beatle"> Paul</label></li>
<li><label><input type="radio" class="bar" value="G" name="beatle" /> George</label></li> <li><label><input type="radio" class="bar" value="G" name="beatle"> George</label></li>
<li><label><input type="radio" class="bar" value="R" name="beatle" /> Ringo</label></li> <li><label><input type="radio" class="bar" value="R" name="beatle"> Ringo</label></li>
</ul> </ul>
""" """
self.check_html(self.widget(choices=self.beatles), 'beatle', 'J', attrs={'class': 'bar'}, html=html) self.check_html(self.widget(choices=self.beatles), 'beatle', 'J', attrs={'class': 'bar'}, html=html)
@ -112,9 +112,9 @@ class RadioSelectTest(WidgetTest):
] ]
html = """ html = """
<ul> <ul>
<li><label><input type="radio" name="number" value="1" /> One</label></li> <li><label><input type="radio" name="number" value="1"> One</label></li>
<li><label><input type="radio" name="number" value="1000" /> One thousand</label></li> <li><label><input type="radio" name="number" value="1000"> One thousand</label></li>
<li><label><input type="radio" name="number" value="1000000" /> One million</label></li> <li><label><input type="radio" name="number" value="1000000"> One million</label></li>
</ul> </ul>
""" """
self.check_html(self.widget(choices=choices), 'number', None, html=html) self.check_html(self.widget(choices=choices), 'number', None, html=html)
@ -125,8 +125,8 @@ class RadioSelectTest(WidgetTest):
] ]
html = """ html = """
<ul> <ul>
<li><label><input type="radio" name="time" value="00:00:00" /> midnight</label></li> <li><label><input type="radio" name="time" value="00:00:00"> midnight</label></li>
<li><label><input type="radio" name="time" value="12:00:00" /> noon</label></li> <li><label><input type="radio" name="time" value="12:00:00"> noon</label></li>
</ul> </ul>
""" """
self.check_html(self.widget(choices=choices), 'time', None, html=html) self.check_html(self.widget(choices=choices), 'time', None, html=html)

View File

@ -10,37 +10,37 @@ class SplitDateTimeWidgetTest(WidgetTest):
def test_render_empty(self): def test_render_empty(self):
self.check_html(self.widget, 'date', '', html=( self.check_html(self.widget, 'date', '', html=(
'<input type="text" name="date_0" /><input type="text" name="date_1" />' '<input type="text" name="date_0"><input type="text" name="date_1">'
)) ))
def test_render_none(self): def test_render_none(self):
self.check_html(self.widget, 'date', None, html=( self.check_html(self.widget, 'date', None, html=(
'<input type="text" name="date_0" /><input type="text" name="date_1" />' '<input type="text" name="date_0"><input type="text" name="date_1">'
)) ))
def test_render_datetime(self): def test_render_datetime(self):
self.check_html(self.widget, 'date', datetime(2006, 1, 10, 7, 30), html=( self.check_html(self.widget, 'date', datetime(2006, 1, 10, 7, 30), html=(
'<input type="text" name="date_0" value="2006-01-10" />' '<input type="text" name="date_0" value="2006-01-10">'
'<input type="text" name="date_1" value="07:30:00" />' '<input type="text" name="date_1" value="07:30:00">'
)) ))
def test_render_date_and_time(self): def test_render_date_and_time(self):
self.check_html(self.widget, 'date', [date(2006, 1, 10), time(7, 30)], html=( self.check_html(self.widget, 'date', [date(2006, 1, 10), time(7, 30)], html=(
'<input type="text" name="date_0" value="2006-01-10" />' '<input type="text" name="date_0" value="2006-01-10">'
'<input type="text" name="date_1" value="07:30:00" />' '<input type="text" name="date_1" value="07:30:00">'
)) ))
def test_constructor_attrs(self): def test_constructor_attrs(self):
widget = SplitDateTimeWidget(attrs={'class': 'pretty'}) widget = SplitDateTimeWidget(attrs={'class': 'pretty'})
self.check_html(widget, 'date', datetime(2006, 1, 10, 7, 30), html=( self.check_html(widget, 'date', datetime(2006, 1, 10, 7, 30), html=(
'<input type="text" class="pretty" value="2006-01-10" name="date_0" />' '<input type="text" class="pretty" value="2006-01-10" name="date_0">'
'<input type="text" class="pretty" value="07:30:00" name="date_1" />' '<input type="text" class="pretty" value="07:30:00" name="date_1">'
)) ))
def test_constructor_different_attrs(self): def test_constructor_different_attrs(self):
html = ( html = (
'<input type="text" class="foo" value="2006-01-10" name="date_0" />' '<input type="text" class="foo" value="2006-01-10" name="date_0">'
'<input type="text" class="bar" value="07:30:00" name="date_1" />' '<input type="text" class="bar" value="07:30:00" name="date_1">'
) )
widget = SplitDateTimeWidget(date_attrs={'class': 'foo'}, time_attrs={'class': 'bar'}) widget = SplitDateTimeWidget(date_attrs={'class': 'foo'}, time_attrs={'class': 'bar'})
self.check_html(widget, 'date', datetime(2006, 1, 10, 7, 30), html=html) self.check_html(widget, 'date', datetime(2006, 1, 10, 7, 30), html=html)
@ -58,6 +58,6 @@ class SplitDateTimeWidgetTest(WidgetTest):
date_format='%d/%m/%Y', time_format='%H:%M', date_format='%d/%m/%Y', time_format='%H:%M',
) )
self.check_html(widget, 'date', datetime(2006, 1, 10, 7, 30), html=( self.check_html(widget, 'date', datetime(2006, 1, 10, 7, 30), html=(
'<input type="text" name="date_0" value="10/01/2006" />' '<input type="text" name="date_0" value="10/01/2006">'
'<input type="text" name="date_1" value="07:30" />' '<input type="text" name="date_1" value="07:30">'
)) ))

View File

@ -12,22 +12,22 @@ class SplitHiddenDateTimeWidgetTest(WidgetTest):
def test_render_empty(self): def test_render_empty(self):
self.check_html(self.widget, 'date', '', html=( self.check_html(self.widget, 'date', '', html=(
'<input type="hidden" name="date_0" /><input type="hidden" name="date_1" />' '<input type="hidden" name="date_0"><input type="hidden" name="date_1">'
)) ))
def test_render_value(self): def test_render_value(self):
d = datetime(2007, 9, 17, 12, 51, 34, 482548) d = datetime(2007, 9, 17, 12, 51, 34, 482548)
self.check_html(self.widget, 'date', d, html=( self.check_html(self.widget, 'date', d, html=(
'<input type="hidden" name="date_0" value="2007-09-17" />' '<input type="hidden" name="date_0" value="2007-09-17">'
'<input type="hidden" name="date_1" value="12:51:34" />' '<input type="hidden" name="date_1" value="12:51:34">'
)) ))
self.check_html(self.widget, 'date', datetime(2007, 9, 17, 12, 51, 34), html=( self.check_html(self.widget, 'date', datetime(2007, 9, 17, 12, 51, 34), html=(
'<input type="hidden" name="date_0" value="2007-09-17" />' '<input type="hidden" name="date_0" value="2007-09-17">'
'<input type="hidden" name="date_1" value="12:51:34" />' '<input type="hidden" name="date_1" value="12:51:34">'
)) ))
self.check_html(self.widget, 'date', datetime(2007, 9, 17, 12, 51), html=( self.check_html(self.widget, 'date', datetime(2007, 9, 17, 12, 51), html=(
'<input type="hidden" name="date_0" value="2007-09-17" />' '<input type="hidden" name="date_0" value="2007-09-17">'
'<input type="hidden" name="date_1" value="12:51:00" />' '<input type="hidden" name="date_1" value="12:51:00">'
)) ))
@override_settings(USE_L10N=True) @override_settings(USE_L10N=True)
@ -36,15 +36,15 @@ class SplitHiddenDateTimeWidgetTest(WidgetTest):
d = datetime(2007, 9, 17, 12, 51) d = datetime(2007, 9, 17, 12, 51)
self.check_html(self.widget, 'date', d, html=( self.check_html(self.widget, 'date', d, html=(
""" """
<input type="hidden" name="date_0" value="17.09.2007" /> <input type="hidden" name="date_0" value="17.09.2007">
<input type="hidden" name="date_1" value="12:51:00" /> <input type="hidden" name="date_1" value="12:51:00">
""" """
)) ))
def test_constructor_different_attrs(self): def test_constructor_different_attrs(self):
html = ( html = (
'<input type="hidden" class="foo" value="2006-01-10" name="date_0" />' '<input type="hidden" class="foo" value="2006-01-10" name="date_0">'
'<input type="hidden" class="bar" value="07:30:00" name="date_1" />' '<input type="hidden" class="bar" value="07:30:00" name="date_1">'
) )
widget = SplitHiddenDateTimeWidget(date_attrs={'class': 'foo'}, time_attrs={'class': 'bar'}) widget = SplitHiddenDateTimeWidget(date_attrs={'class': 'foo'}, time_attrs={'class': 'bar'})
self.check_html(widget, 'date', datetime(2006, 1, 10, 7, 30), html=html) self.check_html(widget, 'date', datetime(2006, 1, 10, 7, 30), html=html)

View File

@ -8,14 +8,14 @@ class TextInputTest(WidgetTest):
widget = TextInput() widget = TextInput()
def test_render(self): def test_render(self):
self.check_html(self.widget, 'email', '', html='<input type="text" name="email" />') self.check_html(self.widget, 'email', '', html='<input type="text" name="email">')
def test_render_none(self): def test_render_none(self):
self.check_html(self.widget, 'email', None, html='<input type="text" name="email" />') self.check_html(self.widget, 'email', None, html='<input type="text" name="email">')
def test_render_value(self): def test_render_value(self):
self.check_html(self.widget, 'email', 'test@example.com', html=( self.check_html(self.widget, 'email', 'test@example.com', html=(
'<input type="text" name="email" value="test@example.com" />' '<input type="text" name="email" value="test@example.com">'
)) ))
def test_render_boolean(self): def test_render_boolean(self):
@ -24,22 +24,22 @@ class TextInputTest(WidgetTest):
"False"). "False").
""" """
self.check_html(self.widget, 'get_spam', False, html=( self.check_html(self.widget, 'get_spam', False, html=(
'<input type="text" name="get_spam" value="False" />' '<input type="text" name="get_spam" value="False">'
)) ))
self.check_html(self.widget, 'get_spam', True, html=( self.check_html(self.widget, 'get_spam', True, html=(
'<input type="text" name="get_spam" value="True" />' '<input type="text" name="get_spam" value="True">'
)) ))
def test_render_quoted(self): def test_render_quoted(self):
self.check_html( self.check_html(
self.widget, 'email', 'some "quoted" & ampersanded value', self.widget, 'email', 'some "quoted" & ampersanded value',
html='<input type="text" name="email" value="some &quot;quoted&quot; &amp; ampersanded value" />', html='<input type="text" name="email" value="some &quot;quoted&quot; &amp; ampersanded value">',
) )
def test_render_custom_attrs(self): def test_render_custom_attrs(self):
self.check_html( self.check_html(
self.widget, 'email', 'test@example.com', attrs={'class': 'fun'}, self.widget, 'email', 'test@example.com', attrs={'class': 'fun'},
html='<input type="text" name="email" value="test@example.com" class="fun" />', html='<input type="text" name="email" value="test@example.com" class="fun">',
) )
def test_render_unicode(self): def test_render_unicode(self):
@ -47,16 +47,16 @@ class TextInputTest(WidgetTest):
self.widget, 'email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}, self.widget, 'email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'},
html=( html=(
'<input type="text" name="email" ' '<input type="text" name="email" '
'value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" class="fun" />' 'value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" class="fun">'
), ),
) )
def test_constructor_attrs(self): def test_constructor_attrs(self):
widget = TextInput(attrs={'class': 'fun', 'type': 'email'}) widget = TextInput(attrs={'class': 'fun', 'type': 'email'})
self.check_html(widget, 'email', '', html='<input type="email" class="fun" name="email" />') self.check_html(widget, 'email', '', html='<input type="email" class="fun" name="email">')
self.check_html( self.check_html(
widget, 'email', 'foo@example.com', widget, 'email', 'foo@example.com',
html='<input type="email" class="fun" value="foo@example.com" name="email" />', html='<input type="email" class="fun" value="foo@example.com" name="email">',
) )
def test_attrs_precedence(self): def test_attrs_precedence(self):
@ -67,12 +67,12 @@ class TextInputTest(WidgetTest):
widget = TextInput(attrs={'class': 'pretty'}) widget = TextInput(attrs={'class': 'pretty'})
self.check_html( self.check_html(
widget, 'email', '', attrs={'class': 'special'}, widget, 'email', '', attrs={'class': 'special'},
html='<input type="text" class="special" name="email" />', html='<input type="text" class="special" name="email">',
) )
def test_attrs_safestring(self): def test_attrs_safestring(self):
widget = TextInput(attrs={'onBlur': mark_safe("function('foo')")}) widget = TextInput(attrs={'onBlur': mark_safe("function('foo')")})
self.check_html(widget, 'email', '', html='<input onBlur="function(\'foo\')" type="text" name="email" />') self.check_html(widget, 'email', '', html='<input onBlur="function(\'foo\')" type="text" name="email">')
def test_use_required_attribute(self): def test_use_required_attribute(self):
# Text inputs can safely trigger the browser validation. # Text inputs can safely trigger the browser validation.

View File

@ -11,7 +11,7 @@ class TimeInputTest(WidgetTest):
widget = TimeInput() widget = TimeInput()
def test_render_none(self): def test_render_none(self):
self.check_html(self.widget, 'time', None, html='<input type="text" name="time" />') self.check_html(self.widget, 'time', None, html='<input type="text" name="time">')
def test_render_value(self): def test_render_value(self):
""" """
@ -19,18 +19,18 @@ class TimeInputTest(WidgetTest):
""" """
t = time(12, 51, 34, 482548) t = time(12, 51, 34, 482548)
self.assertEqual(str(t), '12:51:34.482548') self.assertEqual(str(t), '12:51:34.482548')
self.check_html(self.widget, 'time', t, html='<input type="text" name="time" value="12:51:34" />') self.check_html(self.widget, 'time', t, html='<input type="text" name="time" value="12:51:34">')
self.check_html(self.widget, 'time', time(12, 51, 34), html=( self.check_html(self.widget, 'time', time(12, 51, 34), html=(
'<input type="text" name="time" value="12:51:34" />' '<input type="text" name="time" value="12:51:34">'
)) ))
self.check_html(self.widget, 'time', time(12, 51), html=( self.check_html(self.widget, 'time', time(12, 51), html=(
'<input type="text" name="time" value="12:51:00" />' '<input type="text" name="time" value="12:51:00">'
)) ))
def test_string(self): def test_string(self):
"""Initializing from a string value.""" """Initializing from a string value."""
self.check_html(self.widget, 'time', '13:12:11', html=( self.check_html(self.widget, 'time', '13:12:11', html=(
'<input type="text" name="time" value="13:12:11" />' '<input type="text" name="time" value="13:12:11">'
)) ))
def test_format(self): def test_format(self):
@ -39,10 +39,10 @@ class TimeInputTest(WidgetTest):
""" """
t = time(12, 51, 34, 482548) t = time(12, 51, 34, 482548)
widget = TimeInput(format='%H:%M', attrs={'type': 'time'}) widget = TimeInput(format='%H:%M', attrs={'type': 'time'})
self.check_html(widget, 'time', t, html='<input type="time" name="time" value="12:51" />') self.check_html(widget, 'time', t, html='<input type="time" name="time" value="12:51">')
@override_settings(USE_L10N=True) @override_settings(USE_L10N=True)
@translation.override('de-at') @translation.override('de-at')
def test_l10n(self): def test_l10n(self):
t = time(12, 51, 34, 482548) t = time(12, 51, 34, 482548)
self.check_html(self.widget, 'time', t, html='<input type="text" name="time" value="12:51:34" />') self.check_html(self.widget, 'time', t, html='<input type="text" name="time" value="12:51:34">')

View File

@ -19,8 +19,8 @@ class WidgetTests(WidgetTest):
self.assertIs(widget.value_omitted_from_data({'field': 'value'}, {}, 'field'), False) self.assertIs(widget.value_omitted_from_data({'field': 'value'}, {}, 'field'), False)
def test_no_trailing_newline_in_attrs(self): def test_no_trailing_newline_in_attrs(self):
self.check_html(Input(), 'name', 'value', strict=True, html='<input type="None" name="name" value="value" />') self.check_html(Input(), 'name', 'value', strict=True, html='<input type="None" name="name" value="value">')
def test_attr_false_not_rendered(self): def test_attr_false_not_rendered(self):
html = '<input type="None" name="name" value="value" />' html = '<input type="None" name="name" value="value">'
self.check_html(Input(), 'name', 'value', html=html, attrs={'readonly': False}) self.check_html(Input(), 'name', 'value', html=html, attrs={'readonly': False})

Some files were not shown because too many files have changed in this diff Show More