From 3def6abb84b72e0beca48c7676644ae77926ee47 Mon Sep 17 00:00:00 2001 From: SDE Date: Thu, 22 Jun 2023 17:45:43 +0300 Subject: [PATCH] 0.0.10 registration form routines --- AuthApp/forms.py | 31 ++++++++++++++++++----------- AuthApp/js_views.py | 9 +++++++++ static/js/header.js | 2 +- templates/forms/f_registration.html | 24 +++++++++++----------- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/AuthApp/forms.py b/AuthApp/forms.py index 2978242..75128c6 100644 --- a/AuthApp/forms.py +++ b/AuthApp/forms.py @@ -1,16 +1,23 @@ # # coding=utf-8 -# from django import forms -# from django.contrib.auth.forms import AuthenticationForm -# from django.utils.translation import ugettext_lazy as _ -# from django.core.exceptions import ValidationError -# from .models import * -# # from djng.styling.bootstrap3.forms import Bootstrap3ModelForm -# # from djng.forms import fields, NgModelFormMixin, NgFormValidationMixin, NgModelForm -# # from datetimepicker.widgets import DateTimePicker -# # from datetimepicker.helpers import js_loader_url -# -# -# +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 * +# from djng.styling.bootstrap3.forms import Bootstrap3ModelForm +# from djng.forms import fields, NgModelFormMixin, NgFormValidationMixin, NgModelForm +# from datetimepicker.widgets import DateTimePicker +# from datetimepicker.helpers import js_loader_url + +class RegistrationForm(forms.Form): + firstname = forms.CharField(required=False) + lastname = forms.CharField(required=False) + email = forms.EmailField() + password = forms.CharField(widget=forms.PasswordInput()) + confirm_password = forms.CharField(widget=forms.PasswordInput()) + tel = forms.CharField() + + # # class PersonForm(NgModelFormMixin, NgFormValidationMixin, NgModelForm, Bootstrap3ModelForm): # # # # form_name = 'person_form' diff --git a/AuthApp/js_views.py b/AuthApp/js_views.py index 3471064..19a9cca 100644 --- a/AuthApp/js_views.py +++ b/AuthApp/js_views.py @@ -9,6 +9,7 @@ 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 def registration_ajax(request): if request.method != 'POST': @@ -18,6 +19,14 @@ def registration_ajax(request): data = request.POST + from .forms import RegistrationForm + form = RegistrationForm(data) + if not form.is_valid(): + Dict = {'form': form} + html = render_to_string('forms/f_registration.html', Dict) + return JsonResponse({'html': html}, status=400) + + res_data = { 'errors': 'тестовый верный ответ' } diff --git a/static/js/header.js b/static/js/header.js index 885ee2c..464c028 100644 --- a/static/js/header.js +++ b/static/js/header.js @@ -4,7 +4,7 @@ function SendRegistrationForm(el){ let formData = new FormData(form); $.ajax({ - headers: { "X-CSRFToken": '{{csrf_token}}' }, + headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, url: '/ru/user_account/registration/', type: "POST", // async: true, diff --git a/templates/forms/f_registration.html b/templates/forms/f_registration.html index bbbf43d..7cb895a 100644 --- a/templates/forms/f_registration.html +++ b/templates/forms/f_registration.html @@ -10,28 +10,28 @@ {% csrf_token %}
- {% if errors and 'firstname' in errors %} - Проверьте правильность написания имя + {% if form.errors and form.errors.firstname %} + {{ form.errors.firstname }} {% endif %} - {% if errors and 'email' in errors %} - + {% if form.errors and form.errors.email %} + {{ form.errors.email }} {% endif %} - {% if errors and 'password' in errors %} - + {% if form.errors and form.errors.password %} + {{ form.errors.password }} {% endif %} - {% if errors and 'lastname' in errors %} - + {% if form.errors and form.errors.lastname %} + {{ form.errors.lastname }} {% endif %} - {% if errors and 'tel' in errors %} - + {% if form.errors and form.errors.tel %} + {{ form.errors.tel }} {% endif %} - {% if errors and 'confirm_password' in errors %} - + {% if form.errors and form.errors.confirm_password %} + {{ form.errors.confirm_password }} {% endif %}