set model mimetype, even when content=False

This commit is contained in:
Min RK 2015-07-20 12:10:25 -07:00
parent 6ec427b523
commit f64aa490e3
2 changed files with 7 additions and 8 deletions

View File

@ -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

View File

@ -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: