import datetime
import mimetypes
import os
+from teleforma.utils import guess_mimetypes
import urllib
import uuid
sha1.update(chunk)
return sha1.hexdigest()
-
-def mimetype_file(path):
- return mimetypes.guess_type(path)[0]
-
-
def check_unique_mimetype(l):
i = 0
for d in l:
self.auto_reject('file not found')
return
- mime_type = mimetype_file(self.file.path)
+ mime_type = guess_mimetypes(self.file.path)
if mime_type:
if not 'pdf' in mime_type:
self.auto_reject('wrong format')
if instance.file:
trig_save = False
if not instance.mime_type:
- mime_type = mimetype_file(instance.file.path)
+ mime_type = guess_mimetypes(instance.file.path)
if mime_type:
- instance.mime_type = mimetype_file(instance.file.path)
+ instance.mime_type = guess_mimetypes(instance.file.path)
trig_save = True
# HOTFIX
else:
import mimetypes
import os
import string
+from teleforma.utils import guess_mimetypes
import django.db.models as models
from django.conf import settings
return 'image' in self.mime_type or is_url_image
def set_mime_type(self):
- self.mime_type = mimetypes.guess_type(self.file.path)[0]
+ self.mime_type = guess_mimetypes(self.file.path)
def __str__(self):
types = ' - '.join([str(t) for t in self.course_type.all()])
return 'image' in self.mime_type or is_url_image
def set_mime_type(self):
- self.mime_type = mimetypes.guess_type(self.file.path)[0]
+ self.mime_type = guess_mimetypes(self.file.path)
def __str__(self):
return self.title
if not self.mimetype:
if self.file:
if os.path.exists(self.file.path):
- self.mimetype = mimetypes.guess_type(self.file.path)[0]
+ self.mimetype = guess_mimetypes(self.file.path)
self.save()
return self.mimetype
else:
def set_mime_type(self):
if self.item.file:
- mime_type = mimetypes.guess_type(self.file.path)[0]
+ mime_type = guess_mimetypes(self.file.path)
if mime_type == 'audio/mpeg':
self.mime_type = 'audio/mp3'
else:
--- /dev/null
+import mimetypes
+
+def guess_mimetypes(path):
+ try:
+ path = path.decode()
+ except (UnicodeDecodeError, AttributeError):
+ pass
+ return mimetypes.guess_type(path)[0]
\ No newline at end of file
import os
from html import escape
from io import StringIO
+from teleforma.utils import guess_mimetypes
from django.conf import settings
from django.contrib import messages
def serve_media(media_path, content_type="", buffering=True, streaming=False):
if not content_type:
- content_type = mimetypes.guess_type(media_path)[0]
+ content_type = guess_mimetypes(media_path)
if not settings.DEBUG:
return nginx_media_accel(media_path, content_type=content_type,
document = Document.objects.get(pk=pk)
if get_access(document, courses):
return serve_media(document.file.path.encode('utf8'), streaming=False)
- #fsock = open(document.file.path.encode('utf8'), 'r')
- #mimetype = mimetypes.guess_type(document.file.path)[0]
- #extension = mimetypes.guess_extension(mimetype)
- #response = HttpResponse(fsock, mimetype=mimetype)
- # response['Content-Disposition'] = "attachment; filename=%s%s" % \
- # (document.title.encode('utf8'), extension)
- # return response
else:
return redirect('teleforma-home')
document = Document.objects.get(pk=pk)
if get_access(document, courses):
return serve_media(document.file.path.encode('utf8'), streaming=True)
- #fsock = open(document.file.path.encode('utf8'), 'r')
- #mimetype = mimetypes.guess_type(document.file.path)[0]
- #extension = mimetypes.guess_extension(mimetype)
- #response = HttpResponse(fsock, mimetype=mimetype)
- # return response
else:
return redirect('teleforma-home')
+from teleforma.utils import guess_mimetypes
from django.conf import settings
import re
import os
self.path = path
def mimetype(self):
- type, encoding = mimetypes.guess_type(self.filename)
+ type = guess_mimetypes(self.filename)
return type
def __iter__(self):