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 ...@@ -37,7 +37,7 @@ from datetime import datetime, timedelta
import weblate import weblate
from weblate import appsettings from weblate import appsettings
from weblate.lang.models import Language 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.checks import CHECKS
from weblate.trans.models.unit import Unit from weblate.trans.models.unit import Unit
from weblate.trans.models.unitdata import Check, Suggestion, Comment from weblate.trans.models.unitdata import Check, Suggestion, Comment
...@@ -1223,17 +1223,20 @@ class Translation(models.Model, URLMixin, PercentMixin): ...@@ -1223,17 +1223,20 @@ class Translation(models.Model, URLMixin, PercentMixin):
''' '''
Top level handler for file uploads. Top level handler for file uploads.
''' '''
filecopy = fileobj.read()
fileobj.close()
# Load backend file # Load backend file
try: try:
# First try using own loader # First try using own loader
store = self.subproject.file_format_cls( store = self.subproject.file_format_cls(
fileobj, StringIOMode(fileobj.name, filecopy),
self.subproject.template_store self.subproject.template_store
) )
except Exception: except Exception:
# Fallback to automatic detection # Fallback to automatic detection
fileobj.seek(0) store = AutoFormat(
store = AutoFormat(fileobj) StringIOMode(fileobj.name, filecopy),
)
# Optionally set authorship # Optionally set authorship
if author is None: 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