remotes/origin/setup
ArturBaybulatov 10 years ago
parent ec8da23d62
commit 6048dc1f89
  1. 1
      archilance/management/commands/tmp.py
  2. 1
      projects/models.py
  3. 13
      projects/templates/project_filter.html
  4. 42
      users/forms.py
  5. 31
      users/templates/contractor_filter.html
  6. 45
      users/views.py

@ -15,5 +15,6 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
for user in User.objects.all(): for user in User.objects.all():
user.location = Location.objects.root_nodes()[0].get_descendants().order_by('?').first() user.location = Location.objects.root_nodes()[0].get_descendants().order_by('?').first()
user.cro = _.sample((True, False))
user.save() user.save()

@ -20,6 +20,7 @@ TERMS = (
('month', 'За месяц'), ('month', 'За месяц'),
) )
class BuildingClassfication(models.Model): class BuildingClassfication(models.Model):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)

@ -191,13 +191,16 @@
<p class="textPro">{{ proj.text }}</p> <p class="textPro">{{ proj.text }}</p>
{% if TEMPLATE_DEBUG %} {% if TEMPLATE_DEBUG %}
<pre class="textPro"><!-- <pre><!--
-->{{ proj|inspect }}<br><!-- -->{{ proj|inspect }}<br><!--
--><br><!-- --><br><!--
-->Specialization: {{ proj.specialization }}<br><!-- --><b>Specialization:</b> {{ proj.specialization }}<br><!--
-->Realty location: {{ proj.realty.location }}<br><!-- --><br><!--
-->Constr. type: {{ proj.realty.construction_type }}<br><!-- --><b>Realty location:</b> {{ proj.realty.location }}<br><!--
-->Build. classif.: {{ proj.realty.building_classification }}<br><!-- --><br><!--
--><b>Constr. type:</b> {{ proj.realty.construction_type }}<br><!--
--><br><!--
--><b>Build. classif.:</b> {{ proj.realty.building_classification }}<br><!--
--></pre> --></pre>
{% endif %} {% endif %}

