From 0d58c3daad00f1ae67b73782daaeaf2b4502d01c Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sat, 18 Sep 2021 21:51:47 +0200 Subject: [PATCH] =?UTF-8?q?View=20na=20export=20=C5=A1kol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/urls.py | 3 +++ seminar/views/__init__.py | 2 ++ seminar/views/exports.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 seminar/views/exports.py diff --git a/seminar/urls.py b/seminar/urls.py index ddd46d00..141453c7 100644 --- a/seminar/urls.py +++ b/seminar/urls.py @@ -158,6 +158,9 @@ urlpatterns = [ path('api/autocomplete/resitel/', org_required(views.ResitelAutocomplete.as_view()), name='autocomplete_resitel'), path('api/autocomplete/problem/odevzdatelny',views.OdevzdatelnyProblemAutocomplete.as_view(), name='autocomplete_problem_odevzdatelny'), + # Export škol + path('api/export/skoly/', views.exportSkolView, name='export_skoly'), + path('org/add_solution', org_required(views.AddSolutionView.as_view()), name='seminar_vloz_reseni'), path('resitel/nahraj_reseni', resitel_required(views.NahrajReseniView.as_view()), name='seminar_nahraj_reseni'), diff --git a/seminar/views/__init__.py b/seminar/views/__init__.py index 163f2535..f84d99d7 100644 --- a/seminar/views/__init__.py +++ b/seminar/views/__init__.py @@ -3,5 +3,7 @@ from .autocomplete import * from .views_rest import * from .odevzdavatko import * +from .exports import * + # Dočsasné views from .docasne import * diff --git a/seminar/views/exports.py b/seminar/views/exports.py new file mode 100644 index 00000000..6df7d32b --- /dev/null +++ b/seminar/views/exports.py @@ -0,0 +1,15 @@ +import seminar.models as m +from django.core import serializers as ser +from django.http import HttpResponse +def exportSkolView(request): + # Některé fieldy nechceme: Kontaktní osoby, AESOP ID, org poznámky. + fields = ('id', 'izo', 'nazev', 'kratky_nazev', 'ulice', 'mesto', 'psc', 'stat', 'je_zs', 'je_ss') + # TODO: Použít JSONL, aby protistrana mohla číst po řádkách a nesežralo to tunu paměti úplně hned + skoly_json = ser.serialize("json", m.Skola.objects.all(), fields=fields) + response = HttpResponse( + content = skoly_json, + content_type = 'text/json', + reason = 'Here you go', # :-) + ) + return(response) +