set model mimetype, even when content=False

Min RK 11 years ago
parent 6ec427b523
commit f64aa490e3

@ -278,18 +278,20 @@ class FileContentsManager(FileManagerMixin, ContentsManager):
model['type'] = 'file'
os_path = self._get_os_path(path)
model['mimetype'] = mimetypes.guess_type(os_path)[0]
if content:
content, format = self._read_file(os_path, format)
default_mime = {
'text': 'text/plain',
'base64': 'application/octet-stream'
}[format]
if model['mimetype'] is None:
default_mime = {
'text': 'text/plain',
'base64': 'application/octet-stream'
}[format]
model['mimetype'] = default_mime
model.update(
content=content,
format=format,
mimetype=mimetypes.guess_type(os_path)[0] or default_mime,
)
return model

@ -55,9 +55,6 @@ def validate_model(model, expect_content):
)
maybe_none_keys = ['content', 'format']
if model['type'] == 'file':
# mimetype should be populated only for file models
maybe_none_keys.append('mimetype')
if expect_content:
errors = [key for key in maybe_none_keys if model[key] is None]
if errors:

Loading…
Cancel
Save