View na export škol

This commit is contained in:
Pavel "LEdoian" Turinsky 2021-09-18 21:51:47 +02:00
parent 75598c59b2
commit 0d58c3daad
3 changed files with 20 additions and 0 deletions

View file

@ -158,6 +158,9 @@ urlpatterns = [
path('api/autocomplete/resitel/', org_required(views.ResitelAutocomplete.as_view()), name='autocomplete_resitel'), 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'), 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('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'), path('resitel/nahraj_reseni', resitel_required(views.NahrajReseniView.as_view()), name='seminar_nahraj_reseni'),

View file

@ -3,5 +3,7 @@ from .autocomplete import *
from .views_rest import * from .views_rest import *
from .odevzdavatko import * from .odevzdavatko import *
from .exports import *
# Dočsasné views # Dočsasné views
from .docasne import * from .docasne import *

15
seminar/views/exports.py Normal file
View file

@ -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)