-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from serge-gaia/export_data
Export data
- Loading branch information
Showing
11 changed files
with
87 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.6 on 2016-06-09 09:16 | ||
from __future__ import unicode_literals | ||
|
||
import django.contrib.postgres.fields.jsonb | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('main', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='project', | ||
old_name='data', | ||
new_name='attributes', | ||
), | ||
migrations.RemoveField( | ||
model_name='project', | ||
name='dataset', | ||
), | ||
migrations.AddField( | ||
model_name='project', | ||
name='attributes_descriptor', | ||
field=django.contrib.postgres.fields.jsonb.JSONField(null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from django.conf.urls import url | ||
from apps.publish.views import data_view | ||
from apps.publish.views import data_view, export | ||
|
||
urlpatterns = [ | ||
url(r'^$', data_view.DataView.as_view(), name='data_view'), | ||
url(r'^data/(?P<pk>\d+)/?$', data_view.JSONDataTableView.as_view(), name='data_json'), | ||
url(r'^export/(?P<pk>\d+)/?$', export.ExportDataSetView.as_view(), name='data_export') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import datetime | ||
from django.views.generic import View | ||
from django.shortcuts import get_object_or_404 | ||
|
||
from main.models import DataSet, GenericRecord, Observation, SpeciesObservation | ||
from main.utils_data_package import Exporter | ||
from main.utils_http import WorkbookResponse | ||
|
||
|
||
class ExportDataSetView(View): | ||
def get(self, request, *args, **kwargs): | ||
ds = get_object_or_404(DataSet, pk=kwargs.get('pk')) | ||
qs = [] | ||
if ds.type == DataSet.TYPE_GENERIC: | ||
qs = GenericRecord.objects.filter(dataset=ds).order_by('id') | ||
elif ds.type == DataSet.TYPE_OBSERVATION: | ||
qs = Observation.objects.filter(dataset=ds).order_by('id') | ||
elif ds.type == DataSet.TYPE_SPECIES_OBSERVATION: | ||
qs = SpeciesObservation.objects.filter(dataset=ds).order_by('id') | ||
exporter = Exporter(ds, qs) | ||
wb = exporter.to_workbook() | ||
now = datetime.datetime.now() | ||
file_name = ds.name + '_' + now.strftime('%Y-%m-%d-%H%M%S') + '.xlsx' | ||
response = WorkbookResponse(wb, file_name) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters