def update_subinterval_referencing_file(file): """Update a subinterval-referencing file model. :param file: a file model object to update. :param request.body: a JSON object containing the data for updating the file. :returns: the file model or, if the file has not been updated, ``False``. """ changed = False schema = FileSubintervalReferencingSchema() data = json.loads(unicode(request.body, request.charset)) data['name'] = data.get('name') or u'' state = h.State() state.full_dict = data state.user = session['user'] data = schema.to_python(data, state) # Data unique to referencing subinterval files changed = file.set_attr('parent_file', data['parent_file'], changed) changed = file.set_attr('name', (h.normalize(data['name']) or file.parent_file.filename), changed) changed = file.set_attr('start', data['start'], changed) changed = file.set_attr('end', data['end'], changed) file, changed = update_standard_metadata(file, data, changed) if changed: file.datetime_modified = datetime.datetime.utcnow() return file return changed
def create_subinterval_referencing_file(data): """Create a subinterval-referencing file. :param dict data: the data to create the file model. :param int data['parent_file']: the ``id`` value of an audio/video file model. :param float/int data['start']: the start of the interval in seconds. :param float/int data['end']: the end of the interval in seconds. :returns: an SQLAlchemy model object representing the file. A value for ``data['name']`` may also be supplied. """ data['name'] = data.get('name') or u'' schema = FileSubintervalReferencingSchema() state = h.State() state.full_dict = data state.user = session['user'] data = schema.to_python(data, state) file = File() # Data unique to referencing subinterval files file.parent_file = data['parent_file'] file.name = h.normalize(data['name']) or file.parent_file.filename # Name defaults to the parent file's filename if nothing provided by user file.start = data['start'] file.end = data['end'] file.MIME_type = file.parent_file.MIME_type file = add_standard_metadata(file, data) file = restrict_file_by_forms(file) return file