You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.7 KiB
57 lines
1.7 KiB
from django.shortcuts import render
|
|
from django.views.generic import ListView, DetailView
|
|
from django.http import JsonResponse
|
|
from django.views.generic import TemplateView
|
|
from django.http import HttpResponse
|
|
from .models import Specialization
|
|
|
|
class SpecListView(ListView):
|
|
model = Specialization
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(SpecListView, self).get_context_data(**kwargs)
|
|
root = Specialization.objects.get(pk=1)
|
|
context['root'] = root
|
|
context['children'] = root.get_children()
|
|
context['roots'] = Specialization.objects.root_nodes()
|
|
return context
|
|
|
|
|
|
def test_page(request):
|
|
if request.method == 'POST':
|
|
if request.is_ajax():
|
|
spec_id = request.POST.get('spec_id')
|
|
spec = Specialization.objects.get(pk=spec_id)
|
|
children = spec.get_children()
|
|
return JsonResponse({"hello": 'yes'})
|
|
else:
|
|
return JsonResponse({"hello":"python"})
|
|
|
|
|
|
def test_spec(request):
|
|
spec = Specialization.objects.get(pk=2)
|
|
# children = spec.get_children()
|
|
return HttpResponse(request, {'mm':'hello'})
|
|
|
|
class SpecChildrenDetailView(DetailView):
|
|
model = Specialization
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
return context
|
|
|
|
|
|
class JSONResponseMixin(object):
|
|
def render_to_json_response(self, context, **response_kwargs):
|
|
return JsonResponse(
|
|
self.get_data(context),
|
|
**response_kwargs
|
|
)
|
|
|
|
def get_data(self, context):
|
|
return context
|
|
|
|
|
|
class JSONView(JSONResponseMixin, TemplateView):
|
|
def render_to_response(self, context, **response_kwargs):
|
|
return self.render_to_json_response(context, **response_kwargs)
|
|
|