Python django.forms.ImageField() Examples
The following are 30
code examples of django.forms.ImageField().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.forms
, or try the search function
.

Example #1
Source File: forms.py From SchoolIdolAPI with Apache License 2.0 | 6 votes |
def save(self, commit=True, use_card_filenames=False): instance = super(TinyPngForm, self).save(commit=False) for field in self.fields.keys(): if (hasattr(instance, field) and field in dir(self.Meta.model) and type(self.Meta.model._meta.get_field(field)) == models.models.ImageField): image = self.cleaned_data[field] if image and (isinstance(image, InMemoryUploadedFile) or isinstance(image, TemporaryUploadedFile)): filename = image.name _, extension = os.path.splitext(filename) if extension.lower() == '.png': image = shrinkImageFromData(image.read(), filename) if use_card_filenames and field in models.cardsImagesToName: image.name = models.cardsImagesToName[field]({ 'id': instance.id, 'firstname': instance.idol.name.split(' ')[-1] if instance.idol and instance.idol.name else 'Unknown', }) else: image.name = randomString(32) + extension setattr(instance, field, image) if commit: instance.save() return instance
Example #2
Source File: files.py From python2017 with MIT License | 5 votes |
def _check_image_library_installed(self): try: from PIL import Image # NOQA except ImportError: return [ checks.Error( 'Cannot use ImageField because Pillow is not installed.', hint=('Get Pillow at https://pypi.python.org/pypi/Pillow ' 'or run command "pip install Pillow".'), obj=self, id='fields.E210', ) ] else: return []
Example #3
Source File: files.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, **kwargs): self.width_field, self.height_field = width_field, height_field super(ImageField, self).__init__(verbose_name, name, **kwargs)
Example #4
Source File: files.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def contribute_to_class(self, cls, name): super(ImageField, self).contribute_to_class(cls, name) # Attach update_dimension_fields so that dimension fields declared # after their corresponding image field don't stay cleared by # Model.__init__, see bug #11196. signals.post_init.connect(self.update_dimension_fields, sender=cls)
Example #5
Source File: files.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def formfield(self, **kwargs): defaults = {'form_class': forms.ImageField} defaults.update(kwargs) return super(ImageField, self).formfield(**defaults)
Example #6
Source File: files.py From openhgsenti with Apache License 2.0 | 5 votes |
def __set__(self, instance, value): previous_file = instance.__dict__.get(self.field.name) super(ImageFileDescriptor, self).__set__(instance, value) # To prevent recalculating image dimensions when we are instantiating # an object from the database (bug #11084), only update dimensions if # the field had a value before this assignment. Since the default # value for FileField subclasses is an instance of field.attr_class, # previous_file will only be None when we are called from # Model.__init__(). The ImageField.update_dimension_fields method # hooked up to the post_init signal handles the Model.__init__() cases. # Assignment happening outside of Model.__init__() will trigger the # update right here. if previous_file is not None: self.field.update_dimension_fields(instance, force=True)
Example #7
Source File: files.py From openhgsenti with Apache License 2.0 | 5 votes |
def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, **kwargs): self.width_field, self.height_field = width_field, height_field super(ImageField, self).__init__(verbose_name, name, **kwargs)
Example #8
Source File: files.py From openhgsenti with Apache License 2.0 | 5 votes |
def check(self, **kwargs): errors = super(ImageField, self).check(**kwargs) errors.extend(self._check_image_library_installed()) return errors
Example #9
Source File: files.py From openhgsenti with Apache License 2.0 | 5 votes |
def _check_image_library_installed(self): try: from PIL import Image # NOQA except ImportError: return [ checks.Error( 'Cannot use ImageField because Pillow is not installed.', hint=('Get Pillow at https://pypi.python.org/pypi/Pillow ' 'or run command "pip install Pillow".'), obj=self, id='fields.E210', ) ] else: return []
Example #10
Source File: files.py From openhgsenti with Apache License 2.0 | 5 votes |
def deconstruct(self): name, path, args, kwargs = super(ImageField, self).deconstruct() if self.width_field: kwargs['width_field'] = self.width_field if self.height_field: kwargs['height_field'] = self.height_field return name, path, args, kwargs
Example #11
Source File: files.py From openhgsenti with Apache License 2.0 | 5 votes |
def formfield(self, **kwargs): defaults = {'form_class': forms.ImageField} defaults.update(kwargs) return super(ImageField, self).formfield(**defaults)
Example #12
Source File: images.py From Mxonline3 with Apache License 2.0 | 5 votes |
def get_field_attrs(self, attrs, db_field, **kwargs): if isinstance(db_field, models.ImageField): attrs['widget'] = AdminImageWidget attrs['form_class'] = AdminImageField self.include_image = True return attrs
Example #13
Source File: images.py From Mxonline3 with Apache License 2.0 | 5 votes |
def get_field_result(self, result, field_name): if isinstance(result.field, models.ImageField): if result.value: img = getattr(result.obj, field_name) result.text = mark_safe('<a href="%s" target="_blank" title="%s" data-gallery="gallery"><img src="%s" class="field_img"/></a>' % (img.url, result.label, img.url)) self.include_image = True return result # Media
Example #14
Source File: files.py From python2017 with MIT License | 5 votes |
def __set__(self, instance, value): previous_file = instance.__dict__.get(self.field.name) super(ImageFileDescriptor, self).__set__(instance, value) # To prevent recalculating image dimensions when we are instantiating # an object from the database (bug #11084), only update dimensions if # the field had a value before this assignment. Since the default # value for FileField subclasses is an instance of field.attr_class, # previous_file will only be None when we are called from # Model.__init__(). The ImageField.update_dimension_fields method # hooked up to the post_init signal handles the Model.__init__() cases. # Assignment happening outside of Model.__init__() will trigger the # update right here. if previous_file is not None: self.field.update_dimension_fields(instance, force=True)
Example #15
Source File: files.py From python2017 with MIT License | 5 votes |
def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, **kwargs): self.width_field, self.height_field = width_field, height_field super(ImageField, self).__init__(verbose_name, name, **kwargs)
Example #16
Source File: files.py From python2017 with MIT License | 5 votes |
def check(self, **kwargs): errors = super(ImageField, self).check(**kwargs) errors.extend(self._check_image_library_installed()) return errors
Example #17
Source File: files.py From python with Apache License 2.0 | 5 votes |
def formfield(self, **kwargs): defaults = {'form_class': forms.ImageField} defaults.update(kwargs) return super(ImageField, self).formfield(**defaults)
Example #18
Source File: files.py From python2017 with MIT License | 5 votes |
def deconstruct(self): name, path, args, kwargs = super(ImageField, self).deconstruct() if self.width_field: kwargs['width_field'] = self.width_field if self.height_field: kwargs['height_field'] = self.height_field return name, path, args, kwargs
Example #19
Source File: files.py From python2017 with MIT License | 5 votes |
def formfield(self, **kwargs): defaults = {'form_class': forms.ImageField} defaults.update(kwargs) return super(ImageField, self).formfield(**defaults)
Example #20
Source File: images.py From imoocc with GNU General Public License v2.0 | 5 votes |
def get_field_attrs(self, attrs, db_field, **kwargs): if isinstance(db_field, models.ImageField): attrs['widget'] = AdminImageWidget attrs['form_class'] = AdminImageField self.include_image = True return attrs
Example #21
Source File: images.py From imoocc with GNU General Public License v2.0 | 5 votes |
def get_field_result(self, result, field_name): if isinstance(result.field, models.ImageField): if result.value: img = getattr(result.obj, field_name) result.text = mark_safe('<a href="%s" target="_blank" title="%s" data-gallery="gallery"><img src="%s" class="field_img"/></a>' % (img.url, result.label, img.url)) self.include_image = True return result # Media
Example #22
Source File: images.py From devops with MIT License | 5 votes |
def get_field_attrs(self, attrs, db_field, **kwargs): if isinstance(db_field, models.ImageField): attrs['widget'] = AdminImageWidget attrs['form_class'] = AdminImageField self.include_image = True return attrs
Example #23
Source File: images.py From devops with MIT License | 5 votes |
def get_field_result(self, result, field_name): if isinstance(result.field, models.ImageField): if result.value: img = getattr(result.obj, field_name) result.text = mark_safe('<a href="%s" target="_blank" title="%s" data-gallery="gallery"><img src="%s" class="field_img"/></a>' % (img.url, result.label, img.url)) self.include_image = True return result # Media
Example #24
Source File: images.py From online with GNU Affero General Public License v3.0 | 5 votes |
def get_field_attrs(self, attrs, db_field, **kwargs): if isinstance(db_field, models.ImageField): attrs['widget'] = AdminImageWidget attrs['form_class'] = AdminImageField self.include_image = True return attrs
Example #25
Source File: images.py From online with GNU Affero General Public License v3.0 | 5 votes |
def get_field_result(self, result, field_name): if isinstance(result.field, models.ImageField): if result.value: img = getattr(result.obj, field_name) result.text = mark_safe('<a href="%s" target="_blank" title="%s" data-gallery="gallery"><img src="%s" class="field_img"/></a>' % (img.url, result.label, img.url)) self.include_image = True return result # Media
Example #26
Source File: images.py From Dailyfresh-B2C with Apache License 2.0 | 5 votes |
def get_field_attrs(self, attrs, db_field, **kwargs): if isinstance(db_field, models.ImageField): attrs['widget'] = AdminImageWidget attrs['form_class'] = AdminImageField self.include_image = True return attrs
Example #27
Source File: images.py From Dailyfresh-B2C with Apache License 2.0 | 5 votes |
def get_field_result(self, result, field_name): if isinstance(result.field, models.ImageField): if result.value: img = getattr(result.obj, field_name) result.text = mark_safe('<a href="%s" target="_blank" title="%s" data-gallery="gallery"><img src="%s" class="field_img"/></a>' % (img.url, result.label, img.url)) self.include_image = True return result # Media
Example #28
Source File: fields.py From Dailyfresh-B2C with Apache License 2.0 | 5 votes |
def __init__(self, *args, **kwargs): self._DjangoImageField = kwargs.pop('_DjangoImageField', DjangoImageField) super(ImageField, self).__init__(*args, **kwargs)
Example #29
Source File: images.py From ImitationTmall_Django with GNU General Public License v3.0 | 5 votes |
def get_field_attrs(self, attrs, db_field, **kwargs): if isinstance(db_field, models.ImageField): attrs['widget'] = AdminImageWidget attrs['form_class'] = AdminImageField self.include_image = True return attrs
Example #30
Source File: images.py From ImitationTmall_Django with GNU General Public License v3.0 | 5 votes |
def get_field_result(self, result, field_name): if isinstance(result.field, models.ImageField): if result.value: img = getattr(result.obj, field_name) result.text = mark_safe('<a href="%s" target="_blank" title="%s" data-gallery="gallery"><img src="%s" class="field_img"/></a>' % (img.url, result.label, img.url)) self.include_image = True return result # Media