Export seznamu přednášek
This commit is contained in:
parent
934a29a336
commit
3a8d5b2207
2 changed files with 37 additions and 0 deletions
|
@ -22,4 +22,9 @@ urlpatterns = [
|
||||||
org_required(views.SeznamListView.as_view()),
|
org_required(views.SeznamListView.as_view()),
|
||||||
name='seznam-list'
|
name='seznam-list'
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
'prednasky/seznam_export/<int:seznam>/',
|
||||||
|
org_required(views.exportSeznamuPrednasekNeHodnoceni),
|
||||||
|
name='seznam_export_csv'
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -114,4 +114,36 @@ def SeznamExportView(request, seznam):
|
||||||
content_type="text/plain"
|
content_type="text/plain"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def exportSeznamuPrednasekNeHodnoceni(req, seznam):
|
||||||
|
# UGLY CODE. Jen byla potřeba pro garanta přednášek tabulka, tak vznikla :-P
|
||||||
|
|
||||||
|
seznam = get_object_or_404(Seznam, id=seznam)
|
||||||
|
|
||||||
|
from django.http import HttpResponse
|
||||||
|
|
||||||
|
# Kód jsem zkopíroval přímo z tutoriálu
|
||||||
|
# https://docs.djangoproject.com/en/4.0/howto/outputting-csv/
|
||||||
|
# Jo, je to špatná verze djanga. whatever.
|
||||||
|
response = HttpResponse(
|
||||||
|
content_type='text/csv',
|
||||||
|
headers={'Content-Disposition': 'attachment; filename="seznam.csv"'},
|
||||||
|
)
|
||||||
|
|
||||||
|
writer = csv.writer(response)
|
||||||
|
|
||||||
|
attrs = (
|
||||||
|
'id',
|
||||||
|
'org',
|
||||||
|
'nazev',
|
||||||
|
'anotace',
|
||||||
|
'klicova',
|
||||||
|
'obor',
|
||||||
|
'obtiznost',
|
||||||
|
'popis',
|
||||||
|
)
|
||||||
|
for predn in Prednaska.objects.filter(seznamy=seznam):
|
||||||
|
row = [getattr(predn, attr) for attr in attrs]
|
||||||
|
writer.writerow(row)
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue