Closed Mike-Heneghan closed 5 years ago
Django has a csv library for streaming csv from a view https://docs.djangoproject.com/en/2.1/howto/outputting-csv/.
Interesting although I don't think the is the way we want to implement this function.
Using an import/export library and adding it to the admin: https://www.youtube.com/watch?v=vYIuvSwLsMc
Information on CSV export: https://djangotricks.blogspot.com/2013/12/how-to-export-data-as-excel.html
Maybe best approach is to try exporting one model as a csv and work from there.
Further information form a blog post about generating csv files from the backend: http://blog.aeguana.com/2015/12/12/csv-export-data-for-django-model/
Open Referral docs https://openreferral.readthedocs.io/en/latest/
Could create a new term to determine how a variable is handled. Could write methods which generate a permalink for the model record.
To Do List:
""
export_csv
command. (wrote checks rather than tests)To do list:
For making the results of the CSV more accurate we could use .distinct(field to compare against)
for the organisations. Although how do we ensure the unique organisation returned is the one we want? We could potentially order_by
something like last_edited
or only include organisations which have greater than 0 services?
To resolve the issue with dummy data being committed created a new branch and copied the code across.
Merged into master
CSV
First as a management command (like digest emails).
We want the following to be filterable by published orgs/services/whatever, for public consumption.
Services
id, name, description, url, phone, email, aliss_url, permalink, last_edited, organisation_id, organisation_name, organisation_permalink, categories, service_areas, location_ids
Locations
id, formatted_address, name, locality, region, postal_code, country, latitude, longitude, organisation_name, organisation_id, organisation_permalink
Services at location
service_id, location_id, service_name, service_permalink, formatted_address, organisation_id
name this services_at_location.csv
Organisations
Default queryset should be:
Service.objects.values('organisation_id').distinct()
, also with option to include unpublished.id, name, description, aliss_url, permalink, url, twitter, facebook, phone, email, last_edited, service_names, service_ids, service_permalinks
Notes
String wrap, and comma separate categories and service areas using slugs. For locations comma separate the ids and/or permalinks.
Be careful to escape quotation marks in descriptions. Try testing against quotation mark and comma characters