-
-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ImageFormField render with accept="image/*"' HTML attribute
Since Django 2.1, the default forms.ImageField has rendered with accept="image/*". Copy the code here to do the same.
- Loading branch information
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django import forms | ||
from django.test import SimpleTestCase | ||
from django.forms.widgets import FileInput | ||
|
||
from sorl.thumbnail.fields import ImageFormField | ||
|
||
|
||
class ImageFormFieldTest(SimpleTestCase): | ||
|
||
def assertWidgetRendersTo(self, field, to): | ||
class Form(forms.Form): | ||
f = field | ||
self.assertHTMLEqual(str(Form()["f"]), to) | ||
|
||
def test_widget_attrs_default_accept(self): | ||
f = ImageFormField() | ||
self.assertEqual(f.widget_attrs(FileInput()), {'accept': 'image/*'}) | ||
self.assertWidgetRendersTo(f, '<input type="file" name="f" accept="image/*" required id="id_f" />') |