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