From 6a12f2dd621ef16fe4a7c75810248e0cffd9629f Mon Sep 17 00:00:00 2001 From: ArturBaybulatov Date: Thu, 14 Jul 2016 20:00:34 +0300 Subject: [PATCH] #ARC-21 --- .../management/commands/generate_projects.py | 7 ++- .../management/commands/generate_users.py | 2 + archilance/management/commands/tmp.py | 19 +++++++ projects/models.py | 20 +++---- reviews/models.py | 6 +- users/forms.py | 1 + users/models.py | 56 +++++++++---------- users/templates/contractor_filter.html | 39 ++++++++++++- users/views.py | 53 ++++++++++-------- work_sell/models.py | 16 +++--- 10 files changed, 142 insertions(+), 77 deletions(-) create mode 100644 archilance/management/commands/tmp.py diff --git a/archilance/management/commands/generate_projects.py b/archilance/management/commands/generate_projects.py index 66f6846..7ff5779 100644 --- a/archilance/management/commands/generate_projects.py +++ b/archilance/management/commands/generate_projects.py @@ -74,7 +74,12 @@ class Command(BaseCommand): project.save() - Order.objects.create(project=project) + Order.objects.create( + project=project, + contractor=_.sample((None, User.contractor_objects.order_by('?').first())), + secure=_.sample((True, False)), + status=_.sample((True, False)), + ) return project diff --git a/archilance/management/commands/generate_users.py b/archilance/management/commands/generate_users.py index 17b5c19..50963e8 100644 --- a/archilance/management/commands/generate_users.py +++ b/archilance/management/commands/generate_users.py @@ -6,6 +6,7 @@ import pydash as _; _.map = _.map_; _.filter = _.filter_ import random from archilance import util +from common.models import Location from specializations.models import Specialization from users.models import User, GENDERS @@ -95,5 +96,6 @@ class Command(BaseCommand): user.set_password('123') user.groups.add(customer_group if user.pk % 2 == 0 else contractor_group) user.contractor_specializations = Specialization.objects.order_by('?')[:_.random(1, 5)] + user.location = Location.objects.root_nodes()[0].get_descendants().order_by('?').first() user.save() diff --git a/archilance/management/commands/tmp.py b/archilance/management/commands/tmp.py new file mode 100644 index 0000000..1258132 --- /dev/null +++ b/archilance/management/commands/tmp.py @@ -0,0 +1,19 @@ +from django.contrib.auth.models import Group, Permission +from django.contrib.contenttypes.models import ContentType +from django.core.management import BaseCommand +from django.utils import timezone +import pydash as _; _.map = _.map_; _.filter = _.filter_ +import random + +from archilance import util +from common.models import Location +from projects.models import Project, Order, CURRENCIES, TERMS, Specialization, Realty +from users.models import User + + +class Command(BaseCommand): + def handle(self, *args, **options): + for user in User.objects.all(): + user.location = Location.objects.root_nodes()[0].get_descendants().order_by('?').first() + + user.save() diff --git a/projects/models.py b/projects/models.py index 4e9f3eb..24e5e3f 100644 --- a/projects/models.py +++ b/projects/models.py @@ -80,16 +80,16 @@ class Project(models.Model): cro = models.BooleanField(default=False) currency = models.CharField(max_length=20, default='rur', choices=CURRENCIES) customer = models.ForeignKey(User, related_name='projects') + deal_type = models.CharField(max_length=20, default='secure_deal', choices=DEAL_TYPES) name = models.CharField(max_length=255) price_and_term_required = models.BooleanField(default=False) realty = models.ForeignKey(Realty, blank=True, null=True, related_name='projects') - deal_type = models.CharField(max_length=20, default='secure_deal', choices=DEAL_TYPES) specialization = TreeForeignKey(Specialization, related_name='projects') + state = models.CharField(default='active', max_length=20, choices=STATES) term = models.IntegerField(default=0) term_type = models.CharField(max_length=20, choices=TERMS, default='hour') text = models.TextField(blank=True) work_type = models.IntegerField(default=1, choices=WORK_TYPES) - state = models.CharField(default='active', max_length=20, choices=STATES) def __str__(self): return self.name @@ -116,13 +116,13 @@ class ProjectFile(models.Model): class Answer(models.Model): budget = models.DecimalField(max_digits=10, decimal_places=0) - currency = models.CharField(max_length=5, choices=CURRENCIES, default='rur') + contractor = models.ForeignKey(User, related_name='answers') created = models.DateTimeField(default=timezone.now) + currency = models.CharField(max_length=5, choices=CURRENCIES, default='rur') project = models.ForeignKey(Project, related_name='answers') term = models.IntegerField(default=0) term_type = models.CharField(max_length=10, choices=TERMS, default='hour') text = models.TextField() - contractor = models.ForeignKey(User, related_name='answers') def __str__(self): return self.text @@ -179,18 +179,18 @@ class Candidate(models.Model): class Portfolio(models.Model): - description = models.TextField() - name = models.CharField(max_length=255) budget = models.DecimalField(max_digits=10, decimal_places=0, default=0, null=True, blank=True) + building_classification = models.ForeignKey(BuildingClassfication, related_name='portfolios',null=True, blank=True) + construction_type = models.ForeignKey(ConstructionType, related_name='portfolios',null=True, blank=True) currency = models.CharField(max_length=20, default='rur', choices=CURRENCIES, null=True, blank=True) + description = models.TextField() + location = TreeForeignKey('common.Location', related_name='portfolios', null=True, blank=True) + name = models.CharField(max_length=255) specialization = TreeForeignKey(Specialization, related_name='portfolios',null=True, blank=True) term = models.IntegerField(default=0,null=True, blank=True) term_type = models.CharField(max_length=20, choices=TERMS, default='hour',null=True, blank=True) - building_classification = models.ForeignKey(BuildingClassfication, related_name='portfolios',null=True, blank=True) - construction_type = models.ForeignKey(ConstructionType, related_name='portfolios',null=True, blank=True) - location = TreeForeignKey('common.Location', related_name='portfolios', null=True, blank=True) - worksell = models.BooleanField(default=False) user = models.ForeignKey(User, related_name='portfolios') + worksell = models.BooleanField(default=False) def __str__(self): return self.name diff --git a/reviews/models.py b/reviews/models.py index db574df..7d2d623 100644 --- a/reviews/models.py +++ b/reviews/models.py @@ -2,11 +2,11 @@ from django.db import models from django.core.validators import MaxValueValidator, MinValueValidator class Review(models.Model): - text = models.TextField() + is_secured = models.BooleanField(default=False) project = models.ForeignKey("projects.Project", related_name='reviews') - user = models.ForeignKey("users.User", related_name='reviews') stars = models.IntegerField(validators=[MinValueValidator(1), MaxValueValidator(5)]) - is_secured = models.BooleanField(default=False) + text = models.TextField() + user = models.ForeignKey("users.User", related_name='reviews') def __str__(self): return self.pk diff --git a/users/forms.py b/users/forms.py index 00a2b26..81904f9 100644 --- a/users/forms.py +++ b/users/forms.py @@ -98,6 +98,7 @@ class ContractorFinancicalInfoForm(ModelForm): class Meta: model = ContractorFinancialInfo + fields = ( 'fio', 'date_of_birth', diff --git a/users/models.py b/users/models.py index 7535ff7..2e51b55 100644 --- a/users/models.py +++ b/users/models.py @@ -55,20 +55,20 @@ class ContractorFinancialInfo(models.Model): ('legal_entity', 'ИП и юридическое лицо'), ) - fio = models.CharField(max_length=255) + credit_card_number = models.CharField(max_length=50) date_of_birth = models.DateTimeField() - phone = models.CharField(max_length=30) - residency = models.CharField(max_length=50, choices=RESIDENCIES) + fio = models.CharField(max_length=255) + inn = models.CharField(max_length=100) legal_status = models.CharField(max_length=30, choices=LEGAL_STATUSES) - passport_series = models.CharField(max_length=6) + passport_issue_date = models.DateTimeField() + passport_issued_by = models.CharField(max_length=255) passport_number = models.CharField(max_length=10) + 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) - passport_issued_by = models.CharField(max_length=255) - passport_issue_date = models.DateTimeField() - inn = models.CharField(max_length=100) yandex_money = models.CharField(max_length=50) - credit_card_number = models.CharField(max_length=50) - passport_scan = models.ImageField(upload_to='users/contractors/') def __str__(self): return self.fio @@ -78,8 +78,8 @@ class ContractorFinancialInfo(models.Model): verbose_name_plural = 'Финансовая информация' class ContractorResume(models.Model): - text = models.TextField() resume_file = models.FileField(upload_to='users/resume/files/') + text = models.TextField() def __str__(self): return self.text @@ -96,11 +96,11 @@ RESUME_TYPE_FILES = ( class ContractorResumeFiles(models.Model): + description = models.TextField(blank=True) img = models.ImageField(upload_to='users/resume/images/') + resume = models.ForeignKey(ContractorResume, related_name='resume_files') title = models.CharField(max_length=255) - description = models.TextField(blank=True) type = models.CharField(max_length=50, choices=RESUME_TYPE_FILES) - resume = models.ForeignKey(ContractorResume, related_name='resume_files') def __str__(self): return self.title @@ -116,27 +116,27 @@ class User(AbstractBaseUser, PermissionsMixin): ('busy', 'Занят'), ) - username = models.CharField(max_length=50, unique=True) - first_name = models.CharField(max_length=255, blank=True) - last_name = models.CharField(max_length=255, blank=True) - patronym = models.CharField(max_length=255, blank=True) - email = models.EmailField(max_length=255, unique=True, db_index=True) - is_active = models.BooleanField(default=True) + avatar = models.ImageField(upload_to='users/avatars/', blank=True) + contractor_financial_info = models.OneToOneField(ContractorFinancialInfo, related_name='contractor', blank=True, null=True) + 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) created = models.DateTimeField(default=timezone.now) + cro = models.BooleanField(default=False) date_joined = models.DateTimeField(default=timezone.now) + date_of_birth = models.DateTimeField(null=True, blank=True) + email = models.EmailField(max_length=255, unique=True, db_index=True) + first_name = models.CharField(max_length=255, blank=True) + gender = models.CharField(max_length=30, choices=GENDERS, blank=True) + is_active = models.BooleanField(default=True) + last_name = models.CharField(max_length=255, blank=True) last_time_visit = models.DateTimeField(default=timezone.now) - contractor_specializations = TreeManyToManyField(Specialization, related_name='contractors', blank=True) - contractor_status = models.CharField(default='free', max_length=20, choices=STATUSES) - contractor_financial_info = models.OneToOneField(ContractorFinancialInfo, related_name='contractor',blank=True, null=True) - contractor_resume = models.OneToOneField(ContractorResume, related_name='contractor', blank=True, null=True) location = TreeForeignKey('common.Location', related_name='users', null=True, blank=True) + patronym = models.CharField(max_length=255, blank=True) + phone = models.CharField(max_length=30, blank=True, null=True) skype = models.CharField(max_length=100, blank=True) - gender = models.CharField(max_length=30, choices=GENDERS, blank=True) - cro = models.BooleanField(default=False) + username = models.CharField(max_length=50, unique=True) website = models.CharField(max_length=255, blank=True) - date_of_birth = models.DateTimeField(null=True,blank=True) - avatar = models.ImageField(upload_to='users/avatars/', blank=True) - phone = models.CharField(max_length=30, blank=True, null=True) @property def is_staff(self): @@ -180,8 +180,8 @@ class User(AbstractBaseUser, PermissionsMixin): class Team(models.Model): name = models.CharField(max_length=255) - users = models.ManyToManyField(User, related_name ='teams', blank=True) owner = models.OneToOneField(User, related_name='team', blank=True, null=True) + users = models.ManyToManyField(User, related_name ='teams', blank=True) # groups = models.ManyToManyField(Group, related_name='teams', blank=True) def __str__(self): diff --git a/users/templates/contractor_filter.html b/users/templates/contractor_filter.html index 1078567..827e5b7 100644 --- a/users/templates/contractor_filter.html +++ b/users/templates/contractor_filter.html @@ -9,7 +9,7 @@
-

