From 0e2af5ffa389af4f73bb413a0360076767751e19 Mon Sep 17 00:00:00 2001 From: Andrey Baydashkin Date: Sat, 15 Oct 2016 16:54:23 +0300 Subject: [PATCH] PR-11 --- assets/index.js | 4 +- users/forms.py | 15 ++ users/migrations/0019_auto_20161014_2337.py | 27 ++++ users/models.py | 4 + users/templates/user_financial_info_edit.html | 3 + users/templates/user_profile_edit.html | 148 ++++++++++-------- users/urls.py | 1 + users/views.py | 12 +- 8 files changed, 150 insertions(+), 64 deletions(-) create mode 100644 users/migrations/0019_auto_20161014_2337.py diff --git a/assets/index.js b/assets/index.js index 5f1fea7..f156436 100644 --- a/assets/index.js +++ b/assets/index.js @@ -311,8 +311,10 @@ $('[data-tooltip]').tooltip({ }()) +// Contractor experience ------------------------------- - +$('.profile-building-classifications select').select2({width: 450, placeholder: 'Выберите типы зданий'}); +$('.profile-construction-types select').select2({width: 450, placeholder: 'Выберите виды строительства'}); diff --git a/users/forms.py b/users/forms.py index ade4f21..bc4cc27 100644 --- a/users/forms.py +++ b/users/forms.py @@ -104,6 +104,21 @@ class UserProfileBasicInfoEditForm(forms.ModelForm): super().__init__(*args, **kwargs) +class UserProfileExperienceEditForm(UserProfileBasicInfoEditForm): + class Meta: + model = User + + fields = ( + 'contractor_specializations', + 'first_name', + 'last_name', + 'location', + 'patronym', + 'contractor_building_classifications', + 'contractor_construction_types', + ) + + class UserFinancialInfoEditForm(forms.ModelForm): class Meta: model = UserFinancialInfo diff --git a/users/migrations/0019_auto_20161014_2337.py b/users/migrations/0019_auto_20161014_2337.py new file mode 100644 index 0000000..b487963 --- /dev/null +++ b/users/migrations/0019_auto_20161014_2337.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-10-15 15:37 +from __future__ import unicode_literals + +from django.db import migrations, models +import mptt.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0046_merge'), + ('users', '0018_auto_20160913_0215'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='contractor_building_classifications', + field=mptt.fields.TreeManyToManyField(blank=True, related_name='contractors', to='projects.BuildingClassfication'), + ), + migrations.AddField( + model_name='user', + name='contractor_construction_types', + field=models.ManyToManyField(blank=True, related_name='contractors', to='projects.ConstructionType'), + ), + ] diff --git a/users/models.py b/users/models.py index 65871f5..d82c0ce 100644 --- a/users/models.py +++ b/users/models.py @@ -129,6 +129,10 @@ class User(AbstractBaseUser, PermissionsMixin): contractor_resume = models.OneToOneField(ContractorResume, related_name='contractor', blank=True, null=True) contractor_specializations = TreeManyToManyField(Specialization, related_name='contractors', blank=True) contractor_status = models.CharField(default='free', max_length=20, choices=STATUSES) + contractor_building_classifications = TreeManyToManyField('projects.BuildingClassfication', + related_name='contractors', blank=True) + contractor_construction_types = models.ManyToManyField('projects.ConstructionType', related_name='contractors', + blank=True) created = models.DateTimeField(default=timezone.now) cro = models.BooleanField(default=False) date_joined = models.DateTimeField(default=timezone.now) diff --git a/users/templates/user_financial_info_edit.html b/users/templates/user_financial_info_edit.html index 60eefc6..5ffb2d5 100644 --- a/users/templates/user_financial_info_edit.html +++ b/users/templates/user_financial_info_edit.html @@ -112,6 +112,9 @@
Общая информация Финансовая информация + {% if request.user.is_contractor %} + Опыт + {% endif %}
diff --git a/users/templates/user_profile_edit.html b/users/templates/user_profile_edit.html index 684f46a..d88cf7e 100644 --- a/users/templates/user_profile_edit.html +++ b/users/templates/user_profile_edit.html @@ -21,7 +21,7 @@
-
+ {% csrf_token %} {% if request.user.is_customer %} @@ -110,80 +110,106 @@
-
-
Дата рождения
-
Пол
-
Статус
-
- -
-
- {{ form.date_of_birth }} + {% if request.experience_edit %} +
+
Классификация зданий
+
Виды строительства
- -
- {% for id, text in form.gender.field.choices %} - - -

{{ text }}    

- {% endfor %} + +
+
+ {{ form.contractor_building_classifications }} +
+ +
+ {{ form.contractor_construction_types }} +
- -
- {{ form.contractor_status }} + + -
- -
-
Сайт
-
Skype
-
Телефон
-
Второй телефон
-
- -
-
- + {% else %} +
+
Дата рождения
+
Пол
+
Статус
- -
- + +
+
+ {{ form.date_of_birth }} +
+ +
+ {% for id, text in form.gender.field.choices %} + + +

{{ text }}    

+ {% endfor %} +
+ +
+ {{ form.contractor_status }} +
- -
- + +
+
Сайт
+
Skype
+
Телефон
+
Второй телефон
- -
- + +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
-
- -
-
- -

Есть допуск СРО

+ +
+
+ +

Есть допуск СРО

+
-
- - + + + {% endif %}
diff --git a/users/urls.py b/users/urls.py index aefc753..6b03c9a 100755 --- a/users/urls.py +++ b/users/urls.py @@ -28,6 +28,7 @@ app_name = 'users' urlpatterns = [ urls.url(r'^(?P\d+)/edit/$', UserProfileEditView.as_view(), name='user-profile-edit'), urls.url(r'^(?P\d+)/financial-info/edit/$', UserFinancialInfoEditView.as_view(), name='user-financial-info-edit'), + urls.url(r'^(?P\d+)/experience/edit/$', UserProfileEditView.as_view(), name='user-experience-edit'), urls.url(r'^customers/(?P\d+)/$', CustomerProfileOpenProjectsView.as_view(), name='customer-profile-open-projects'), urls.url(r'^customers/(?P\d+)/trashed-projects/$', CustomerProfileTrashedProjectsView.as_view(), name='customer-profile-trashed-projects'), diff --git a/users/views.py b/users/views.py index 25e48be..8ed1323 100644 --- a/users/views.py +++ b/users/views.py @@ -39,6 +39,7 @@ from .forms import ( UserFinancialInfoEditForm, UserProfileBasicInfoEditForm, UserProfileEditForm, + UserProfileExperienceEditForm, ) @@ -47,6 +48,11 @@ class UserProfileEditView(BaseMixin, View): 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: @@ -239,10 +245,12 @@ class ContractorFilterView(BaseMixin, View): contractors = contractors.filter(orders__project__work_type=work_type) if build_classif: - contractors = contractors.filter(orders__project__realty__building_classification=build_classif) + contractors = contractors.filter(Q(orders__project__realty__building_classification=build_classif) | + Q(contractor_building_classifications=build_classif)) if constr_type: - contractors = contractors.filter(orders__project__realty__construction_type=constr_type) + contractors = contractors.filter(Q(orders__project__realty__construction_type=constr_type) | + Q(contractor_construction_types=constr_type)) if get_teams: teams = Team.objects.all()