import json from django.shortcuts import render from uuid import uuid1 from .models import * from django.contrib import auth from django.http import HttpResponse, Http404, JsonResponse from django.template import loader, RequestContext from django.contrib.auth.decorators import login_required from BaseModels.mailSender import techSendMail from django.utils.translation import gettext as _ from datetime import datetime from django.template.loader import render_to_string from django.urls import reverse from .funcs import * def get_content_for_section_ajax(request): if request.method != 'POST': raise Http404 try: data = request.POST.dict() if not data and request.body: data = json.loads(request.body) if not 'section_url' in data or not data['section_url']: msg = _("Не найден section_url в data") err_Dict = { 'error': msg } return JsonResponse(err_Dict, status=400) section = Section.objects.get(url=data['section_url']) html = render_to_string('blocks/b_search_routes.html', routes_Dict, request=request) res_Dict = { 'html': html, 'last_block': routes_Dict['last_block'] # 'form': RouteForm(initial=data) } return JsonResponse(res_Dict) except Exception as e: errors_Dict = { 'errors': { 'all__': f'ошибка в запросе = {str(e)}' } } return JsonResponse(errors_Dict, status=400)