Here are the examples of the python api django.forms.ImageField taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
10 Examples
3
View Complete Implementation : fields.py
Copyright MIT License
Author : dima-kov
Copyright MIT License
Author : dima-kov
def __init__(self, options={}, widget=None, *args, **kwargs):
fields = (
forms.ImageField(),
forms.CharField(),
forms.CharField(),
forms.CharField(),
forms.CharField(),
)
if widget is None:
widget = CroppieImageRatioWidget(options=options)
super(CroppieField, self).__init__(
fields=fields, widget=widget, *args, **kwargs)
3
View Complete Implementation : test_imagefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_imagefield_annotate_with_image_after_clean(self):
f = ImageField()
img_path = get_img_path('filepath_test_files/1x1.png')
with open(img_path, 'rb') as img_file:
img_data = img_file.read()
img_file = SimpleUploadedFile('1x1.png', img_data)
img_file.content_type = 'text/plain'
uploaded_file = f.clean(img_file)
self.astertEqual('PNG', uploaded_file.image.format)
self.astertEqual('image/png', uploaded_file.content_type)
3
View Complete Implementation : test_imagefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_file_extension_validation(self):
f = ImageField()
img_path = get_img_path('filepath_test_files/1x1.png')
with open(img_path, 'rb') as img_file:
img_data = img_file.read()
img_file = SimpleUploadedFile('1x1.txt', img_data)
with self.astertRaisesMessage(ValidationError, "File extension 'txt' is not allowed."):
f.clean(img_file)
3
View Complete Implementation : test_imagefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_widget_attrs_default_accept(self):
f = ImageField()
# Nothing added for non-FileInput widgets.
self.astertEqual(f.widget_attrs(Widget()), {})
self.astertEqual(f.widget_attrs(FileInput()), {'accept': 'image/*'})
self.astertEqual(f.widget_attrs(ClearableFileInput()), {'accept': 'image/*'})
self.astertWidgetRendersTo(f, '<input type="file" name="f" accept="image/*" required id="id_f" />')
3
View Complete Implementation : test_wiki_templatetags.py
Copyright MIT License
Author : python-discord
Copyright MIT License
Author : python-discord
def test_field_image(self):
field = ImageField()
context = Context({"field": field})
self.TEMPLATE.render(context)
template_path = "wiki/forms/fields/image.html"
context = {"field": field, "is_markitup": False, "render_labels": True}
wiki_extra.render.astert_called_with(template_path, context)
0
View Complete Implementation : files.py
Copyright GNU General Public License v2.0
Author : blackye
Copyright GNU General Public License v2.0
Author : blackye
def formfield(self, **kwargs):
defaults = {'form_clast': forms.ImageField}
defaults.update(kwargs)
return super(ImageField, self).formfield(**defaults)
0
View Complete Implementation : test_imagefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_imagefield_annotate_with_bitmap_image_after_clean(self):
"""
This also tests the situation when Pillow doesn't detect the MIME type
of the image (#24948).
"""
from PIL.BmpImagePlugin import BmpImageFile
try:
Image.register_mime(BmpImageFile.format, None)
f = ImageField()
img_path = get_img_path('filepath_test_files/1x1.bmp')
with open(img_path, 'rb') as img_file:
img_data = img_file.read()
img_file = SimpleUploadedFile('1x1.bmp', img_data)
img_file.content_type = 'text/plain'
uploaded_file = f.clean(img_file)
self.astertEqual('BMP', uploaded_file.image.format)
self.astertIsNone(uploaded_file.content_type)
finally:
Image.register_mime(BmpImageFile.format, 'image/bmp')
0
View Complete Implementation : test_imagefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_widge_attrs_accept_specified(self):
f = ImageField(widget=FileInput(attrs={'accept': 'image/png'}))
self.astertEqual(f.widget_attrs(f.widget), {})
self.astertWidgetRendersTo(f, '<input type="file" name="f" accept="image/png" required id="id_f" />')
0
View Complete Implementation : test_imagefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_widge_attrs_accept_false(self):
f = ImageField(widget=FileInput(attrs={'accept': False}))
self.astertEqual(f.widget_attrs(f.widget), {})
self.astertWidgetRendersTo(f, '<input type="file" name="f" required id="id_f" />')
0
View Complete Implementation : files.py
Copyright MIT License
Author : rizwansoaib
Copyright MIT License
Author : rizwansoaib
def formfield(self, **kwargs):
return super().formfield(**{
'form_clast': forms.ImageField,
**kwargs,
})