0.0.16
login routines
This commit is contained in:
@@ -9,6 +9,11 @@ from .models import *
|
||||
# from datetimepicker.widgets import DateTimePicker
|
||||
# from datetimepicker.helpers import js_loader_url
|
||||
|
||||
|
||||
class LoginForm(forms.Form):
|
||||
username = forms.CharField(required=True)
|
||||
password = forms.CharField(required=True)
|
||||
|
||||
class RegistrationForm(forms.Form):
|
||||
from .models import account_type_choices
|
||||
account_type = forms.ChoiceField(choices=account_type_choices, initial='sender', required=True)
|
||||
|
||||
@@ -7,4 +7,7 @@ from django.contrib.auth import views
|
||||
|
||||
urlpatterns = [
|
||||
path('registration/', registration_ajax, name='registration_ajax'),
|
||||
path('login/', login_ajax, name='login_ajax'),
|
||||
|
||||
path('new_route_view/', new_route_view_ajax, name='new_route_view_ajax'),
|
||||
]
|
||||
@@ -12,6 +12,69 @@ from datetime import datetime
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
|
||||
|
||||
|
||||
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):
|
||||
if request.method != 'POST':
|
||||
raise Http404
|
||||
|
||||
try:
|
||||
|
||||
data = request.POST
|
||||
|
||||
from .forms import LoginForm
|
||||
form = LoginForm(data)
|
||||
if not form.is_valid():
|
||||
Dict = {'form': form}
|
||||
html = render_to_string('forms/f_registration.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('forms/f_login.html', Dict)
|
||||
return JsonResponse({'html': html}, status=400)
|
||||
|
||||
|
||||
res_Dict = {
|
||||
'redirect_url': reverse('user_profile')
|
||||
}
|
||||
|
||||
return JsonResponse(res_Dict)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
errors_Dict = {
|
||||
'errors': {
|
||||
'__all__': f'ошибка в запросе = {str(e)}'
|
||||
}
|
||||
}
|
||||
Dict = {'form': errors_Dict}
|
||||
html = render_to_string('forms/f_login.html', Dict)
|
||||
return JsonResponse({'html': html}, status=400)
|
||||
|
||||
|
||||
def registration_ajax(request):
|
||||
if request.method != 'POST':
|
||||
raise Http404
|
||||
|
||||
0
RoutesApp/__init__.py
Normal file
0
RoutesApp/__init__.py
Normal file
3
RoutesApp/admin.py
Normal file
3
RoutesApp/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
RoutesApp/apps.py
Normal file
6
RoutesApp/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class RoutesappConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'RoutesApp'
|
||||
25
RoutesApp/forms.py
Normal file
25
RoutesApp/forms.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# # coding=utf-8
|
||||
from django import forms
|
||||
from django.contrib.auth.forms import AuthenticationForm
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.core.exceptions import ValidationError
|
||||
from .models import *
|
||||
|
||||
|
||||
class RegistrationForm(forms.Form):
|
||||
type_transport = forms.ChoiceField(choices=type_transport_choices, initial='avia', required=True)
|
||||
departure_DT = forms.DateTimeField(required=True)
|
||||
arrival_DT = forms.DateTimeField(required=True)
|
||||
from_country = forms.CharField(required=True)
|
||||
to_country = forms.CharField(required=True)
|
||||
from_city = forms.CharField(required=True)
|
||||
to_city = forms.CharField(required=True)
|
||||
from_place = forms.ChoiceField(choices=transfer_location_choices, initial='other', required=True)
|
||||
to_place = forms.ChoiceField(choices=transfer_location_choices, initial='other', required=True)
|
||||
cargo_type = forms.ChoiceField(choices=cargo_type_choices, initial='parcel', required=True)
|
||||
weight = forms.IntegerField(required=True)
|
||||
phone = forms.CharField(required=True)
|
||||
add_phone = forms.CharField(required=True)
|
||||
receive_msg_by_email = forms.BooleanField(initial=False, required=True)
|
||||
receive_msg_by_sms = forms.BooleanField(initial=False, required=True)
|
||||
owner = forms.IntegerField(required=True)
|
||||
0
RoutesApp/migrations/__init__.py
Normal file
0
RoutesApp/migrations/__init__.py
Normal file
23
RoutesApp/models.py
Normal file
23
RoutesApp/models.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
# Create your models here.
|
||||
|
||||
|
||||
type_transport_choices = (
|
||||
('avia', _('Авиатранспорт')),
|
||||
('road', _('Наземный транспорт'))
|
||||
)
|
||||
|
||||
transfer_location_choices = (
|
||||
('airport', _('В аэропорту')),
|
||||
('city', _('По городу')),
|
||||
('other', _('По договоренности'))
|
||||
)
|
||||
|
||||
cargo_type_choices = (
|
||||
('passenger', _('Пассажир')),
|
||||
('cargo', _('Груз')),
|
||||
('parcel', _('Бандероль')),
|
||||
('package', _('Посылка')),
|
||||
('letter', _('Письмо\Документ'))
|
||||
)
|
||||
3
RoutesApp/tests.py
Normal file
3
RoutesApp/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
3
RoutesApp/views.py
Normal file
3
RoutesApp/views.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
3
templates/blocks/profile/b_new_route.html
Normal file
3
templates/blocks/profile/b_new_route.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<div>
|
||||
|
||||
</div>
|
||||
@@ -4,7 +4,6 @@
|
||||
<form name="registration_form" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
|
||||
<div class="switch">
|
||||
<div><a class="active" href="#">Перевозчик</a></div>
|
||||
<div><a class="deadctive" href="#">Отправитель</a></div>
|
||||
|
||||
Reference in New Issue
Block a user