Skip to content

Commit

Permalink
Merge branch 'issue-717'
Browse files Browse the repository at this point in the history
  • Loading branch information
witekdev committed Dec 21, 2022
2 parents 020c89a + 07f3c19 commit e486694
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions jazkarta/shop/browser/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import csv
import datetime
from six import StringIO
from six import PY3
from DateTime import DateTime
try:
from cgi import escape
Expand Down Expand Up @@ -133,10 +134,11 @@ def __getitem__(self, index):
# check if shipping address has been entered
if data['ship_to'].replace(',','').replace(' ','') == '':
data['ship_to'] = u''
# CSV output needs to be encoded
data['items'] = data['items'].encode('utf-8')
data['ship_to'] = data['ship_to'].encode('utf-8')
data['userid'] = data['userid'].encode('utf-8')
# CSV output needs to be encoded in PY2
# the encoding in PY3 is done on the whole stream later
data['items'] = data['items'] if PY3 else data['items'].encode('utf-8')
data['ship_to'] = data['ship_to'] if PY3 else data['ship_to'].encode('utf-8')
data['userid'] = data['userid'] if PY3 else data['userid'].encode('utf-8')
else:
data['ship_to'] = u'<p>{} {}</p><p>{}</p><p>{}, {} {}</p><p>{}</p>'.format(
escape(address.get('first_name', '')),
Expand Down Expand Up @@ -245,7 +247,7 @@ def __call__(self):
)
orders_csv = StringIO()

if (order_sequence) > 0:
if len(order_sequence) > 0:
writer = csv.DictWriter(
orders_csv,
fieldnames=['userid', 'date', 'items',
Expand Down Expand Up @@ -303,7 +305,7 @@ def __call__(self):
DateTime.rfc822(DateTime()))
self.request.response.setHeader("Cache-Control", "no-store")
self.request.response.setHeader("Pragma", "no-cache")
self.request.response.write(csv_content)
self.request.response.write(csv_content.encode() if PY3 else csv_content)

return csv_content

Expand Down

0 comments on commit e486694

Please sign in to comment.