mirror of https://github.com/django/django.git
Fixed warnings per flake8 5.0.0.
This commit is contained in:
parent
1e5bbbb2a8
commit
c18861804f
|
@ -9,7 +9,7 @@ repos:
|
|||
hooks:
|
||||
- id: isort
|
||||
- repo: https://github.com/PyCQA/flake8
|
||||
rev: 4.0.1
|
||||
rev: 5.0.0
|
||||
hooks:
|
||||
- id: flake8
|
||||
- repo: https://github.com/pre-commit/mirrors-eslint
|
||||
|
|
|
@ -72,18 +72,18 @@ class Command(BaseCommand):
|
|||
)
|
||||
content_type_display = "\n".join(ct_info)
|
||||
self.stdout.write(
|
||||
"""Some content types in your database are stale and can be deleted.
|
||||
Any objects that depend on these content types will also be deleted.
|
||||
The content types and dependent objects that would be deleted are:
|
||||
|
||||
%s
|
||||
|
||||
This list doesn't include any cascade deletions to data outside of Django's
|
||||
models (uncommon).
|
||||
|
||||
Are you sure you want to delete these content types?
|
||||
If you're unsure, answer 'no'."""
|
||||
% content_type_display
|
||||
"Some content types in your database are stale and can be "
|
||||
"deleted.\n"
|
||||
"Any objects that depend on these content types will also be "
|
||||
"deleted.\n"
|
||||
"The content types and dependent objects that would be deleted "
|
||||
"are:\n\n"
|
||||
f"{content_type_display}\n\n"
|
||||
"This list doesn't include any cascade deletions to data "
|
||||
"outside of Django's\n"
|
||||
"models (uncommon).\n\n"
|
||||
"Are you sure you want to delete these content types?\n"
|
||||
"If you're unsure, answer 'no'."
|
||||
)
|
||||
ok_to_delete = input("Type 'yes' to continue, or 'no' to cancel: ")
|
||||
else:
|
||||
|
|
|
@ -803,8 +803,9 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
|
|||
self.assertIs(response.context["cl"].has_related_field_in_list_display(), False)
|
||||
|
||||
def test_limited_filter(self):
|
||||
"""Ensure admin changelist filters do not contain objects excluded via limit_choices_to.
|
||||
This also tests relation-spanning filters (e.g. 'color__value').
|
||||
"""
|
||||
Admin changelist filters do not contain objects excluded via
|
||||
limit_choices_to.
|
||||
"""
|
||||
response = self.client.get(reverse("admin:admin_views_thing_changelist"))
|
||||
self.assertContains(
|
||||
|
|
|
@ -130,9 +130,12 @@ class FormsTestCase(SimpleTestCase):
|
|||
|
||||
self.assertHTMLEqual(
|
||||
"\n".join(form_output),
|
||||
"""<input type="text" name="first_name" value="John" id="id_first_name" required>
|
||||
<input type="text" name="last_name" value="Lennon" id="id_last_name" required>
|
||||
<input type="text" name="birthday" value="1940-10-9" id="id_birthday" required>""",
|
||||
'<input type="text" name="first_name" value="John" id="id_first_name" '
|
||||
"required>"
|
||||
'<input type="text" name="last_name" value="Lennon" id="id_last_name" '
|
||||
"required>"
|
||||
'<input type="text" name="birthday" value="1940-10-9" id="id_birthday" '
|
||||
"required>",
|
||||
)
|
||||
|
||||
form_output = []
|
||||
|
@ -893,10 +896,12 @@ class FormsTestCase(SimpleTestCase):
|
|||
f = BeatleForm(auto_id=False)
|
||||
self.assertHTMLEqual(
|
||||
"\n".join(str(bf) for bf in f["name"]),
|
||||
"""<label><input type="radio" name="name" value="john" required> John</label>
|
||||
<label><input type="radio" name="name" value="paul" required> Paul</label>
|
||||
<label><input type="radio" name="name" value="george" required> George</label>
|
||||
<label><input type="radio" name="name" value="ringo" required> Ringo</label>""",
|
||||
'<label><input type="radio" name="name" value="john" required> John</label>'
|
||||
'<label><input type="radio" name="name" value="paul" required> Paul</label>'
|
||||
'<label><input type="radio" name="name" value="george" required> George'
|
||||
"</label>"
|
||||
'<label><input type="radio" name="name" value="ringo" required> Ringo'
|
||||
"</label>",
|
||||
)
|
||||
self.assertHTMLEqual(
|
||||
"\n".join("<div>%s</div>" % bf for bf in f["name"]),
|
||||
|
@ -2229,8 +2234,10 @@ class FormsTestCase(SimpleTestCase):
|
|||
p = UserRegistration(auto_id=False)
|
||||
self.assertHTMLEqual(
|
||||
p.as_ul(),
|
||||
"""<li>Username: <input type="text" name="username" maxlength="10" required></li>
|
||||
<li>Password: <input type="password" name="password" maxlength="10" required></li>""",
|
||||
'<li>Username: <input type="text" name="username" maxlength="10" required>'
|
||||
"</li>"
|
||||
'<li>Password: <input type="password" name="password" maxlength="10" '
|
||||
"required></li>",
|
||||
)
|
||||
|
||||
def test_specifying_labels(self):
|
||||
|
@ -2320,8 +2327,9 @@ class FormsTestCase(SimpleTestCase):
|
|||
p = UserRegistration(auto_id=False)
|
||||
self.assertHTMLEqual(
|
||||
p.as_ul(),
|
||||
"""<li>Username: <input type="text" name="username" maxlength="10" required></li>
|
||||
<li>Password: <input type="password" name="password" required></li>""",
|
||||
'<li>Username: <input type="text" name="username" maxlength="10" required>'
|
||||
"</li>"
|
||||
'<li>Password: <input type="password" name="password" required></li>',
|
||||
)
|
||||
p = UserRegistration(auto_id="id_%s")
|
||||
self.assertHTMLEqual(
|
||||
|
@ -2945,11 +2953,12 @@ Options: <select multiple name="options" required>
|
|||
p = UserRegistration({"username": "foo"}, auto_id=False)
|
||||
self.assertHTMLEqual(
|
||||
p.as_ul(),
|
||||
"""<li>Username: <input type="text" name="username" value="foo" maxlength="10" required>
|
||||
<span class="helptext">e.g., user@example.com</span></li>
|
||||
<li><ul class="errorlist"><li>This field is required.</li></ul>
|
||||
Password: <input type="password" name="password" required>
|
||||
<span class="helptext">Wählen Sie mit Bedacht.</span></li>""",
|
||||
'<li>Username: <input type="text" name="username" value="foo" '
|
||||
'maxlength="10" required>'
|
||||
'<span class="helptext">e.g., user@example.com</span></li>'
|
||||
'<li><ul class="errorlist"><li>This field is required.</li></ul>'
|
||||
'Password: <input type="password" name="password" required>'
|
||||
'<span class="helptext">Wählen Sie mit Bedacht.</span></li>',
|
||||
)
|
||||
|
||||
# help_text is not displayed for hidden fields. It can be used for documentation
|
||||
|
|
|
@ -245,10 +245,11 @@ class FormsFormsetTestCase(SimpleTestCase):
|
|||
)
|
||||
self.assertHTMLEqual(
|
||||
"\n".join(form.as_ul() for form in formset.forms),
|
||||
"""<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>Choice: <input type="text" name="choices-1-choice"></li>
|
||||
<li>Votes: <input type="number" name="choices-1-votes"></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>Choice: <input type="text" name="choices-1-choice"></li>'
|
||||
'<li>Votes: <input type="number" name="choices-1-votes"></li>',
|
||||
)
|
||||
|
||||
def test_blank_form_unfilled(self):
|
||||
|
@ -564,14 +565,15 @@ class FormsFormsetTestCase(SimpleTestCase):
|
|||
formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices")
|
||||
self.assertHTMLEqual(
|
||||
"\n".join(form.as_ul() for form in formset.forms),
|
||||
"""<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>Choice: <input type="text" name="choices-1-choice"></li>
|
||||
<li>Votes: <input type="number" name="choices-1-votes"></li>
|
||||
<li>Choice: <input type="text" name="choices-2-choice"></li>
|
||||
<li>Votes: <input type="number" name="choices-2-votes"></li>
|
||||
<li>Choice: <input type="text" name="choices-3-choice"></li>
|
||||
<li>Votes: <input type="number" name="choices-3-votes"></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>Choice: <input type="text" name="choices-1-choice"></li>'
|
||||
'<li>Votes: <input type="number" name="choices-1-votes"></li>'
|
||||
'<li>Choice: <input type="text" name="choices-2-choice"></li>'
|
||||
'<li>Votes: <input type="number" name="choices-2-votes"></li>'
|
||||
'<li>Choice: <input type="text" name="choices-3-choice"></li>'
|
||||
'<li>Votes: <input type="number" name="choices-3-votes"></li>',
|
||||
)
|
||||
# Retrieving an empty form works. Tt shows up in the form list.
|
||||
self.assertTrue(formset.empty_form.empty_permitted)
|
||||
|
@ -595,15 +597,17 @@ class FormsFormsetTestCase(SimpleTestCase):
|
|||
formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices")
|
||||
self.assertHTMLEqual(
|
||||
"\n".join(form.as_ul() for form in formset.forms),
|
||||
"""<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>Delete: <input type="checkbox" name="choices-0-DELETE"></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>Delete: <input type="checkbox" name="choices-1-DELETE"></li>
|
||||
<li>Choice: <input type="text" name="choices-2-choice"></li>
|
||||
<li>Votes: <input type="number" name="choices-2-votes"></li>
|
||||
<li>Delete: <input type="checkbox" name="choices-2-DELETE"></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>Delete: <input type="checkbox" name="choices-0-DELETE"></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>Delete: <input type="checkbox" name="choices-1-DELETE"></li>'
|
||||
'<li>Choice: <input type="text" name="choices-2-choice"></li>'
|
||||
'<li>Votes: <input type="number" name="choices-2-votes"></li>'
|
||||
'<li>Delete: <input type="checkbox" name="choices-2-DELETE"></li>',
|
||||
)
|
||||
# To delete something, set that form's special delete field to 'on'.
|
||||
# Let's go ahead and delete Fergie.
|
||||
|
@ -738,15 +742,17 @@ class FormsFormsetTestCase(SimpleTestCase):
|
|||
formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices")
|
||||
self.assertHTMLEqual(
|
||||
"\n".join(form.as_ul() for form in formset.forms),
|
||||
"""<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>Order: <input type="number" name="choices-0-ORDER" value="1"></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>Order: <input type="number" name="choices-1-ORDER" value="2"></li>
|
||||
<li>Choice: <input type="text" name="choices-2-choice"></li>
|
||||
<li>Votes: <input type="number" name="choices-2-votes"></li>
|
||||
<li>Order: <input type="number" name="choices-2-ORDER"></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>Order: <input type="number" name="choices-0-ORDER" value="1"></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>Order: <input type="number" name="choices-1-ORDER" value="2"></li>'
|
||||
'<li>Choice: <input type="text" name="choices-2-choice"></li>'
|
||||
'<li>Votes: <input type="number" name="choices-2-votes"></li>'
|
||||
'<li>Order: <input type="number" name="choices-2-ORDER"></li>',
|
||||
)
|
||||
data = {
|
||||
"choices-TOTAL_FORMS": "3", # the number of forms rendered
|
||||
|
@ -864,22 +870,25 @@ class FormsFormsetTestCase(SimpleTestCase):
|
|||
formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices")
|
||||
self.assertHTMLEqual(
|
||||
"\n".join(form.as_ul() for form in formset.forms),
|
||||
"""<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>Order: <input type="number" name="choices-0-ORDER" value="1"></li>
|
||||
<li>Delete: <input type="checkbox" name="choices-0-DELETE"></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>Order: <input type="number" name="choices-1-ORDER" value="2"></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>Votes: <input type="number" name="choices-2-votes" value="500"></li>
|
||||
<li>Order: <input type="number" name="choices-2-ORDER" value="3"></li>
|
||||
<li>Delete: <input type="checkbox" name="choices-2-DELETE"></li>
|
||||
<li>Choice: <input type="text" name="choices-3-choice"></li>
|
||||
<li>Votes: <input type="number" name="choices-3-votes"></li>
|
||||
<li>Order: <input type="number" name="choices-3-ORDER"></li>
|
||||
<li>Delete: <input type="checkbox" name="choices-3-DELETE"></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>Order: <input type="number" name="choices-0-ORDER" value="1"></li>'
|
||||
'<li>Delete: <input type="checkbox" name="choices-0-DELETE"></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>Order: <input type="number" name="choices-1-ORDER" value="2"></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>Votes: <input type="number" name="choices-2-votes" value="500"></li>'
|
||||
'<li>Order: <input type="number" name="choices-2-ORDER" value="3"></li>'
|
||||
'<li>Delete: <input type="checkbox" name="choices-2-DELETE"></li>'
|
||||
'<li>Choice: <input type="text" name="choices-3-choice"></li>'
|
||||
'<li>Votes: <input type="number" name="choices-3-votes"></li>'
|
||||
'<li>Order: <input type="number" name="choices-3-ORDER"></li>'
|
||||
'<li>Delete: <input type="checkbox" name="choices-3-DELETE"></li>',
|
||||
)
|
||||
# Let's delete Fergie, and put The Decemberists ahead of Calexico.
|
||||
data = {
|
||||
|
|
|
@ -1929,26 +1929,28 @@ class ModelFormBasicTests(TestCase):
|
|||
f = ArticleForm(auto_id=False)
|
||||
self.assertHTMLEqual(
|
||||
f.as_ul(),
|
||||
"""<li>Headline: <input type="text" name="headline" maxlength="50" required></li>
|
||||
<li>Slug: <input type="text" name="slug" maxlength="50" required></li>
|
||||
<li>Pub date: <input type="text" name="pub_date" required></li>
|
||||
<li>Writer: <select name="writer" required>
|
||||
<option value="" selected>---------</option>
|
||||
<option value="%s">Bob Woodward</option>
|
||||
<option value="%s">Mike Royko</option>
|
||||
</select></li>
|
||||
<li>Article: <textarea rows="10" cols="40" name="article" required></textarea></li>
|
||||
<li>Categories: <select multiple name="categories">
|
||||
<option value="%s">Entertainment</option>
|
||||
<option value="%s">It's a test</option>
|
||||
<option value="%s">Third test</option>
|
||||
</select> </li>
|
||||
<li>Status: <select name="status">
|
||||
<option value="" selected>---------</option>
|
||||
<option value="1">Draft</option>
|
||||
<option value="2">Pending</option>
|
||||
<option value="3">Live</option>
|
||||
</select></li>"""
|
||||
'<li>Headline: <input type="text" name="headline" maxlength="50" required>'
|
||||
"</li>"
|
||||
'<li>Slug: <input type="text" name="slug" maxlength="50" required></li>'
|
||||
'<li>Pub date: <input type="text" name="pub_date" required></li>'
|
||||
'<li>Writer: <select name="writer" required>'
|
||||
'<option value="" selected>---------</option>'
|
||||
'<option value="%s">Bob Woodward</option>'
|
||||
'<option value="%s">Mike Royko</option>'
|
||||
"</select></li>"
|
||||
'<li>Article: <textarea rows="10" cols="40" name="article" required>'
|
||||
"</textarea></li>"
|
||||
'<li>Categories: <select multiple name="categories">'
|
||||
'<option value="%s">Entertainment</option>'
|
||||
'<option value="%s">It's a test</option>'
|
||||
'<option value="%s">Third test</option>'
|
||||
"</select> </li>"
|
||||
'<li>Status: <select name="status">'
|
||||
'<option value="" selected>---------</option>'
|
||||
'<option value="1">Draft</option>'
|
||||
'<option value="2">Pending</option>'
|
||||
'<option value="3">Live</option>'
|
||||
"</select></li>"
|
||||
% (self.w_woodward.pk, self.w_royko.pk, self.c1.pk, self.c2.pk, self.c3.pk),
|
||||
)
|
||||
|
||||
|
@ -1956,28 +1958,30 @@ class ModelFormBasicTests(TestCase):
|
|||
w_bernstein = Writer.objects.create(name="Carl Bernstein")
|
||||
self.assertHTMLEqual(
|
||||
f.as_ul(),
|
||||
"""<li>Headline: <input type="text" name="headline" maxlength="50" required></li>
|
||||
<li>Slug: <input type="text" name="slug" maxlength="50" required></li>
|
||||
<li>Pub date: <input type="text" name="pub_date" required></li>
|
||||
<li>Writer: <select name="writer" required>
|
||||
<option value="" selected>---------</option>
|
||||
<option value="%s">Bob Woodward</option>
|
||||
<option value="%s">Carl Bernstein</option>
|
||||
<option value="%s">Mike Royko</option>
|
||||
</select></li>
|
||||
<li>Article: <textarea rows="10" cols="40" name="article" required></textarea></li>
|
||||
<li>Categories: <select multiple name="categories">
|
||||
<option value="%s">Entertainment</option>
|
||||
<option value="%s">It's a test</option>
|
||||
<option value="%s">Third test</option>
|
||||
<option value="%s">Fourth</option>
|
||||
</select></li>
|
||||
<li>Status: <select name="status">
|
||||
<option value="" selected>---------</option>
|
||||
<option value="1">Draft</option>
|
||||
<option value="2">Pending</option>
|
||||
<option value="3">Live</option>
|
||||
</select></li>"""
|
||||
'<li>Headline: <input type="text" name="headline" maxlength="50" required>'
|
||||
"</li>"
|
||||
'<li>Slug: <input type="text" name="slug" maxlength="50" required></li>'
|
||||
'<li>Pub date: <input type="text" name="pub_date" required></li>'
|
||||
'<li>Writer: <select name="writer" required>'
|
||||
'<option value="" selected>---------</option>'
|
||||
'<option value="%s">Bob Woodward</option>'
|
||||
'<option value="%s">Carl Bernstein</option>'
|
||||
'<option value="%s">Mike Royko</option>'
|
||||
"</select></li>"
|
||||
'<li>Article: <textarea rows="10" cols="40" name="article" required>'
|
||||
"</textarea></li>"
|
||||
'<li>Categories: <select multiple name="categories">'
|
||||
'<option value="%s">Entertainment</option>'
|
||||
'<option value="%s">It's a test</option>'
|
||||
'<option value="%s">Third test</option>'
|
||||
'<option value="%s">Fourth</option>'
|
||||
"</select></li>"
|
||||
'<li>Status: <select name="status">'
|
||||
'<option value="" selected>---------</option>'
|
||||
'<option value="1">Draft</option>'
|
||||
'<option value="2">Pending</option>'
|
||||
'<option value="3">Live</option>'
|
||||
"</select></li>"
|
||||
% (
|
||||
self.w_woodward.pk,
|
||||
w_bernstein.pk,
|
||||
|
|
|
@ -29,10 +29,11 @@ class StaticFilesFormsMediaTestCase(SimpleTestCase):
|
|||
)
|
||||
self.assertEqual(
|
||||
str(m),
|
||||
"""<link href="https://example.com/assets/path/to/css1" media="all" rel="stylesheet">
|
||||
<link href="/path/to/css2" media="all" rel="stylesheet">
|
||||
<script src="/path/to/js1"></script>
|
||||
<script src="http://media.other.com/path/to/js2"></script>
|
||||
<script src="https://secure.other.com/path/to/js3"></script>
|
||||
<script src="https://example.com/assets/relative/path/to/js4"></script>""",
|
||||
'<link href="https://example.com/assets/path/to/css1" media="all" '
|
||||
'rel="stylesheet">\n'
|
||||
'<link href="/path/to/css2" media="all" rel="stylesheet">\n'
|
||||
'<script src="/path/to/js1"></script>\n'
|
||||
'<script src="http://media.other.com/path/to/js2"></script>\n'
|
||||
'<script src="https://secure.other.com/path/to/js3"></script>\n'
|
||||
'<script src="https://example.com/assets/relative/path/to/js4"></script>',
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue