Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Use six to wrap differences between python 2 and 3

Roland Geideraafa081ea918
diff --git a/requirements.txt b/requirements.txt
index 05c4f0a55..25bef9abc 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -9,11 +9,16 @@ reportlab
django_mobile
bleach
south < 2.0
-django-tastypie==0.9.16
python-mimeparse
pillow
easy-thumbnails
django_compressor
icalendar
+
+# REST API
djangorestframework==2.3.13
-django-filter
\ No newline at end of file
+django-filter
+django-tastypie==0.9.16
+
+# Python3 compatibility
+six
diff --git a/wger/main.py b/wger/main.py
index afa9e60a2..7e983db5c 100755
--- a/wger/main.py
+++ b/wger/main.py
@@ -10,9 +10,7 @@
:license: GNU GPL, see LICENSE for more details.
"""
-# for python 2.5 support
-from __future__ import with_statement
-
+import six
import base64
import ctypes
import optparse
@@ -477,7 +475,7 @@ def start_browser(url):
def fs2unicode(s):
- if isinstance(s, unicode):
+ if isinstance(s, six.text_type):
return s
fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
return s.decode(fs_encoding)
diff --git a/wger/utils/widgets.py b/wger/utils/widgets.py
index cbd10f6d6..74fa77a03 100644
--- a/wger/utils/widgets.py
+++ b/wger/utils/widgets.py
@@ -25,7 +25,7 @@ from django.forms.widgets import TextInput
from django.forms import fields
from django.utils.translation import ugettext as _
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
from django.utils.html import escape
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
@@ -113,14 +113,14 @@ class ExerciseAjaxSelect(SelectMultiple):
def render_options(self, choices, selected_choices):
# Normalize to strings.
- selected_choices = set(force_unicode(v) for v in selected_choices)
+ selected_choices = set(force_text(v) for v in selected_choices)
output = []
for option_value, option_label in chain(self.choices, choices):
output.append(self.render_option(selected_choices, option_value, option_label))
return u'\n'.join(output)
def render_option(self, selected_choices, option_value, option_label):
- option_value = force_unicode(option_value)
+ option_value = force_text(option_value)
if option_value in selected_choices:
return u'''
@@ -133,7 +133,7 @@ class ExerciseAjaxSelect(SelectMultiple):
</a> %(value)s
<input type="hidden" name="exercises" value="%(id)s">
</div>
- ''' % {'value': conditional_escape(force_unicode(option_label)),
+ ''' % {'value': conditional_escape(force_text(option_label)),
'id': escape(option_value),
'div_id': uuid.uuid4()}
diff --git a/wger/weight/helpers.py b/wger/weight/helpers.py
index b52634c4e..45cfa4d8f 100644
--- a/wger/weight/helpers.py
+++ b/wger/weight/helpers.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Affero General Public License
import logging
-import StringIO
+import six
import datetime
import decimal
import csv
@@ -36,7 +36,7 @@ def parse_weight_csv(request, cleaned_data):
dialect = 'excel'
# csv.reader expects a file-like object, so use StringIO
- parsed_csv = csv.reader(StringIO.StringIO(cleaned_data['csv_input']),
+ parsed_csv = csv.reader(six.StringIO.StringIO(cleaned_data['csv_input']),
dialect)
weight_list = []