121 lines
3.1 KiB
Python
121 lines
3.1 KiB
Python
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 get_routes_for_user
|
|
|
|
|
|
def new_route_view_ajax(request):
|
|
if request.method != 'POST':
|
|
raise Http404
|
|
|
|
form = CreateRouteForm()
|
|
Dict = {
|
|
'form': form
|
|
}
|
|
try:
|
|
|
|
data = request.POST
|
|
|
|
form = CreateRouteForm(data)
|
|
|
|
if not form.is_valid():
|
|
pass
|
|
|
|
if form.cleaned_data['type_transport'] == 'avia':
|
|
pass
|
|
|
|
# print(form)
|
|
except Exception as e:
|
|
form.errors.apend({'__all__': f'Ошибка: {str(e)}'})
|
|
|
|
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
|
return JsonResponse({'html': html}, status=200)
|
|
|
|
|
|
def get_routes_ajax(request):
|
|
|
|
|
|
if request.method != 'POST':
|
|
raise Http404
|
|
|
|
try:
|
|
routes_Dict = get_routes_for_user(request.user)
|
|
if 'errors' in routes_Dict:
|
|
return JsonResponse(routes_Dict, status=400)
|
|
|
|
|
|
html = render_to_string('blocks/profile/b_my_routes.html', routes_Dict, request=request)
|
|
|
|
res_Dict = {
|
|
'html': html
|
|
}
|
|
|
|
return JsonResponse(res_Dict)
|
|
|
|
except Exception as e:
|
|
|
|
errors_Dict = {
|
|
'errors': {
|
|
'all__': f'ошибка в запросе = {str(e)}'
|
|
}
|
|
}
|
|
return JsonResponse(errors_Dict, status=400)
|
|
|
|
|
|
|
|
def create_route_ajax(request):
|
|
|
|
if request.method != 'POST':
|
|
raise Http404
|
|
|
|
try:
|
|
|
|
data = request.POST
|
|
|
|
form = CreateRouteForm(data)
|
|
if not form.is_valid():
|
|
Dict = {'form': form}
|
|
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
|
return JsonResponse({'html': html}, status=400)
|
|
|
|
obj = form.save(commit=False)
|
|
obj.owner = request.user
|
|
obj.save()
|
|
|
|
routes_Dict = get_routes_for_user(request.user)
|
|
|
|
if 'errors' in routes_Dict:
|
|
form.errors.update(routes_Dict['errors'])
|
|
Dict = {'form': form}
|
|
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
|
return JsonResponse({'html': html}, status=400)
|
|
|
|
html = render_to_string('blocks/profile/b_my_routes.html', routes_Dict, request=request)
|
|
|
|
res_Dict = {
|
|
'html': html
|
|
}
|
|
|
|
return JsonResponse(res_Dict)
|
|
|
|
except Exception as e:
|
|
|
|
errors_Dict = {
|
|
'errors': {
|
|
'all__': f'ошибка в запросе = {str(e)}'
|
|
}
|
|
}
|
|
Dict = {'form': errors_Dict}
|
|
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
|
return JsonResponse({'html': html}, status=400) |