From 86a43d69e2fe08a67242e67e0860463cadbbe2cc Mon Sep 17 00:00:00 2001 From: SDE Date: Thu, 13 Jul 2023 15:37:31 +0300 Subject: [PATCH] =?UTF-8?q?0.0.26=20route=20=D1=81reate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AuthApp/js_urls.py | 3 +- AuthApp/js_views.py | 12 +------ RoutesApp/forms.py | 2 +- RoutesApp/js_urls.py | 9 ++++++ RoutesApp/js_views.py | 74 +++++++++++++++++++++++++++++++++++++++++++ TWB/urls.py | 1 + 6 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 RoutesApp/js_urls.py create mode 100644 RoutesApp/js_views.py diff --git a/AuthApp/js_urls.py b/AuthApp/js_urls.py index 10bf2f4..c1ae1b3 100644 --- a/AuthApp/js_urls.py +++ b/AuthApp/js_urls.py @@ -2,8 +2,9 @@ from django.urls import path # from AuthApp.js_views import * # from AuthApp.import_funcs import * -from AuthApp.js_views import * +from .js_views import * from django.contrib.auth import views +from RoutesApp.js_views import new_route_view_ajax urlpatterns = [ path('registration/', registration_ajax, name='registration_ajax'), diff --git a/AuthApp/js_views.py b/AuthApp/js_views.py index 551cc18..6c42724 100644 --- a/AuthApp/js_views.py +++ b/AuthApp/js_views.py @@ -1,7 +1,7 @@ from django.shortcuts import render from uuid import uuid1 -from AuthApp.models import * +from .models import * from django.contrib import auth from django.http import HttpResponse, Http404, JsonResponse from django.template import loader, RequestContext @@ -24,17 +24,7 @@ def my_routes_ajax(request): 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): diff --git a/RoutesApp/forms.py b/RoutesApp/forms.py index 7414f30..0015a08 100644 --- a/RoutesApp/forms.py +++ b/RoutesApp/forms.py @@ -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 = [ diff --git a/RoutesApp/js_urls.py b/RoutesApp/js_urls.py new file mode 100644 index 0000000..36d48e1 --- /dev/null +++ b/RoutesApp/js_urls.py @@ -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'), +] \ No newline at end of file diff --git a/RoutesApp/js_views.py b/RoutesApp/js_views.py new file mode 100644 index 0000000..3bcb9ea --- /dev/null +++ b/RoutesApp/js_views.py @@ -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) \ No newline at end of file diff --git a/TWB/urls.py b/TWB/urls.py index 1730d1c..1c8f080 100644 --- a/TWB/urls.py +++ b/TWB/urls.py @@ -20,6 +20,7 @@ urlpatterns += i18n_patterns( path('profile/', include('AuthApp.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) \ No newline at end of file