62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
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 'screen_width' in data and data['screen_width']:
|
||
request.session['screen_width'] = data['screen_width']
|
||
|
||
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'])
|
||
|
||
from .funcs import get_sections
|
||
|
||
Dict = {
|
||
'cur_section': section,
|
||
'sections': get_sections(),
|
||
}
|
||
|
||
html = render_to_string('pages/content/c_projectiing_section.html', Dict, request=request)
|
||
|
||
res_Dict = {
|
||
'html': html,
|
||
}
|
||
|
||
return JsonResponse(res_Dict)
|
||
|
||
except Exception as e:
|
||
msg = f' get_content_for_section_ajax ошибка в запросе = {str(e)}'
|
||
errors_Dict = {
|
||
'errors': msg
|
||
}
|
||
return JsonResponse(errors_Dict, status=400)
|