@ -1,9 +1,10 @@
from django import forms from django import forms
from django.forms import ModelForm from django.forms import ModelForm
import itertools
from .models import User, ContractorFinancialInfo from .models import User, ContractorFinancialInfo
from common.models import Location from common.models import Location
from projects.models import BuildingClassfication, ConstructionType from projects.models import Project, BuildingClassfication, ConstructionType
from specializations.models import Specialization from specializations.models import Specialization
@ -39,7 +40,7 @@ class UserEditForm(ModelForm):
} }
class ContractorFilterForm(forms.ModelForm): class ContractorFilterForm(forms.Form):
# PROJECT_ORDER_CHOICES = ( # "Упорядочить по"... # PROJECT_ORDER_CHOICES = ( # "Упорядочить по"...
# ('name', 'названию'), # ('name', 'названию'),
# ('budget', 'цене'), # ('budget', 'цене'),
@ -50,7 +51,6 @@ class ContractorFilterForm(forms.ModelForm):
# order_by = forms.ChoiceField(required=False, choices=PROJECT_ORDER_CHOICES) # order_by = forms.ChoiceField(required=False, choices=PROJECT_ORDER_CHOICES)
# last_order_by = forms.ChoiceField(required=False, choices=PROJECT_ORDER_CHOICES) # last_order_by = forms.ChoiceField(required=False, choices=PROJECT_ORDER_CHOICES)
# reverse_order = forms.BooleanField(required=False) # reverse_order = forms.BooleanField(required=False)
# keywords = forms.CharField(required=False, max_length=255)
specialization = forms.ModelChoiceField( specialization = forms.ModelChoiceField(
queryset=Specialization.objects.root_nodes()[0].get_descendants(), queryset=Specialization.objects.root_nodes()[0].get_descendants(),
@ -64,33 +64,29 @@ class ContractorFilterForm(forms.ModelForm):
building_classification = forms.ModelChoiceField( building_classification = forms.ModelChoiceField(
queryset=BuildingClassfication.objects, queryset=BuildingClassfication.objects,
widget=forms.Select(attrs={'class': 'selectpicker'}),
required=False, required=False,
empty_label='',
) )
class Meta: work_type = forms.ChoiceField(
model = User choices=tuple(itertools.chain((('',''),), Project.WORK_TYPES)),
widget=forms.Select(attrs={'class': 'selectpicker'}),
fields = ( required=False,
# 'cro', )
# 'specialization',
# 'work_type', construction_type = forms.ModelChoiceField(
) queryset=ConstructionType.objects,
widget=forms.Select(attrs={'class': 'selectpicker'}),
# widgets = { required=False,
# 'work_type': forms.Select(attrs={'class': 'selectpicker'}), empty_label='',
# } )
cro = forms.BooleanField(required=False)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request') self.request = kwargs.pop('request')
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
# self.fields['work_type'].choices = tuple(itertools.chain((('',''),), self.fields['work_type'].choices))
# self.fields['work_type'].required = False
# self.fields['work_type'].initial = ''
#
# self.fields['specialization'].required = False
#
# self.fields['specialization'].queryset = Specialization.objects.root_nodes()[0].get_descendants()
class ContractorFinancicalInfoForm(ModelForm): class ContractorFinancicalInfoForm(ModelForm):

@ -103,7 +103,8 @@
<div class="slideRes disTab activeSlide"> <div class="slideRes disTab activeSlide">
<div class="titleF1 disTab"> <div class="titleF1 disTab">
<div class="col-lg-3">Классификация здания</div> <div class="col-lg-3">Классификация здания</div>
{# <div class="col-lg-3">Вид строительства</div>#} <div class="col-lg-3">Тип работы</div>
<div class="col-lg-3">Вид строительства</div>
</div> </div>
<div class="polsF1 disTab"> <div class="polsF1 disTab">
@ -111,9 +112,18 @@
{{ form.building_classification }} {{ form.building_classification }}
</div> </div>
{# <div class="col-lg-3">#} <div class="col-lg-3">
{# {{ realty_form.construction_type }}#} {{ form.work_type }}
{# </div>#} </div>
<div class="col-lg-3">
{{ form.construction_type }}
</div>
<div class="col-lg-3">
<label>{{ form.cro }}<span></span></label>
<p>Требуется допуск (СРО)</p>
</div>
</div> </div>
</div> </div>
@ -236,10 +246,17 @@
{% if TEMPLATE_DEBUG %} {% if TEMPLATE_DEBUG %}
<div class="col-lg-12"> <div class="col-lg-12">
<pre><!-- <pre><!--
-->Specializations: {{ contractor.contractor_specializations.all }}<br><!-- --><b>Specializations:</b> {{ contractor.contractor_specializations.all }}<br><!--
--><br><!--
--><b>Location:</b> {{ contractor.location }}<br><!--
--><br><!--
--><b>Build. classif-s:</b> {% for o in contractor.orders.all %}{{ o.project.realty.building_classification }}, {% endfor %}<br><!--
--><br><!--
--><b>Constr. types:</b> {% for o in contractor.orders.all %}{{ o.project.realty.construction_type }}, {% endfor %}<br><!--
--><br><!--
--><b>CRO:</b> {{ contractor.cro }}<br><!--
--><br><!-- --><br><!--
-->Location: {{ contractor.location }}<br><!-- --><b>Work types:</b> {% for o in contractor.orders.all %}{{ o.project.work_type }}, {% endfor %}<br><!--
-->Build. classif.: {% for o in contractor.orders.all %}{{ o.project.realty.building_classification }},{% endfor %}<br><!--
--></pre> --></pre>
</div> </div>
{% endif %} {% endif %}

@ -42,51 +42,39 @@ class ContractorFilterView(BaseMixin, View):
contractors = User.contractor_objects contractors = User.contractor_objects
if form.is_valid(): if form.is_valid():
# keywords = form.cleaned_data.get('keywords') cro = form.cleaned_data.get('cro')
# 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 = form.cleaned_data.get('location') location = form.cleaned_data.get('location')
work_type = form.cleaned_data.get('work_type')
build_classif = form.cleaned_data.get('building_classification') build_classif = form.cleaned_data.get('building_classification')
constr_type = form.cleaned_data.get('construction_type')
# if keywords: contractors = contractors.filter(cro=cro)
# keywords = tuple(filter(None, re.split(r'\s|,|;', keywords)))
#
# for k in keywords:
# projects = projects.filter(Q(name__icontains=k) | Q(text__icontains=k))
#
# projects = projects.filter(cro=cro)
#
# if work_type:
# projects = projects.filter(work_type=work_type)
if specialization: if specialization:
contractors = contractors.filter( contractors = contractors.filter(
# specialization__lft__gte=specialization.lft, # specialization__lft__gte=specialization.lft,
# specialization__rght__lte=specialization.rght, # specialization__rght__lte=specialization.rght,
contractor_specializations=specialization, contractor_specializations=specialization, # TODO: Honor the hierarchical data structure
) )
# if building_classification:
# projects = projects.filter(realty__building_classification=building_classification)
#
# if construction_type:
# projects = projects.filter(realty__construction_type=construction_type)
if location: if location:
contractors = contractors.filter( contractors = contractors.filter(
location__lft__gte=location.lft, location__lft__gte=location.lft,
location__rght__lte=location.rght, location__rght__lte=location.rght,
) )
if work_type:
contractors = contractors.filter(orders__project__work_type=work_type).distinct() # TODO: OK?
if build_classif: if build_classif:
contractors = contractors.filter(orders__project__realty__building_classification=build_classif) contractors = contractors.filter(orders__project__realty__building_classification=build_classif)
if constr_type:
contractors = contractors.filter(orders__project__realty__construction_type=constr_type)
# import code; code.interact(local=dict(globals(), **locals()))
# order_by = form.cleaned_data.get('order_by') # order_by = form.cleaned_data.get('order_by')
# last_order_by = form.cleaned_data.get('last_order_by') # last_order_by = form.cleaned_data.get('last_order_by')
@ -108,8 +96,6 @@ class ContractorFilterView(BaseMixin, View):
# 'reverse_order': reverse_order, # 'reverse_order': reverse_order,
# }) # })
# import code; code.interact(local=dict(globals(), **locals()))
contr_count = contractors.count() contr_count = contractors.count()
display_msg = 'Найдено %s исполнителей' % contr_count if contr_count > 0 else 'Ничего не найдено' display_msg = 'Найдено %s исполнителей' % contr_count if contr_count > 0 else 'Ничего не найдено'
else: else:
@ -120,12 +106,6 @@ class ContractorFilterView(BaseMixin, View):
'<p>Произошла ошибка (form)</p>' '<p>Произошла ошибка (form)</p>'
'<pre>{form}</pre>' '<pre>{form}</pre>'
).format(form=pformat(form.errors))) ).format(form=pformat(form.errors)))
# if realty_form and realty_form.errors:
# messages.info(request, (
# '<p>Произошла ошибка (realty_form)</p>'
# '<pre>{realty_form}</pre>'
# ).format(realty_form=pformat(realty_form.errors)))
paginator = Paginator(contractors.all(), settings.PAGE_SIZE) paginator = Paginator(contractors.all(), settings.PAGE_SIZE)
@ -140,7 +120,6 @@ class ContractorFilterView(BaseMixin, View):
context.update({ context.update({
'form': form, 'form': form,
# 'realty_form': realty_form,
'contractors': contractors, 'contractors': contractors,
'is_paginated': True, 'is_paginated': True,
'page_obj': contractors, 'page_obj': contractors,

Loading…
Cancel
Save