0.0.26
route сreate
This commit is contained in:
@@ -2,8 +2,9 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
# from AuthApp.js_views import *
|
# from AuthApp.js_views import *
|
||||||
# from AuthApp.import_funcs import *
|
# from AuthApp.import_funcs import *
|
||||||
from AuthApp.js_views import *
|
from .js_views import *
|
||||||
from django.contrib.auth import views
|
from django.contrib.auth import views
|
||||||
|
from RoutesApp.js_views import new_route_view_ajax
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('registration/', registration_ajax, name='registration_ajax'),
|
path('registration/', registration_ajax, name='registration_ajax'),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
from uuid import uuid1
|
from uuid import uuid1
|
||||||
from AuthApp.models import *
|
from .models import *
|
||||||
from django.contrib import auth
|
from django.contrib import auth
|
||||||
from django.http import HttpResponse, Http404, JsonResponse
|
from django.http import HttpResponse, Http404, JsonResponse
|
||||||
from django.template import loader, RequestContext
|
from django.template import loader, RequestContext
|
||||||
@@ -24,17 +24,7 @@ def my_routes_ajax(request):
|
|||||||
return JsonResponse({'html': html}, status=200)
|
return JsonResponse({'html': html}, status=200)
|
||||||
|
|
||||||
|
|
||||||
def new_route_view_ajax(request):
|
|
||||||
if request.method != 'POST':
|
|
||||||
raise Http404
|
|
||||||
|
|
||||||
from RoutesApp.forms import RegistrationForm
|
|
||||||
Dict = {
|
|
||||||
'form': RegistrationForm()
|
|
||||||
}
|
|
||||||
|
|
||||||
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
|
||||||
return JsonResponse({'html': html}, status=200)
|
|
||||||
|
|
||||||
|
|
||||||
def login_ajax(request):
|
def login_ajax(request):
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from django.core.exceptions import ValidationError
|
|||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
|
|
||||||
class RegistrationForm(forms.ModelForm):
|
class CreateRouteForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Route
|
model = Route
|
||||||
exclude = [
|
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)
|
||||||
@@ -20,6 +20,7 @@ urlpatterns += i18n_patterns(
|
|||||||
path('profile/', include('AuthApp.urls')),
|
path('profile/', include('AuthApp.urls')),
|
||||||
|
|
||||||
path('user_account/', include('AuthApp.js_urls')),
|
path('user_account/', include('AuthApp.js_urls')),
|
||||||
|
path('routes/', include('RoutesApp.js_urls')),
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
Reference in New Issue
Block a user