More tweaks for python 3
This commit is contained in:
parent
135e98cde1
commit
5c1008a0df
|
@ -39,13 +39,6 @@
|
||||||
</style>
|
</style>
|
||||||
</%def>
|
</%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()">
|
<%def name="buttons()">
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
${self.leading_buttons()}
|
${self.leading_buttons()}
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
|
|
||||||
var recipient_mappings = new Map([
|
var recipient_mappings = new Map([
|
||||||
<% last = len(available_recipients) %>
|
<% 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 ''}
|
['${uuid}', ${json.dumps(entry)|n}]${',' if i < last else ''}
|
||||||
% endfor
|
% endfor
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -239,18 +239,18 @@ class EmployeesView(MasterView):
|
||||||
stores = employee.stores if employee else None
|
stores = employee.stores if employee else None
|
||||||
if not stores:
|
if not stores:
|
||||||
return ""
|
return ""
|
||||||
items = HTML.literal('')
|
items = []
|
||||||
for store in sorted(stores, key=six.text_type):
|
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)
|
return HTML.tag('ul', c=items)
|
||||||
|
|
||||||
def render_departments(self, employee, field):
|
def render_departments(self, employee, field):
|
||||||
departments = employee.departments if employee else None
|
departments = employee.departments if employee else None
|
||||||
if not departments:
|
if not departments:
|
||||||
return ""
|
return ""
|
||||||
items = HTML.literal('')
|
items = []
|
||||||
for department in sorted(departments, key=six.text_type):
|
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)
|
return HTML.tag('ul', c=items)
|
||||||
|
|
||||||
def get_version_child_classes(self):
|
def get_version_child_classes(self):
|
||||||
|
|
|
@ -144,8 +144,12 @@ class ExportMasterView(MasterView):
|
||||||
export = self.get_instance()
|
export = self.get_instance()
|
||||||
path = self.get_file_path(export)
|
path = self.get_file_path(export)
|
||||||
response = FileResponse(path, request=self.request)
|
response = FileResponse(path, request=self.request)
|
||||||
response.headers[b'Content-Length'] = six.binary_type(os.path.getsize(path))
|
if six.PY3:
|
||||||
response.headers[b'Content-Disposition'] = b'attachment; filename="{}"'.format(export.filename)
|
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
|
return response
|
||||||
|
|
||||||
def delete_instance(self, export):
|
def delete_instance(self, export):
|
||||||
|
|
|
@ -2010,12 +2010,17 @@ class MasterView(View):
|
||||||
for row in self.get_effective_row_data(sort=True):
|
for row in self.get_effective_row_data(sort=True):
|
||||||
writer.writerow(self.get_row_csv_row(row, fields))
|
writer.writerow(self.get_row_csv_row(row, fields))
|
||||||
response = self.request.response
|
response = self.request.response
|
||||||
response.body = data.getvalue()
|
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()
|
data.close()
|
||||||
response.content_length = len(response.body)
|
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
|
return response
|
||||||
|
|
||||||
def get_row_results_csv_filename(self, instance):
|
def get_row_results_csv_filename(self, instance):
|
||||||
|
|
|
@ -286,11 +286,19 @@ class MessagesView(MasterView):
|
||||||
return recipient
|
return recipient
|
||||||
|
|
||||||
def template_kwargs_create(self, **kwargs):
|
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:
|
if self.replying:
|
||||||
kwargs['original_message'] = self.get_instance()
|
kwargs['original_message'] = self.get_instance()
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
def recipient_sortkey(self, recip):
|
||||||
|
uuid, entry = recip
|
||||||
|
if isinstance(entry, dict):
|
||||||
|
return entry['name']
|
||||||
|
return entry
|
||||||
|
|
||||||
def get_available_recipients(self):
|
def get_available_recipients(self):
|
||||||
"""
|
"""
|
||||||
Return the full mapping of recipients which may be included in a
|
Return the full mapping of recipients which may be included in a
|
||||||
|
|
|
@ -28,11 +28,14 @@ from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
import six
|
||||||
import humanize
|
import humanize
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
from rattail.time import localtime
|
from rattail.time import localtime
|
||||||
|
|
||||||
|
from webhelpers2.html import tags
|
||||||
|
|
||||||
from tailbone.views import MasterView
|
from tailbone.views import MasterView
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue