diff --git a/assets/js/build/user_profile_edit.js b/assets/js/build/user_profile_edit.js index 3197679..556e37c 100644 --- a/assets/js/build/user_profile_edit.js +++ b/assets/js/build/user_profile_edit.js @@ -159,20 +159,25 @@ value: true }); function checkBoxBindingInit() { - var $residency_checkBoxes = $('input[name=residency]'); - var $legal_status_checkBoxes = $('input[name=legal_status]'); + /* + Скрываем/Показываем формы/части форм, взависимости от выбранных checkBox'ов + */ + var $residency_checkBoxes = $('input[name=fin_info-residency]'); + var $legal_status_checkBoxes = $('input[name=fin_info-legal_status]'); var $legal_status_boxes = $legal_status_checkBoxes.closest('div'); + var $fin_infos = $('.js-fin-info'); var shows = { 'russian_resident': ['individual', 'entity', 'employed'], 'non_russian_resident': ['individual', 'entity'], 'russian_stay_permit': ['individual'] }; - // $legal_status_boxes.hide(); - $residency_checkBoxes.first().attr("checked", true); - $legal_status_checkBoxes.first().attr("checked", true); + $fin_infos.hide(); + $('.-russian_stay_permit-individual').hide(); $residency_checkBoxes.on("click", function (e) { - $legal_status_checkBoxes.first().attr("checked", true); + $legal_status_checkBoxes.first().trigger("click"); + }); + $residency_checkBoxes.on("change", function (e) { $legal_status_boxes.hide(); var value = $(e.target).val(); var _iteratorNormalCompletion = true; @@ -183,7 +188,6 @@ for (var _iterator = shows[value][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var legal_status = _step.value; - // console.log(legal_status); $('input[value=' + legal_status + ']').closest('div').show(); } } catch (err) { @@ -200,7 +204,44 @@ } } } + + var fin_info_id = ''; + fin_info_id += '-' + $residency_checkBoxes.filter(':checked').val(); + fin_info_id += '-' + $legal_status_checkBoxes.filter(':checked').val(); + if (fin_info_id == '-non_russian_resident-individual') { + $('.-non_russian_resident-individual').hide(); + $('.-non_russian_resident-individual').children('input').val(''); + } else { + $('.-non_russian_resident-individual').show(); + } + if (fin_info_id == '-russian_stay_permit-individual') { + $('.-russian_stay_permit-individual').show(); + } else { + $('.-russian_stay_permit-individual').hide(); + $('.-russian_stay_permit-individual').children('input').val(''); + } + }); + + $legal_status_checkBoxes.on("click", function (e) { + $fin_infos.each(function (ind, el) { + $(el).find('input').val(''); + }); + }); + $legal_status_checkBoxes.on("change", function (e) { + $fin_infos.hide(); + + var fin_info_id = ''; + fin_info_id += '-' + $residency_checkBoxes.filter(':checked').val(); + fin_info_id += '-' + $legal_status_checkBoxes.filter(':checked').val(); + + if (fin_info_id != '-non_russian_resident-entity') { + fin_info_id = '-russian_resident'; + fin_info_id += '-' + $legal_status_checkBoxes.filter(':checked').val(); + } + $('#' + fin_info_id).show(); }); + $residency_checkBoxes.first().trigger("change"); + $legal_status_checkBoxes.first().trigger("change"); } exports.checkBoxBindingInit = checkBoxBindingInit; diff --git a/assets/js/src/seeds/user_check_statuses.js b/assets/js/src/seeds/user_check_statuses.js index 24a90eb..f748f82 100644 --- a/assets/js/src/seeds/user_check_statuses.js +++ b/assets/js/src/seeds/user_check_statuses.js @@ -1,25 +1,66 @@ function checkBoxBindingInit() { - let $residency_checkBoxes = $('input[name=residency]'); - let $legal_status_checkBoxes = $('input[name=legal_status]'); + /* + Скрываем/Показываем формы/части форм, взависимости от выбранных checkBox'ов + */ + let $residency_checkBoxes = $('input[name=fin_info-residency]'); + let $legal_status_checkBoxes = $('input[name=fin_info-legal_status]'); let $legal_status_boxes = $legal_status_checkBoxes.closest('div'); + const $fin_infos = $('.js-fin-info'); let shows = { 'russian_resident': ['individual', 'entity', 'employed'], 'non_russian_resident': ['individual', 'entity'], 'russian_stay_permit': ['individual'], }; - // $legal_status_boxes.hide(); - $residency_checkBoxes.first().attr("checked", true); - $legal_status_checkBoxes.first().attr("checked", true); + $fin_infos.hide(); + $('.-russian_stay_permit-individual').hide(); $residency_checkBoxes.on("click", function (e) { - $legal_status_checkBoxes.first().attr("checked", true); + $legal_status_checkBoxes.first().trigger("click"); + }); + $residency_checkBoxes.on("change", function (e) { $legal_status_boxes.hide(); let value = $(e.target).val(); - for (let legal_status of shows[value]){ - // console.log(legal_status); + for (let legal_status of shows[value]) { $(`input[value=${legal_status}]`).closest('div').show(); } - }) + + let fin_info_id = ''; + fin_info_id += '-' + $residency_checkBoxes.filter(':checked').val(); + fin_info_id += '-' + $legal_status_checkBoxes.filter(':checked').val(); + if (fin_info_id == '-non_russian_resident-individual') { + $('.-non_russian_resident-individual').hide(); + $('.-non_russian_resident-individual').children('input').val(''); + } else { + $('.-non_russian_resident-individual').show() + } + if (fin_info_id == '-russian_stay_permit-individual') { + $('.-russian_stay_permit-individual').show(); + } else { + $('.-russian_stay_permit-individual').hide(); + $('.-russian_stay_permit-individual').children('input').val(''); + } + }); + + $legal_status_checkBoxes.on("click", function (e) { + $fin_infos.each(function (ind, el) { + $(el).find('input').val(''); + }); + }); + $legal_status_checkBoxes.on("change", function (e) { + $fin_infos.hide(); + + let fin_info_id = ''; + fin_info_id += '-' + $residency_checkBoxes.filter(':checked').val(); + fin_info_id += '-' + $legal_status_checkBoxes.filter(':checked').val(); + + if (fin_info_id != '-non_russian_resident-entity') { + fin_info_id = '-russian_resident'; + fin_info_id += '-' + $legal_status_checkBoxes.filter(':checked').val(); + } + $(`#${fin_info_id}`).show(); + }); + $residency_checkBoxes.first().trigger("change"); + $legal_status_checkBoxes.first().trigger("change"); } export {checkBoxBindingInit} \ No newline at end of file diff --git a/users/forms.py b/users/forms.py index 399e851..0e4e564 100644 --- a/users/forms.py +++ b/users/forms.py @@ -202,36 +202,56 @@ class UserFinancialInfoEditForm(forms.ModelForm): model = UserFinancialInfo fields = ( - 'address', - 'credit_card_number', - 'date_of_birth', + 'residency', + 'legal_status', + 'fio', + 'date_of_birth', + 'phone', + + 'postal_address', + 'registration_address', + + 'credit_card_number', 'inn', - 'legal_status', + 'passport_issue_date', 'passport_issued_by', 'passport_number', - 'passport_scan', 'passport_series', - 'phone', - 'residency', 'subdivision_code', + 'yandex_money', + 'web_money', + + # Юридические данные + 'correspondent_account', + 'bank_bic', + 'bank_inn', + 'checking_account', + 'bank_name', + 'authorized_bank_name', + 'ppc', + 'psrn', + + 'organization_name', + 'organization_registered_address', + 'organization_postal_address', + 'organization_reg_number' + ) widgets = { - # 'date_of_birth': forms.TextInput(attrs={'class': 'datepicker'}), - # 'passport_issue_date': forms.TextInput(attrs={'class': 'datepicker'}), - 'legal_status': forms.RadioSelect(), - 'residency': forms.RadioSelect(), + 'date_of_birth': forms.DateInput(attrs={'class': 'datepicker box-sizing simple-input'}), + 'passport_issue_date': forms.DateInput(attrs={'class': 'datepicker box-sizing simple-input'}), } def __init__(self, *args, **kwargs): self.request = kwargs.pop('request') super().__init__(*args, **kwargs) - self.fields['residency'].choices = self.fields['residency'].choices[1:] - self.fields['legal_status'].choices = self.fields['legal_status'].choices[1:] + # self.fields['residency'].choices = self.fields['residency'].choices[1:] + # self.fields['legal_status'].choices = self.fields['legal_status'].choices[1:] # self.fields['residency'].empty_label = None # self.fields['residency'].widget.choices = self.fields['residency'].choices diff --git a/users/migrations/0023_auto_20170105_1706.py b/users/migrations/0023_auto_20170105_1706.py new file mode 100644 index 0000000..4309919 --- /dev/null +++ b/users/migrations/0023_auto_20170105_1706.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2017-01-05 14:06 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0022_user_organization_name'), + ] + + operations = [ + migrations.AddField( + model_name='userfinancialinfo', + name='postal_address', + field=models.CharField(blank=True, max_length=255, verbose_name='Почтовый адрес'), + ), + migrations.AddField( + model_name='userfinancialinfo', + name='registration_address', + field=models.CharField(blank=True, max_length=255, verbose_name='Адрес регистрации'), + ), + migrations.AddField( + model_name='userfinancialinfo', + name='web_money', + field=models.CharField(blank=True, max_length=50), + ), + migrations.AlterField( + model_name='userfinancialinfo', + name='credit_card_number', + field=models.CharField(blank=True, max_length=50), + ), + migrations.AlterField( + model_name='userfinancialinfo', + name='fio', + field=models.CharField(blank=True, max_length=255), + ), + migrations.AlterField( + model_name='userfinancialinfo', + name='inn', + field=models.CharField(blank=True, max_length=100), + ), + migrations.AlterField( + model_name='userfinancialinfo', + name='legal_status', + field=models.CharField(choices=[('individual', 'Физическое лицо'), ('entity', 'Юридическое лицо'), ('employed', 'Частный предприниматель')], max_length=30), + ), + migrations.AlterField( + model_name='userfinancialinfo', + name='passport_issued_by', + field=models.CharField(max_length=255, verbose_name='Кем выдан'), + ), + migrations.AlterField( + model_name='userfinancialinfo', + name='phone', + field=models.CharField(blank=True, max_length=30), + ), + migrations.AlterField( + model_name='userfinancialinfo', + name='residency', + field=models.CharField(choices=[('russian_resident', 'Резидент РФ'), ('non_russian_resident', 'Нерезидент РФ'), ('russian_stay_permit', 'Вид на жительство')], max_length=50), + ), + migrations.AlterField( + model_name='userfinancialinfo', + name='subdivision_code', + field=models.CharField(max_length=10, verbose_name='Код подразделения'), + ), + migrations.AlterField( + model_name='userfinancialinfo', + name='yandex_money', + field=models.CharField(blank=True, max_length=50), + ), + ] diff --git a/users/migrations/0024_auto_20170105_1808.py b/users/migrations/0024_auto_20170105_1808.py new file mode 100644 index 0000000..b6c2030 --- /dev/null +++ b/users/migrations/0024_auto_20170105_1808.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2017-01-05 15:08 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0023_auto_20170105_1706'), + ] + + operations = [ + migrations.AddField( + model_name='userfinancialinfo', + name='bank_bic', + field=models.CharField(default='', max_length=32, verbose_name='БИК банка'), + preserve_default=False, + ), + migrations.AddField( + model_name='userfinancialinfo', + name='bank_inn', + field=models.CharField(default='', max_length=32, verbose_name='ИНН банка'), + preserve_default=False, + ), + migrations.AddField( + model_name='userfinancialinfo', + name='bank_name', + field=models.CharField(default='', max_length=32, verbose_name='Название банка'), + preserve_default=False, + ), + migrations.AddField( + model_name='userfinancialinfo', + name='checking_account', + field=models.CharField(default='', max_length=64, verbose_name='Расчетный счет'), + preserve_default=False, + ), + migrations.AddField( + model_name='userfinancialinfo', + name='correspondent_account', + field=models.CharField(default='', max_length=32, verbose_name='Корреспондентский счет'), + preserve_default=False, + ), + migrations.AddField( + model_name='userfinancialinfo', + name='organization_name', + field=models.CharField(default='', max_length=32, verbose_name='Название организации'), + preserve_default=False, + ), + migrations.AddField( + model_name='userfinancialinfo', + name='organization_postal_address', + field=models.CharField(default='', max_length=255, verbose_name='Почтовый адрес'), + preserve_default=False, + ), + migrations.AddField( + model_name='userfinancialinfo', + name='organization_registered_address', + field=models.CharField(default='', max_length=255, verbose_name='Юридический адрес'), + preserve_default=False, + ), + migrations.AddField( + model_name='userfinancialinfo', + name='ppc', + field=models.CharField(default='', max_length=32, verbose_name='КПП'), + preserve_default=False, + ), + migrations.AddField( + model_name='userfinancialinfo', + name='psrn', + field=models.CharField(default='', max_length=32, verbose_name='ОГРН'), + preserve_default=False, + ), + migrations.AlterField( + model_name='userfinancialinfo', + name='date_of_birth', + field=models.DateField(blank=True, null=True), + ), + migrations.AlterField( + model_name='userfinancialinfo', + name='passport_issue_date', + field=models.DateField(blank=True, null=True), + ), + ] diff --git a/users/migrations/0025_auto_20170109_1202.py b/users/migrations/0025_auto_20170109_1202.py new file mode 100644 index 0000000..d40dcfb --- /dev/null +++ b/users/migrations/0025_auto_20170109_1202.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2017-01-09 09:02 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0024_auto_20170105_1808'), + ] + + operations = [ + migrations.AddField( + model_name='userfinancialinfo', + name='authorized_bank_name', + field=models.CharField(default='', max_length=32, verbose_name='Название уполномоченного банка в РФ'), + preserve_default=False, + ), + migrations.AddField( + model_name='userfinancialinfo', + name='organization_reg_number', + field=models.CharField(default='', max_length=64, verbose_name='Регистрационный номер в налоговом органе'), + preserve_default=False, + ), + migrations.AlterField( + model_name='userfinancialinfo', + name='inn', + field=models.CharField(blank=True, max_length=100, verbose_name='ИНН'), + ), + migrations.AlterField( + model_name='userfinancialinfo', + name='legal_status', + field=models.CharField(choices=[('individual', 'Физическое лицо'), ('entity', 'Юридическое лицо'), ('employed', 'Индивидуальный предприниматель')], max_length=30), + ), + ] diff --git a/users/models.py b/users/models.py index d6fb68a..19f71b8 100644 --- a/users/models.py +++ b/users/models.py @@ -62,24 +62,48 @@ class UserFinancialInfo(models.Model): LEGAL_STATUSES = ( ('individual', 'Физическое лицо'), ('entity', 'Юридическое лицо'), - ('employed', 'Частный предприниматель'), + ('employed', 'Индивидуальный предприниматель'), ) - address = models.CharField(max_length=1000) - credit_card_number = models.CharField(max_length=50) - date_of_birth = models.DateField() - fio = models.CharField(max_length=255) - inn = models.CharField(max_length=100) + residency = models.CharField(max_length=50, choices=RESIDENCIES) legal_status = models.CharField(max_length=30, choices=LEGAL_STATUSES) - passport_issue_date = models.DateField() - passport_issued_by = models.CharField(max_length=255) - passport_number = models.CharField(max_length=10) + + fio = models.CharField(max_length=255, blank=True) + date_of_birth = models.DateField(null=True, blank=True) + phone = models.CharField(max_length=30, blank=True) + + # @deprecated + address = models.CharField(max_length=1000, blank=True) + postal_address = models.CharField(max_length=255, verbose_name='Почтовый адрес', blank=True) + registration_address = models.CharField(max_length=255, verbose_name='Адрес регистрации', blank=True) + + credit_card_number = models.CharField(max_length=50, blank=True) + inn = models.CharField(max_length=100, blank=True, verbose_name='ИНН') + + passport_issue_date = models.DateField(null=True, blank=True) + passport_issued_by = models.CharField(max_length=255, verbose_name="Кем выдан", blank=True) + passport_number = models.CharField(max_length=10, blank=True) passport_scan = models.ImageField(upload_to='users/contractors/') - passport_series = models.CharField(max_length=6) - phone = models.CharField(max_length=30) - residency = models.CharField(max_length=50, choices=RESIDENCIES) - subdivision_code = models.CharField(max_length=10) - yandex_money = models.CharField(max_length=50) + passport_series = models.CharField(max_length=6, blank=True) + subdivision_code = models.CharField(max_length=10, verbose_name='Код подразделения', blank=True) + + yandex_money = models.CharField(max_length=50, blank=True) + web_money = models.CharField(max_length=50, blank=True) + + # Юридические данные + correspondent_account = models.CharField(max_length=32, verbose_name='Корреспондентский счет', blank=True) + bank_bic = models.CharField(max_length=32, verbose_name='БИК банка', blank=True) + bank_inn = models.CharField(max_length=32, verbose_name='ИНН банка', blank=True) + checking_account = models.CharField(max_length=64, verbose_name='Расчетный счет', blank=True) + bank_name = models.CharField(max_length=32, verbose_name='Название банка', blank=True) + authorized_bank_name = models.CharField(max_length=32, verbose_name='Название уполномоченного банка в РФ', blank=True) + ppc = models.CharField(max_length=32, verbose_name='КПП', blank=True) + psrn = models.CharField(max_length=32, verbose_name='ОГРН', blank=True) + + organization_name = models.CharField(max_length=32, verbose_name="Название организации", blank=True) + organization_registered_address = models.CharField(max_length=255, verbose_name="Юридический адрес", blank=True) + organization_postal_address = models.CharField(max_length=255, verbose_name="Почтовый адрес", blank=True) + organization_reg_number = models.CharField(max_length=64, verbose_name="Регистрационный номер в налоговом органе", blank=True) def __str__(self): return self.fio diff --git a/users/static/sass/user-profile-edit.sass b/users/static/sass/user-profile-edit.sass index 6080acc..24d4827 100644 --- a/users/static/sass/user-profile-edit.sass +++ b/users/static/sass/user-profile-edit.sass @@ -101,8 +101,10 @@ .info, .financial_info background-color: #F2F2F2 - padding: 50px 40px + padding: 30px 40px 50px margin-top: 20px + .header + margin-top: 30px .btn-simple border-radius: 40px diff --git a/users/templates/partials/tabs/tab-user-financial_info.html b/users/templates/partials/tabs/tab-user-financial_info.html new file mode 100644 index 0000000..0699ba6 --- /dev/null +++ b/users/templates/partials/tabs/tab-user-financial_info.html @@ -0,0 +1,418 @@ +
+
+
+
Имя, Фамилия, Отчество
+ +
+
+
Дата рождения
+ {{ fin_info_form.date_of_birth }} +
+
+
Телефон
+ +
+
+
Резиденство
+
+ {% for residence in RESIDENCIES %} +
+ +
+ {% endfor %} +
+
Юридический статус
+
+ {% for legal_status in LEGAL_STATUSES %} +
+ +
+ {% endfor %} +
+
+
+
+
+
+
+
+
+
+
+
Серия паспорта
+ +
+
+
Номер паспорта
+ +
+
+
Код подразделения
+ +
+
+
Дата выдачи
+ {{ fin_info_form.passport_issue_date }} +
+
+
+
+
Кем выдан
+ +
+
+
+
+
Почтовый адрес
+ +
+
+
+
+
Адрес регистрации
+ +
+
+
+
+
Адрес в стране, гражданином которой является иностранное физическое лицо
+ +
+
+
+
+
+
+
+
+
+
+
+
ИНН
+ +
+
+
Номер карты
+ +
+
+
Яндекс.Деньги
+ +
+
+
WebMoney
+ +
+
+
+
+
+
+
{{ fin_info_form.correspondent_account.label }}
+ +
+
+
{{ fin_info_form.bank_bic.label }}
+ +
+
+
{{ fin_info_form.bank_inn.label }}
+ +
+
+
+
+
{{ fin_info_form.checking_account.label }}
+ +
+
+
+
+
{{ fin_info_form.bank_name.label }}
+ +
+
+
+
+
{{ fin_info_form.ppc.label }}
+ +
+
+
{{ fin_info_form.psrn.label }}
+ +
+
+
+
+
+
+
+
+
+
+
+
{{ fin_info_form.organization_name.label }}
+ +
+
+
+
+
{{ fin_info_form.organization_registered_address.label }}
+ +
+
+
+
+
{{ fin_info_form.organization_postal_address.label }}
+ +
+
+
+
+
+
+
Корр.счет вашего банка в уполномоченном банке
+ +
+
+
БИК уполномоченного банка
+ +
+
+
ИНН уполномоченного банка
+ +
+
+
+
+
{{ fin_info_form.checking_account.label }} (IBAN)
+ +
+
+
+
+
Название вашего банка
+ +
+
+
+
+
Название уполномоченного банка в РФ
+ +
+
+
+
+
+
+
+
+
+
+
+
{{ fin_info_form.organization_name.label }}
+ +
+
+
+
+
{{ fin_info_form.organization_registered_address.label }}
+ +
+
+
+
+
{{ fin_info_form.organization_postal_address.label }}
+ +
+
+
+
+
{{ fin_info_form.organization_reg_number.label }}
+ +
+
+
+
+
+
+
{{ fin_info_form.correspondent_account.label }}
+ +
+
+
{{ fin_info_form.inn.label }}
+ +
+
+
+
+
{{ fin_info_form.checking_account.label }}
+ +
+
+
Номер карты Р/С
+ +
+
+
+
+
{{ fin_info_form.bank_name.label }}
+ +
+
+
+
+
{{ fin_info_form.bank_bic.label }}
+ +
+
+
{{ fin_info_form.psrn.label }}ИП
+ +
+
+
+
+
+
+
+
+
+
+
+
{{ fin_info_form.organization_name.label }}
+ +
+
+
+
+
{{ fin_info_form.organization_registered_address.label }}
+ +
+
+
+
+
{{ fin_info_form.organization_postal_address.label }}
+ +
+
+
+
+
+
 
+ +
+
+
+ + \ No newline at end of file diff --git a/users/templates/partials/tabs/tab-user-info.html b/users/templates/partials/tabs/tab-user-info.html new file mode 100644 index 0000000..614f8ba --- /dev/null +++ b/users/templates/partials/tabs/tab-user-info.html @@ -0,0 +1,92 @@ +
+
+
Дата рождения
+
+ {{ form.date_of_birth }} +
+
+
+
+
+
Пол
+
+ + + +
+ +
+
+ {% if request.user.is_contractor %} +
+
+
Статус
+
+ + + +
+ {% else %} +
{{ form.organization_name.label }}
+ + {% endif %} + +
+
+
Skype
+ +
+
+
+
Сайт
+ +
+
+
Телефон
+ +
+
+
Второй телефон
+ +
+
+
 
+ +
+
\ No newline at end of file diff --git a/users/templates/user_profile_edit.html b/users/templates/user_profile_edit.html index 2b5f8ee..d75ef81 100644 --- a/users/templates/user_profile_edit.html +++ b/users/templates/user_profile_edit.html @@ -112,7 +112,7 @@
-
 
+
 
@@ -213,158 +213,23 @@
Общая информация + class="btn btn-default tab-inserted active"> + Общая информация + Финансовая - информация + class="btn btn-default tab-inserted" role="button"> + Финансоваяинформация +
-
-
-
Дата рождения
-
- {{ form.date_of_birth }} -
-
-
-
-
-
Пол
-
- - - -
- -
-
- {% if request.user.is_contractor %} -
-
-
Статус
-
- - - -
- {% else %} -
{{ form.organization_name.label }}
- - {% endif %} - -
-
-
Skype
- -
-
-
-
Сайт
- -
-
-
Телефон
- -
-
-
Второй телефон
- -
-
-
 
- -
-
+ {% include 'partials/tabs/tab-user-info.html' %}
-
-
-
-
Имя, Фамилия, Отчество
- -
-
-
Дата рождения
- {#
#} - {{ fin_info_form.date_of_birth }} - {#
#} -
-
-
Телефон
- -
-
-
Резиденство
-
- {% for residence in RESIDENCIES %} -
- -
- {% endfor %} -
-
Юридический статус
-
- {% for legal_status in LEGAL_STATUSES %} -
- -
- {% endfor %} -
-
- + {% include 'partials/tabs/tab-user-financial_info.html' %}
@@ -378,7 +243,6 @@ {% block personal_js %} {{ block.super }} - {# #} diff --git a/users/urls.py b/users/urls.py index 643cc7f..86f3061 100755 --- a/users/urls.py +++ b/users/urls.py @@ -17,8 +17,6 @@ from .views import ( CustomerProfileTrashedProjectsView, TeamCreateView, TeamProfileView, - UserFinancialInfoEditView, - UserProfileEditView, UserProfileEditViewFull, ) diff --git a/users/views.py b/users/views.py index c49caad..a700c34 100644 --- a/users/views.py +++ b/users/views.py @@ -46,68 +46,69 @@ from .forms import ( ) -class UserProfileEditView(BaseMixin, View): - form_class = UserProfileEditForm - template_name = 'user_profile_edit.html' - - def dispatch(self, request, *args, **kwargs): - if request.resolver_match.url_name == 'user-experience-edit': - if not request.user.is_contractor(): - raise PermissionDenied - self.form_class = UserProfileExperienceEditForm - request.experience_edit = True - if request.user.is_authenticated() and request.user.pk == int(kwargs.get('pk')): - return super().dispatch(request, *args, **kwargs) - else: - raise PermissionDenied - - def get(self, request, *args, **kwargs): - context = self.get_context_data(**_.merge({}, request.GET, kwargs)) - - form = self.form_class(request=request, instance=request.user) - context.update({'form': form}) - - return render(request, self.template_name, context) - - def post(self, request, *args, **kwargs): - context = self.get_context_data(**kwargs) - - specs = request.POST.getlist('contractor_specializations') - request.POST.setlist('contractor_specializations', _.compact(specs)) # Ignore empty input values - - form = self.form_class(request.POST, request=request, instance=request.user) - - if form.is_valid(): - user = form.save() - - live_image = form.cleaned_data.get('live_image') - - if live_image: - new_image = ContentFile(live_image.file.read()) - new_image.name = live_image.file.name - - user.avatar = new_image - user.save() - - live_image.file.delete() - live_image.delete() - - messages.info(request, 'Пользователь успешно отредактирован') - redirect_to = request.POST.get('next') - return redirect(redirect_to) - else: - if form.errors: - messages.info(request, ( - '

Произошла ошибка (form)

' - '
{form}
' - ).format(form=pformat(form.errors))) - - context.update({'form': form}) - return render(request, self.template_name, context) +# class UserProfileEditView(BaseMixin, View): +# form_class = UserProfileEditForm +# template_name = 'user_profile_edit.html' +# +# def dispatch(self, request, *args, **kwargs): +# if request.resolver_match.url_name == 'user-experience-edit': +# if not request.user.is_contractor(): +# raise PermissionDenied +# self.form_class = UserProfileExperienceEditForm +# request.experience_edit = True +# if request.user.is_authenticated() and request.user.pk == int(kwargs.get('pk')): +# return super().dispatch(request, *args, **kwargs) +# else: +# raise PermissionDenied +# +# def get(self, request, *args, **kwargs): +# context = self.get_context_data(**_.merge({}, request.GET, kwargs)) +# +# form = self.form_class(request=request, instance=request.user) +# context.update({'form': form}) +# +# return render(request, self.template_name, context) +# +# def post(self, request, *args, **kwargs): +# context = self.get_context_data(**kwargs) +# +# specs = request.POST.getlist('contractor_specializations') +# request.POST.setlist('contractor_specializations', _.compact(specs)) # Ignore empty input values +# +# form = self.form_class(request.POST, request=request, instance=request.user) +# +# if form.is_valid(): +# user = form.save() +# +# live_image = form.cleaned_data.get('live_image') +# +# if live_image: +# new_image = ContentFile(live_image.file.read()) +# new_image.name = live_image.file.name +# +# user.avatar = new_image +# user.save() +# +# live_image.file.delete() +# live_image.delete() +# +# messages.info(request, 'Пользователь успешно отредактирован') +# redirect_to = request.POST.get('next') +# return redirect(redirect_to) +# else: +# if form.errors: +# messages.info(request, ( +# '

Произошла ошибка (form)

' +# '
{form}
' +# ).format(form=pformat(form.errors))) +# +# context.update({'form': form}) +# return render(request, self.template_name, context) class UserProfileEditViewFull(BaseMixin, View): form_class = UserProfileEditFullForm + fin_info_form_class = UserFinancialInfoEditForm template_name = 'user_profile_edit.html' def dispatch(self, request, *args, **kwargs): @@ -125,9 +126,14 @@ class UserProfileEditViewFull(BaseMixin, View): context = self.get_context_data(**_.merge({}, request.GET, kwargs)) form = self.form_class(instance=request.user) + fin_info_form = self.fin_info_form_class(request=request, instance=request.user.financial_info, + prefix='fin_info') # import code # code.interact(local=dict(globals(), **locals())) - context.update({'form': form}) + context.update({ + 'form': form, + 'fin_info_form': fin_info_form + }) context.update({ 'RESIDENCIES': UserFinancialInfo.RESIDENCIES, 'LEGAL_STATUSES': UserFinancialInfo.LEGAL_STATUSES, @@ -138,6 +144,7 @@ class UserProfileEditViewFull(BaseMixin, View): def post(self, request, *args, **kwargs): context = self.get_context_data(**kwargs) + # '1,3,4' --> ['1', '3', '4'] specs = tuple(filter(None, re.split(r'\s|,|;', request.POST.get('contractor_specializations', '')))) request.POST.setlist('contractor_specializations', specs) @@ -147,10 +154,20 @@ class UserProfileEditViewFull(BaseMixin, View): constructs = tuple(filter(None, re.split(r'\s|,|;', request.POST.get('contractor_construction_types', '')))) request.POST.setlist('contractor_construction_types', constructs) + print("!)request.POST = ", request.POST) + + # Отфильтровываем пустые значения + for key in request.POST.keys(): + request.POST.setlist(key, list(filter(lambda el: el, request.POST.getlist(key, '')))) + form = self.form_class(request.POST, request=request, instance=request.user) + print("2)request.POST = ", request.POST) + fin_info_form = self.fin_info_form_class(request.POST, request=request, + instance=request.user.financial_info, prefix='fin_info') - if form.is_valid(): + if form.is_valid() and fin_info_form.is_valid(): user = form.save() + fin_info = fin_info_form.save() live_image = form.cleaned_data.get('live_image') @@ -164,17 +181,22 @@ class UserProfileEditViewFull(BaseMixin, View): live_image.file.delete() live_image.delete() + user.financial_info = fin_info + user.save() + messages.info(request, 'Пользователь успешно отредактирован') redirect_to = request.POST.get('next') return redirect(redirect_to) else: - if form.errors: + if form.errors or fin_info_form.errors: messages.info(request, ( '

Произошла ошибка (form)

' '
{form}
' - ).format(form=pformat(form.errors))) + '

Произошла ошибка (fin_info_form)

' + '
{fin_info_form}
' + ).format(form=pformat(form.errors), fin_info_form=pformat(fin_info_form.errors))) - context.update({'form': form}) + context.update({'form': form, 'fin_info_form': fin_info_form}) return render(request, self.template_name, context)