def value_from_datadict(self, data, files, name): upload = data.get(self.md5sum_field_name(name), None) fq = data.get(self.fq_field_name(name), None) if isinstance(upload, six.string_types) and upload[:3] == 'id:': # Pre uploaded linked file. return TemporaryFileWrapper.get_image_from_id(upload[3:], self.field_query) if fq != self.get_fq(): raise Exception(force_text('For some reason FQ value is wrong...')) was_deleted = CheckboxInput().value_from_datadict(data, files, self.clear_checkbox_name(name)) if not self.get_required_state() and was_deleted: # If isn't required and delete is checked if not upload: # False signals to clear any existing value, as opposed to just None return False if upload: try: real_file = TemporaryFileWrapper.objects.get(md5sum=upload) except TemporaryFileWrapper.DoesNotExist: pass else: upload = real_file.file return upload
def value_from_datadict(self, data, files, name): upload = data.get(self.md5sum_field_name(name), None) fq = data.get(self.fq_field_name(name), None) if isinstance(upload, six.string_types) and upload[:3] == 'id:': # Pre uploaded linked file. return TemporaryFileWrapper.get_image_from_id( upload[3:], self.field_query) if fq != self.get_fq(): raise Exception(force_text('For some reason FQ value is wrong...')) was_deleted = CheckboxInput().value_from_datadict( data, files, self.clear_checkbox_name(name)) if not self.get_required_state() and was_deleted: # If isn't required and delete is checked if not upload: # False signals to clear any existing value, as opposed to just None return False if upload: try: real_file = TemporaryFileWrapper.objects.get(md5sum=upload) except TemporaryFileWrapper.DoesNotExist: pass else: upload = real_file.file return upload
def to_python(self, data): if isinstance(data, six.string_types) and data[:3] == 'id:': # Pre uploaded linked file. return TemporaryFileWrapper.get_image_from_id(data[3:], self.field_query) data = super(ThorFormImageField, self).to_python(data) if data: content_type = ThorFormFileField.get_content_type(data) if content_type is not None and not allowed_type(content_type, self.allowed_types): ThorFormFileField.file_type_error(content_type, self.allowed_types) return data
def to_python(self, data): if isinstance(data, six.string_types) and data[:3] == 'id:': # Pre uploaded linked file. return TemporaryFileWrapper.get_image_from_id( data[3:], self.field_query) data = super(ThorFormImageField, self).to_python(data) if data: content_type = ThorFormFileField.get_content_type(data) if content_type is not None and not allowed_type( content_type, self.allowed_types): ThorFormFileField.file_type_error(content_type, self.allowed_types) return data