Commit bb0dc52e authored by Michal Čihař's avatar Michal Čihař

Fix file import with Django 1.7

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 47247d13
......@@ -37,7 +37,7 @@ from datetime import datetime, timedelta
import weblate
from weblate import appsettings
from weblate.lang.models import Language
from weblate.trans.formats import AutoFormat
from weblate.trans.formats import AutoFormat, StringIOMode
from weblate.trans.checks import CHECKS
from weblate.trans.models.unit import Unit
from weblate.trans.models.unitdata import Check, Suggestion, Comment
......@@ -1223,17 +1223,20 @@ class Translation(models.Model, URLMixin, PercentMixin):
'''
Top level handler for file uploads.
'''
filecopy = fileobj.read()
fileobj.close()
# Load backend file
try:
# First try using own loader
store = self.subproject.file_format_cls(
fileobj,
StringIOMode(fileobj.name, filecopy),
self.subproject.template_store
)
except Exception:
# Fallback to automatic detection
fileobj.seek(0)
store = AutoFormat(fileobj)
store = AutoFormat(
StringIOMode(fileobj.name, filecopy),
)
# Optionally set authorship
if author is None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment