Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions be/ldapadmin/import_export.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import xlwt
import xlsxwriter
import logging
import urllib
from StringIO import StringIO
from io import BytesIO

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -52,29 +53,26 @@ def excel_headers_to_object(properties):


def generate_excel(header, rows):
style = xlwt.XFStyle()
wrapstyle = xlwt.XFStyle()
wrapstyle.alignment.wrap = 1
normalfont = xlwt.Font()
headerfont = xlwt.Font()
headerfont.bold = True
style.font = headerfont
output = BytesIO()
wb = xlsxwriter.Workbook(output, {'in_memory': True})
ws = wb.add_worksheet('Sheet 1')
ws.set_column('A:G', 30)
ws.set_column(1, 1, 20)
ws.set_column(2, 2, 50)
ws.set_column(3, 4, 20)
style = wb.add_format()
bold = wb.add_format({'bold': True})
wrapstyle = wb.add_format({'text_wrap': True})

wb = xlwt.Workbook(encoding='utf-8')
ws = wb.add_sheet('Sheet 1')
row = 0
for col in range(0, len(header)):
ws.col(col).width = 256 * 50
for col in range(0, len(header)):
ws.row(row).set_cell_text(col, header[col], style)
style.font = normalfont
ws.write(row, col, header[col].decode('utf-8'), bold)
for item in rows:
row += 1
for col in range(0, len(item)):
if '\n' in item[col]:
ws.row(row).set_cell_text(col, item[col], wrapstyle)
ws.write(row, col, item[col].decode('utf-8'), wrapstyle)
else:
ws.row(row).set_cell_text(col, item[col], style)
output = StringIO()
wb.save(output)
ws.write(row, col, item[col].decode('utf-8'), style)
wb.close()
return output.getvalue()
8 changes: 4 additions & 4 deletions be/ldapadmin/roles_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,16 +998,16 @@ def search_users(self, REQUEST):
security.declareProtected(view, 'export_members')

def export_members(self, REQUEST):
""" Exports xls of members in role given by role_id in QUERY_STRING """
""" Exports xlsx of members in role given by role_id in QUERY_STRING """
role_id = REQUEST.form.get('role_id', None)
subroles = REQUEST.form.get('subroles', None) in [True, 'true', 'True']
if not REQUEST.AUTHENTICATED_USER:
raise Unauthorized("You are not allowed to manage members in %s" %
role_id)
if subroles:
filename = "%s_all_members.xls" % str(role_id)
filename = "%s_all_members.xlsx" % str(role_id)
else:
filename = "%s_members.xls" % str(role_id)
filename = "%s_members.xlsx" % str(role_id)
REQUEST.RESPONSE.setHeader('Content-Type', 'application/vnd.ms-excel')
REQUEST.RESPONSE.setHeader('Content-Disposition',
"attachment;filename=%s" % filename)
Expand Down Expand Up @@ -1803,7 +1803,7 @@ def __call__(self):
RESPONSE.setHeader('Pragma', 'public')
RESPONSE.setHeader('Cache-Control', 'max-age=0')
RESPONSE.addHeader("content-disposition",
"attachment; filename=roles_export-%s.xls" %
"attachment; filename=roles_export-%s.xlsx" %
this_role_id)

return out
Expand Down