Files
tripwithbonus/ArticlesApp/js_views.py

61 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 .forms import *
from .funcs import *
def get_articles_block_ajax(request):
if request.method != 'POST':
raise Http404
from GeneralApp.funcs import get_and_set_lang
lang = get_and_set_lang(request)
try:
data = request.POST.dict()
if not data and request.body:
data = json.loads(request.body)
art_kwargs = {}
Dict = get_articles(art_kwargs=art_kwargs, request_Data=data)
if 'errors' in Dict:
return JsonResponse(Dict, status=400)
html = render_to_string('blocks/articles/b_news_elements.html', Dict, request=request)
res_Dict = {
'html': html,
'last_block': Dict['last_block'],
'next_page_els_count': Dict['next_page_els_count'],
# 'form': RouteForm(initial=data)
}
from GeneralApp.funcs import get_add_to_ajax_response_Dict
res_Dict.update(get_add_to_ajax_response_Dict(request.user))
return JsonResponse(res_Dict)
except Exception as e:
errors_Dict = {
'errors': {
'all__': f'{_("ошибка в запросе")} = {str(e)}'
}
}
return JsonResponse(errors_Dict, status=400)