0.0.26
route сreate
This commit is contained in:
@@ -6,7 +6,7 @@ from django.core.exceptions import ValidationError
|
||||
from .models import *
|
||||
|
||||
|
||||
class RegistrationForm(forms.ModelForm):
|
||||
class CreateRouteForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Route
|
||||
exclude = [
|
||||
|
||||
9
RoutesApp/js_urls.py
Normal file
9
RoutesApp/js_urls.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# coding=utf-8
|
||||
from django.urls import path
|
||||
# from AuthApp.js_views import *
|
||||
# from AuthApp.import_funcs import *
|
||||
from .js_views import *
|
||||
|
||||
urlpatterns = [
|
||||
path('create_route/', create_route_ajax, name='create_route_ajax'),
|
||||
]
|
||||
74
RoutesApp/js_views.py
Normal file
74
RoutesApp/js_views.py
Normal file
@@ -0,0 +1,74 @@
|
||||
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 *
|
||||
|
||||
|
||||
def new_route_view_ajax(request):
|
||||
if request.method != 'POST':
|
||||
raise Http404
|
||||
|
||||
Dict = {
|
||||
'form': CreateRouteForm()
|
||||
}
|
||||
|
||||
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
||||
return JsonResponse({'html': html}, status=200)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
# from django.contrib.auth import authenticate
|
||||
# user = authenticate(username=form.data['username'], password=form.data['password'])
|
||||
# if user is not None:
|
||||
# auth.login(request, user)
|
||||
# else:
|
||||
# errors_Dict = {
|
||||
# 'errors': {
|
||||
# 'all__': f'неверный логин и\или пароль'
|
||||
# }
|
||||
# }
|
||||
# Dict = {'form': errors_Dict}
|
||||
# html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
||||
# return JsonResponse({'html': html}, status=400)
|
||||
|
||||
|
||||
res_Dict = {
|
||||
'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)
|
||||
Reference in New Issue
Block a user