Close #116 - adding in a view to export user data as a CSV #119

Merged
merged 1 commit into from Feb 18, 2013

Conversation

Projects
None yet
3 participants
Member

rossbruniges commented Feb 18, 2013

No description provided.

+ return action_unavailable_response(request, case='not_staff')
+
+ response = HttpResponse(content_type='text/csv')
+ response['Content-Disposition'] = 'attachment; filename="gameon_entries.csv"'
@alfredo

alfredo Feb 18, 2013

Member

Maybe add a date and time to the file name to be able to differentiate between different exports?

Although this may not be that important.

Member

alfredo commented Feb 18, 2013

+1 looks good to me!

+ 'SUBMIT TO MARKETPLACE?'
+ ])
+ for e in entry_set:
+ writer.writerow([
@alfredo

alfredo Feb 18, 2013

Member

As a word of advice, the writer doesn't support unicode by default. If unicode characters are expected on the title an different writer may need to be considered.

@rossbruniges

rossbruniges Feb 18, 2013

Member

If the worst we get is a dodgy looking char here and there then I think that's fine. Is that what will happen or will the export fail?

@alfredo

alfredo Feb 18, 2013

Member

It would rise a 500 with a UnicodeEncoding error.

@andrewhayward

andrewhayward Feb 18, 2013

Member

How concerned are you with data integrity? If you don't mind losing the odd non-translatable character, you can encode it yourself before hand.

e.title.encode('ascii', 'ignore')

You can encode('ascii', 'replace') if you'd rather see ?s than nothing at all.

For extra Brownie points, you could normalise it before hand, which would go some way to dealing with characters that are ASCII-like (such as ä, é, etc).

import unicodedata
unicodedata.normalize('NFKD', e.title).encode('ascii', 'ignore')
@rossbruniges

rossbruniges Feb 18, 2013

Member

@andrewhayward I've got a fix ready to land - just prepping the pull request, thanks for piling the feedback in!

Member

rossbruniges commented Feb 18, 2013

Updated with a fix for potential unicode errors on export

+ return self.reader.next().encode("utf-8")
+
+
+class UnicodeWriter:
@alfredo

alfredo Feb 18, 2013

Member

Lovely!

Member

alfredo commented Feb 18, 2013

Looks awesome +1

rossbruniges added a commit that referenced this pull request Feb 18, 2013

Merge pull request #119 from rossbruniges/data-export
Close #116 - adding in a view to export user data as a CSV

@rossbruniges rossbruniges merged commit c6170bc into mozilla:master Feb 18, 2013

@rossbruniges rossbruniges deleted the rossbruniges:data-export branch Feb 18, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment