Browse Source

View na export škol

middleware_test
Pavel "LEdoian" Turinsky 3 years ago
parent
commit
0d58c3daad
  1. 3
      seminar/urls.py
  2. 2
      seminar/views/__init__.py
  3. 15
      seminar/views/exports.py

3
seminar/urls.py

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

2
seminar/views/__init__.py

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

@ -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)
Loading…
Cancel
Save