0001-views-move-ods-export-next-to-other-visualisation-ac.patch
bijoe/static/css/bijoe.css | ||
---|---|---|
72 | 72 |
justify-content: space-around; |
73 | 73 |
} |
74 | 74 | |
75 |
/* put ODS export export slightly on the right of the repesentation header */ |
|
76 |
#ods { |
|
77 |
margin: 1ex; |
|
78 |
top: -2ex; |
|
79 |
} |
|
80 | ||
81 | 75 |
/* Main content */ |
82 | 76 | |
83 | 77 |
/* size main content to let some place on the right for the form */ |
bijoe/templates/bijoe/cube.html | ||
---|---|---|
26 | 26 |
{% block content %} |
27 | 27 |
<form class="cube-form" method="post" action="."> |
28 | 28 |
{% csrf_token %} |
29 |
{% if visualization %} |
|
30 |
<input type="submit" value="ODS" name="ods" id="ods"/> |
|
31 |
{% endif %} |
|
32 | 29 |
<h3>Représentation</h3> |
33 | 30 |
{% include "bijoe/field.html" with field=form.representation %} |
34 | 31 |
<h3>Répétition</h3> |
bijoe/templates/bijoe/visualization.html | ||
---|---|---|
15 | 15 |
{% block actions %} |
16 | 16 |
<a rel="popup" class="button" href="{% url "rename-visualization" pk=object.pk %}">{% trans "Rename" %}</a> |
17 | 17 |
<a rel="popup" class="button" href="{% url "delete-visualization" pk=object.pk %}">{% trans "Delete" %}</a> |
18 |
<a rel="popup" class="button" href="{% url "visualization-ods" pk=object.pk %}">{% trans "Export as ODS" %}</a> |
|
18 | 19 |
<a href="{{ iframe_url }}" class="button">{% trans "URL for IFRAME" %}</a> |
19 | 20 |
{% endblock %} |
20 | 21 |
bijoe/visualization/urls.py | ||
---|---|---|
33 | 33 |
url(r'(?P<pk>\d+)/json/$', views.visualization_json, name='visualization-json'), |
34 | 34 |
url(r'(?P<pk>\d+)/geojson/$', views.visualization_geojson, name='visualization-geojson'), |
35 | 35 |
url(r'(?P<pk>\d+)/iframe/$', views.visualization_iframe, name='visualization-iframe'), |
36 |
url(r'(?P<pk>\d+)/ods/$', views.visualization_ods, name='visualization-ods'), |
|
36 | 37 |
url(r'(?P<pk>\d+)/rename/$', views.rename_visualization, name='rename-visualization'), |
37 | 38 |
url(r'(?P<pk>\d+)/delete/$', views.delete_visualization, name='delete-visualization'), |
38 | 39 |
] |
bijoe/visualization/views.py | ||
---|---|---|
18 | 18 |
import json |
19 | 19 | |
20 | 20 |
from django.conf import settings |
21 |
from django.utils.text import slugify |
|
21 | 22 |
from django.views.generic.edit import CreateView, DeleteView, UpdateView |
22 | 23 |
from django.views.generic.list import MultipleObjectMixin |
23 | 24 |
from django.views.generic import DetailView, ListView, View, TemplateView |
... | ... | |
81 | 82 |
return super(CubeMixin, self).dispatch(request, *args, **kwargs) |
82 | 83 | |
83 | 84 | |
84 |
class ODSMixin(object): |
|
85 |
def ods(self, visualization): |
|
86 |
if not self.visualization: |
|
87 |
raise Http404 |
|
88 |
response = HttpResponse(content_type='application/vnd.oasis.opendocument.spreadsheet') |
|
89 |
response['Content-Disposition'] = 'attachment; filename=%s.ods' % self.cube.name |
|
90 |
workbook = visualization.ods() |
|
91 |
workbook.save(response) |
|
92 |
return response |
|
93 | ||
94 | ||
95 |
class CubeView(views.AuthorizationMixin, CubeDisplayMixin, ODSMixin, CubeMixin, TemplateView): |
|
85 |
class CubeView(views.AuthorizationMixin, CubeDisplayMixin, CubeMixin, TemplateView): |
|
96 | 86 |
template_name = 'bijoe/cube.html' |
97 | 87 | |
98 | 88 |
def post(self, request, *args, **kwargs): |
... | ... | |
124 | 114 |
return super(CreateVisualizationView, self).form_valid(form) |
125 | 115 | |
126 | 116 | |
127 |
class VisualizationView(views.AuthorizationMixin, ODSMixin, CubeDisplayMixin, |
|
128 |
DetailView): |
|
117 |
class VisualizationView(views.AuthorizationMixin, CubeDisplayMixin, DetailView): |
|
129 | 118 |
model = models.Visualization |
130 | 119 |
template_name = 'bijoe/visualization.html' |
131 | 120 | |
... | ... | |
238 | 227 |
template_name = 'bijoe/cube_raw.html' |
239 | 228 | |
240 | 229 | |
230 |
class VisualizationODSView(DetailView): |
|
231 |
model = models.Visualization |
|
232 | ||
233 |
def get(self, request, *args, **kwargs): |
|
234 |
instance = self.get_object() |
|
235 |
visualization = Visualization.from_json(instance.parameters, request=request) |
|
236 |
response = HttpResponse(content_type='application/vnd.oasis.opendocument.spreadsheet') |
|
237 |
response['Content-Disposition'] = 'attachment; filename=%s.ods' % slugify(instance.name) |
|
238 |
workbook = visualization.ods() |
|
239 |
workbook.save(response) |
|
240 |
return response |
|
241 | ||
242 | ||
241 | 243 |
class VisualizationGeoJSONView(generics.GenericAPIView): |
242 | 244 |
permission_classes = () |
243 | 245 |
queryset = models.Visualization.objects.all() |
... | ... | |
288 | 290 |
visualization_iframe = xframe_options_exempt(VisualizationIframeView.as_view()) |
289 | 291 |
visualization_geojson = VisualizationGeoJSONView.as_view() |
290 | 292 |
visualization_json = VisualizationJSONView.as_view() |
293 |
visualization_ods = VisualizationODSView.as_view() |
|
291 | 294 | |
292 | 295 |
cube_iframe.mellon_no_passive = True |
293 | 296 |
visualization_iframe.mellon_no_passive = True |
294 |
- |