More tweaks for python 3

This commit is contained in:
Lance Edgar 2018-02-15 12:48:14 -06:00
parent 135e98cde1
commit 5c1008a0df
7 changed files with 33 additions and 19 deletions

View file

@ -39,13 +39,6 @@
</style>
</%def>
<%def name="context_menu_items()">
${parent.context_menu_items()}
% if master.cloneable and request.has_perm('{}.clone'.format(permission_prefix)):
<li>${h.link_to("Clone as new batch", url('{}.clone'.format(route_prefix), uuid=batch.uuid))}</li>
% endif
</%def>
<%def name="buttons()">
<div class="buttons">
${self.leading_buttons()}

View file

@ -8,7 +8,8 @@
var recipient_mappings = new Map([
<% last = len(available_recipients) %>
% for i, (uuid, entry) in enumerate(sorted(available_recipients.items(), key=lambda r: r[1]), 1):
% for i, recip in enumerate(available_recipients, 1):
<% uuid, entry = recip %>
['${uuid}', ${json.dumps(entry)|n}]${',' if i < last else ''}
% endfor
]);

View file

@ -239,18 +239,18 @@ class EmployeesView(MasterView):
stores = employee.stores if employee else None
if not stores:
return ""
items = HTML.literal('')
items = []
for store in sorted(stores, key=six.text_type):
items += HTML.tag('li', c=six.text_type(store))
items.append(HTML.tag('li', c=six.text_type(store)))
return HTML.tag('ul', c=items)
def render_departments(self, employee, field):
departments = employee.departments if employee else None
if not departments:
return ""
items = HTML.literal('')
items = []
for department in sorted(departments, key=six.text_type):
items += HTML.tag('li', c=six.text_type(department))
items.append(HTML.tag('li', c=six.text_type(department)))
return HTML.tag('ul', c=items)
def get_version_child_classes(self):

View file

@ -144,6 +144,10 @@ class ExportMasterView(MasterView):
export = self.get_instance()
path = self.get_file_path(export)
response = FileResponse(path, request=self.request)
if six.PY3:
response.headers['Content-Length'] = str(os.path.getsize(path))
response.headers['Content-Disposition'] = 'attachment; filename="{}"'.format(export.filename)
else:
response.headers[b'Content-Length'] = six.binary_type(os.path.getsize(path))
response.headers[b'Content-Disposition'] = b'attachment; filename="{}"'.format(export.filename)
return response

View file

@ -2010,12 +2010,17 @@ class MasterView(View):
for row in self.get_effective_row_data(sort=True):
writer.writerow(self.get_row_csv_row(row, fields))
response = self.request.response
filename = self.get_row_results_csv_filename(obj)
if six.PY3:
response.text = data.getvalue()
response.content_type = 'text/csv'
response.content_disposition = 'attachment; filename={}'.format(filename)
else:
response.body = data.getvalue()
response.content_type = b'text/csv'
response.content_disposition = b'attachment; filename={}'.format(filename)
data.close()
response.content_length = len(response.body)
response.content_type = b'text/csv'
filename = self.get_row_results_csv_filename(obj)
response.content_disposition = b'attachment; filename={}'.format(filename)
return response
def get_row_results_csv_filename(self, instance):

View file

@ -286,11 +286,19 @@ class MessagesView(MasterView):
return recipient
def template_kwargs_create(self, **kwargs):
kwargs['available_recipients'] = self.get_available_recipients()
recips = list(self.get_available_recipients().items())
recips.sort(key=self.recipient_sortkey)
kwargs['available_recipients'] = recips
if self.replying:
kwargs['original_message'] = self.get_instance()
return kwargs
def recipient_sortkey(self, recip):
uuid, entry = recip
if isinstance(entry, dict):
return entry['name']
return entry
def get_available_recipients(self):
"""
Return the full mapping of recipients which may be included in a

View file

@ -28,11 +28,14 @@ from __future__ import unicode_literals, absolute_import
import datetime
import six
import humanize
from rattail.db import model
from rattail.time import localtime
from webhelpers2.html import tags
from tailbone.views import MasterView