Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add explicit UTF8 handling

Roland Geider4d424e87b365
diff --git a/wger/gym/views/export.py b/wger/gym/views/export.py
index c3ed27aeb..6c6413f73 100644
--- a/wger/gym/views/export.py
+++ b/wger/gym/views/export.py
@@ -13,6 +13,8 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
+
+import six
import csv
import datetime
import logging
@@ -48,32 +50,35 @@ def users(request, gym_pk):
# Create CSV 'file'
response = HttpResponse(content_type='text/csv')
writer = csv.writer(response, delimiter='\t', quoting=csv.QUOTE_ALL)
+
+ # Python3: the .encode() is only needed for python 2.7. Should this requirement
+ # be dropped once, they can be removed.
writer.writerow([_('Nr.'),
- _('Gym'),
- _('Username'),
- _('Email'),
- _('First name'),
- _('Last name'),
- _('Gender'),
- _('Age'),
- _('ZIP code'),
- _('City'),
- _('Street'),
- _('Phone')])
+ _('Gym').encode('utf8'),
+ _('Username').encode('utf8'),
+ _('Email').encode('utf8'),
+ _('First name').encode('utf8'),
+ _('Last name').encode('utf8'),
+ _('Gender').encode('utf8'),
+ _('Age').encode('utf8'),
+ _('ZIP code').encode('utf8'),
+ _('City').encode('utf8'),
+ _('Street').encode('utf8'),
+ _('Phone').encode('utf8')])
for user in Gym.objects.get_members(gym_pk):
address = user.userprofile.address
writer.writerow([user.id,
- gym.name,
+ gym.name.encode('utf8'),
user.username,
user.email,
- user.first_name,
- user.last_name,
- user.userprofile.get_gender_display(),
+ user.first_name.encode('utf8'),
+ user.last_name.encode('utf8'),
+ user.userprofile.get_gender_display().encode('utf8'),
user.userprofile.age,
address['zip_code'],
- address['city'],
- address['street'],
- address['phone']
+ address['city'].encode('utf8'),
+ address['street'].encode('utf8'),
+ address['phone'].encode('utf8')
])
# Send the data to the browser