Поиск исполнителей

+

{% if display_msg %}{{ display_msg }}{% else %}Поиск исполнителей{% endif %}

@@ -78,7 +78,7 @@ - +
@@ -93,6 +93,28 @@
+ + + + + + + +
+
+
Foooooooo
+
+ +
+
+ +
+
+
+ + + +
@@ -107,7 +129,7 @@
@@ -206,6 +228,17 @@
+ {% if TEMPLATE_DEBUG %} +
+
Specializations: {{ contractor.contractor_specializations.all }}

Location: {{ contractor.location }}
+
+ {% endif %} + +
diff --git a/users/views.py b/users/views.py index bdb68b7..05b1847 100644 --- a/users/views.py +++ b/users/views.py @@ -48,12 +48,12 @@ class ContractorFilterView(BaseMixin, View): # keywords = form.cleaned_data.get('keywords') # cro = form.cleaned_data.get('cro') # work_type = form.cleaned_data.get('work_type') - # specialization = form.cleaned_data.get('specialization') - # + specialization = form.cleaned_data.get('specialization') + # building_classification = realty_form.cleaned_data.get('building_classification') # construction_type = realty_form.cleaned_data.get('construction_type') - # location = realty_form.cleaned_data.get('location') - # + location = form.cleaned_data.get('location') + # if keywords: # keywords = tuple(filter(None, re.split(r'\s|,|;', keywords))) # @@ -64,25 +64,27 @@ class ContractorFilterView(BaseMixin, View): # # if work_type: # projects = projects.filter(work_type=work_type) - # - # if specialization: - # projects = projects.filter( - # specialization__lft__gte=specialization.lft, - # specialization__rght__lte=specialization.rght, - # ) - # + + if specialization: + contractors = contractors.filter( + # specialization__lft__gte=specialization.lft, + # specialization__rght__lte=specialization.rght, + + contractor_specializations=specialization, + ) + # if building_classification: # projects = projects.filter(realty__building_classification=building_classification) # # if construction_type: # projects = projects.filter(realty__construction_type=construction_type) - # - # if location: - # projects = projects.filter( - # realty__location__lft__gte=location.lft, - # realty__location__rght__lte=location.rght, - # ) - # + + if location: + contractors = contractors.filter( + location__lft__gte=location.lft, + location__rght__lte=location.rght, + ) + # order_by = form.cleaned_data.get('order_by') # last_order_by = form.cleaned_data.get('last_order_by') # reverse_order = form.cleaned_data.get('reverse_order') @@ -102,13 +104,13 @@ class ContractorFilterView(BaseMixin, View): # 'last_order_by': last_order_by, # 'reverse_order': reverse_order, # }) - # - # project_count = projects.count() - # display_msg = 'Найдено %s проектов' % project_count if project_count > 0 else 'Ничего не найдено' - messages.info(request, 'Форма норм') # Tmp + # import code; code.interact(local=dict(globals(), **locals())) + + contr_count = contractors.count() + display_msg = 'Найдено %s исполнителей' % contr_count if contr_count > 0 else 'Ничего не найдено' else: - # display_msg = 'Пожалуйста, введите корректные данные' + display_msg = 'Пожалуйста, введите корректные данные' if form.errors: messages.info(request, ( @@ -139,7 +141,7 @@ class ContractorFilterView(BaseMixin, View): 'contractors': contractors, 'is_paginated': True, 'page_obj': contractors, - # 'display_msg': display_msg, + 'display_msg': display_msg, }) return render(request, self.template_name, context) @@ -268,3 +270,6 @@ class ContractorFinancialInfoEdit(CheckForUserMixin, View): return redirect(reverse('users:contractor-financical', kwargs={'pk': request.user.pk})) return render(request, self.template_name, {'form': form}) + + +# import code; code.interact(local=dict(globals(), **locals())) diff --git a/work_sell/models.py b/work_sell/models.py index b02c11c..174a6d6 100644 --- a/work_sell/models.py +++ b/work_sell/models.py @@ -10,19 +10,19 @@ from specializations.models import Specialization class WorkSell(models.Model): - name = models.CharField(max_length=255) - description = models.TextField(blank=True) - img = ImageField(upload_to='worksell/worksell', null=True, blank=True) budget = models.DecimalField(max_digits=10, decimal_places=0, default=0, null=True, blank=True) + building_classification = models.ForeignKey(BuildingClassfication, related_name='worksells', null=True, blank=True) + construction_type = models.ForeignKey(ConstructionType, related_name='worksells', null=True, blank=True) + contractor = models.ForeignKey(User, related_name='work_sell') + created = models.DateTimeField(default=timezone.now, null=True, blank=True) currency = models.CharField(max_length=20, default='rur', choices=CURRENCIES, null=True, blank=True) + description = models.TextField(blank=True) + img = ImageField(upload_to='worksell/worksell', null=True, blank=True) + location = TreeForeignKey('common.Location', related_name='worksells', null=True, blank=True) + name = models.CharField(max_length=255) specialization = TreeForeignKey(Specialization, related_name='worksells', null=True, blank=True) term = models.IntegerField(default=0, null=True, blank=True) term_type = models.CharField(max_length=20, choices=TERMS, default='hour', null=True, blank=True) - contractor = models.ForeignKey(User, related_name='work_sell') - building_classification = models.ForeignKey(BuildingClassfication, related_name='worksells', null=True, blank=True) - construction_type = models.ForeignKey(ConstructionType, related_name='worksells', null=True, blank=True) - location = TreeForeignKey('common.Location', related_name='worksells', null=True, blank=True) - created = models.DateTimeField(default=timezone.now, null=True, blank=True) def __str__(self): return self.name