misc: add fixmime utility
This commit is contained in:
parent
32e3ef96da
commit
e1890d0ea5
|
@ -146,4 +146,11 @@
|
|||
permission="cmf.ManagePortal"
|
||||
/>
|
||||
|
||||
<browser:view
|
||||
name="fixmime"
|
||||
for="collective.dms.basecontent.dmsfile.IDmsFile"
|
||||
class=".utils.FixMime"
|
||||
permission="cmf.ManagePortal"
|
||||
/>
|
||||
|
||||
</configure>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import os
|
||||
|
||||
from zope.component import getUtility
|
||||
from zope.schema.interfaces import IVocabularyFactory
|
||||
|
||||
|
@ -70,3 +72,17 @@ class ImportUserFolders(BrowserView):
|
|||
class Pdb(BrowserView):
|
||||
def __call__(self):
|
||||
import pdb; pdb.set_trace()
|
||||
|
||||
class FixMime(BrowserView):
|
||||
def __call__(self):
|
||||
ext = os.path.splitext(self.context.file.filename)[-1]
|
||||
if ext == '.odt':
|
||||
new_mime = 'application/vnd.oasis.opendocument.text'
|
||||
elif ext == '.pdf':
|
||||
new_mime = 'application/pdf'
|
||||
else:
|
||||
return 'Unknown'
|
||||
if self.context.file.contentType == new_mime:
|
||||
return 'No change'
|
||||
self.context.file.contentType = new_mime
|
||||
return 'OK'
|
||||
|
|
Reference in New Issue