Skip to content

Commit

Permalink
Merge branch 'canada-v2.9' into staging-v2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
JVickery-TBS committed Aug 28, 2023
2 parents 6edf8b0 + bb272fb commit 9b81c01
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions ckanext/canada/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from dateutil.tz import tzutc
from socket import error as socket_error
from logging import getLogger
from ckanext.datastore.writer import csv_writer
import unicodecsv
from codecs import BOM_UTF8
from six import string_types, PY2

from ckan.plugins.toolkit import (
Expand Down Expand Up @@ -1032,7 +1033,6 @@ def notify_ckan_user_create(email, fullname, username, phoneno, dept):

@canada_views.route('/organization/member_dump/<id>', methods=['GET'])
def organization_member_dump(id):
writer_factory = csv_writer
records_format = u'csv'

org_dict = model.Group.get(id)
Expand Down Expand Up @@ -1060,29 +1060,21 @@ def organization_member_dump(id):
except NotFound:
abort(404, _('Members not found'))

results = ''
results = [[_('Username'), _('Email'), _('Name'), _('Role')]]
for uid, _user, role in members:
user_obj = model.User.get(uid)
if not user_obj:
continue
results += '{name},{email},{fullname},{role}\n'.format(
name=user_obj.name,
email=user_obj.email,
fullname=user_obj.fullname if user_obj.fullname else _('N/A'),
role=role)

fields = [
{'id': _('Username')},
{'id': _('Email')},
{'id': _('Name')},
{'id': _('Role')}]
results.append([
user_obj.name,
user_obj.email,
user_obj.fullname if user_obj.fullname else _('N/A'),
role,
])

output_stream = StringIO()
def start_writer(fields):
return writer_factory(output_stream, fields, bom=True)

with start_writer(fields) as wr:
wr.write_records(results)
output_stream.write(BOM_UTF8)
unicodecsv.writer(output_stream, encoding=u'utf-8').writerows(results)

file_name = u'{org_id}-{members}'.format(
org_id=org_dict.name,
Expand Down

0 comments on commit 9b81c01

Please sign in to comment.