def _save_data(target, value, oldvalue, initiator): """ Refresh metadata and save the binary data to the data field. :param target: The File instance :type target: :class:`kotti.resources.File` or subclass :param value: The container for binary data :type value: A :class:`cgi.FieldStorage` instance """ if isinstance(value, bytes): value = _to_fieldstorage(fp=StringIO(value), filename=target.filename, mimetype=target.mimetype, size=len(value)) newvalue = _SQLAMutationTracker._field_set(target, value, oldvalue, initiator) if newvalue is None: return target.filename = newvalue.filename target.mimetype = newvalue.content_type target.size = newvalue.file.content_length return newvalue
def edit(self, **appstruct): title = appstruct["title"] self.context.title = title self.context.description = appstruct["description"] self.context.tags = appstruct["tags"] if appstruct["file"]: self.context.data = _to_fieldstorage(**appstruct["file"])
def _save_data(cls, target, value, oldvalue, initiator): """ Refresh metadata and save the binary data to the data field. :param target: The File instance :type target: :class:`kotti.resources.File` or subclass :param value: The container for binary data :type value: A :class:`cgi.FieldStorage` instance """ if isinstance(value, bytes): value = _to_fieldstorage(fp=StringIO(value), filename=target.filename, mimetype=target.mimetype, size=len(value)) newvalue = _SQLAMutationTracker._field_set( target, value, oldvalue, initiator) if newvalue is None: return target.filename = newvalue.filename target.mimetype = newvalue.content_type target.size = newvalue.file.content_length return newvalue
def edit(self, **appstruct): title = appstruct['title'] self.context.title = title self.context.description = appstruct['description'] self.context.tags = appstruct['tags'] if appstruct['file']: self.context.data = _to_fieldstorage(**appstruct['file'])
def _save_data(target: 'File', value: Optional[Union[FieldStorage, bytes, UploadedFile, BufferedReader]], # noqa oldvalue: Optional[Union[UploadedFile, _symbol]], initiator: Event) -> Optional[UploadedFile]: """ Refresh metadata and save the binary data to the data field. :param target: The File instance :type target: :class:`kotti.resources.File` or subclass :param value: The container for binary data :type value: A :class:`cgi.FieldStorage` instance """ if isinstance(value, bytes): fp = BytesIO(value) value = _to_fieldstorage(fp=fp, filename=target.filename, mimetype=target.mimetype, size=len(value)) newvalue = _SQLAMutationTracker._field_set( target, value, oldvalue, initiator) if newvalue is None: return target.filename = newvalue.filename target.mimetype = newvalue.content_type target.size = newvalue.file.content_length return newvalue
def edit(self, **appstruct): title = appstruct['title'] self.context.title = title self.context.description = appstruct['description'] self.context.tags = appstruct['tags'] if appstruct['file'] and appstruct['file']['fp']: self.context.data = _to_fieldstorage(**appstruct['file'])
def migrate_storage(from_storage: str, to_storage: str) -> None: log = logging.getLogger(__name__) old_default = DepotManager._default_depot DepotManager._default_depot = to_storage for klass, props in _SQLAMutationTracker.mapped_entities.items(): log.info("Migrating %r", klass) mapper = klass._sa_class_manager.mapper # use type column to avoid polymorphism issues, getting the same # Node item multiple times. type_ = camel_case_to_name(klass.__name__) for instance in DBSession.query(klass).filter_by(type=type_): for prop in props: uf = getattr(instance, prop) if not uf: continue pk = mapper.primary_key_from_instance(instance) log.info("Migrating %s for %r with pk %r", prop, klass, pk) filename = uf["filename"] content_type = uf["content_type"] data = _to_fieldstorage( fp=uf.file, filename=filename, mimetype=content_type, size=uf.file.content_length, ) setattr(instance, prop, data) DepotManager._default_depot = old_default
def migrate_storage(from_storage, to_storage): log = logging.getLogger(__name__) old_default = DepotManager._default_depot DepotManager._default_depot = to_storage for klass, props in _SQLAMutationTracker.mapped_entities.items(): log.info("Migrating %r", klass) mapper = klass._sa_class_manager.mapper # use type column to avoid polymorphism issues, getting the same # Node item multiple times. type_ = camel_case_to_name(klass.__name__) for instance in DBSession.query(klass).filter_by(type=type_): for prop in props: uf = getattr(instance, prop) if not uf: continue pk = mapper.primary_key_from_instance(instance) log.info("Migrating %s for %r with pk %r", prop, klass, pk) filename = uf['filename'] content_type = uf['content_type'] data = _to_fieldstorage(fp=uf.file, filename=filename, mimetype=content_type, size=uf.file.content_length) setattr(instance, prop, data) DepotManager._default_depot = old_default
def edit(self, **appstruct): title = appstruct["title"] self.context.title = title self.context.description = appstruct["description"] self.context.tags = appstruct["tags"] if appstruct["file"] and appstruct["file"]["fp"]: self.context.data = _to_fieldstorage(**appstruct["file"])
def _save_data( target: 'File', value: Optional[Union[FieldStorage, bytes, UploadedFile, BufferedReader]], # noqa oldvalue: Optional[Union[UploadedFile, _symbol]], initiator: Event) -> Optional[UploadedFile]: """ Refresh metadata and save the binary data to the data field. :param target: The File instance :type target: :class:`kotti.resources.File` or subclass :param value: The container for binary data :type value: A :class:`cgi.FieldStorage` instance """ if isinstance(value, bytes): fp = BytesIO(value) value = _to_fieldstorage(fp=fp, filename=target.filename, mimetype=target.mimetype, size=len(value)) newvalue = _SQLAMutationTracker._field_set(target, value, oldvalue, initiator) if newvalue is None: return target.filename = newvalue.filename target.mimetype = newvalue.content_type target.size = newvalue.file.content_length return newvalue
def add(self, **appstruct): filename = appstruct["file"]["filename"] item = self.item_class( title=appstruct["title"] or filename, description=appstruct["description"], tags=appstruct["tags"], data=_to_fieldstorage(**appstruct["file"]), ) return item
def add(self, **appstruct): filename = appstruct['file']['filename'] item = self.item_class( title=appstruct['title'] or filename, description=appstruct['description'], tags=appstruct['tags'], data=_to_fieldstorage(**appstruct['file']), ) return item