Add corporation export
This commit is contained in:
parent
32398be8c3
commit
6ad597b392
3 changed files with 25 additions and 0 deletions
|
|
@ -24,6 +24,8 @@ urlpatterns = [
|
|||
|
||||
path('institutions/', views.CorporationListView.as_view(), name='corporations'),
|
||||
path('institutions/<int:pk>/', views.CorporationView.as_view(), name='corporation'),
|
||||
path('institutions/export/', views.export.institutions_export, name='corporations-export'),
|
||||
|
||||
path('classes/', views.KlassListView.as_view(), name='classes'),
|
||||
path('classes/<int:pk>/', views.KlassView.as_view(), name='class'),
|
||||
path('classes/<int:pk>/import_reports/', views.ImportReportsView.as_view(),
|
||||
|
|
|
|||
|
|
@ -456,3 +456,21 @@ def export_qualification_ede(request):
|
|||
export.write_line(values)
|
||||
|
||||
return export.get_http_response('Export_qualif_EDE')
|
||||
|
||||
|
||||
def institutions_export(request):
|
||||
def format_value(val):
|
||||
return '' if val is None else str(val)
|
||||
|
||||
fields = [
|
||||
(f.verbose_name, f.name)
|
||||
for f in Corporation._meta.get_fields() if hasattr(f, 'verbose_name') and f.name not in ('archived',)
|
||||
]
|
||||
headers = [f[0] for f in fields]
|
||||
|
||||
export = OpenXMLExport('Institutions')
|
||||
export.write_line(headers, bold=True)
|
||||
for corp in Corporation.objects.filter(archived=False).order_by('name'):
|
||||
values = [format_value(getattr(corp, f[1])) for f in fields]
|
||||
export.write_line(values)
|
||||
return export.get_http_response('Institutions')
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
{% extends "admin/base_site.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Liste des institutions</h2>
|
||||
|
||||
<div style="float:right;">
|
||||
<a href="{% url 'corporations-export' %}"><img src="{% static 'img/xls.png' %}" title="Exportation Excel" width="24"></a>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
{% for corp in object_list %}
|
||||
<tr class="{% cycle 'row1' 'row2' %}">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue