|
|
|
|
@ -42,51 +42,39 @@ class ContractorFilterView(BaseMixin, View): |
|
|
|
|
contractors = User.contractor_objects |
|
|
|
|
|
|
|
|
|
if form.is_valid(): |
|
|
|
|
# keywords = form.cleaned_data.get('keywords') |
|
|
|
|
# cro = form.cleaned_data.get('cro') |
|
|
|
|
# work_type = form.cleaned_data.get('work_type') |
|
|
|
|
cro = form.cleaned_data.get('cro') |
|
|
|
|
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') |
|
|
|
|
|
|
|
|
|
work_type = form.cleaned_data.get('work_type') |
|
|
|
|
build_classif = form.cleaned_data.get('building_classification') |
|
|
|
|
constr_type = form.cleaned_data.get('construction_type') |
|
|
|
|
|
|
|
|
|
# if keywords: |
|
|
|
|
# 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) |
|
|
|
|
contractors = contractors.filter(cro=cro) |
|
|
|
|
|
|
|
|
|
if specialization: |
|
|
|
|
contractors = contractors.filter( |
|
|
|
|
# specialization__lft__gte=specialization.lft, |
|
|
|
|
# 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: |
|
|
|
|
contractors = contractors.filter( |
|
|
|
|
location__lft__gte=location.lft, |
|
|
|
|
location__rght__lte=location.rght, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if work_type: |
|
|
|
|
contractors = contractors.filter(orders__project__work_type=work_type).distinct() # TODO: OK? |
|
|
|
|
|
|
|
|
|
if 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') |
|
|
|
|
# last_order_by = form.cleaned_data.get('last_order_by') |
|
|
|
|
@ -108,8 +96,6 @@ class ContractorFilterView(BaseMixin, View): |
|
|
|
|
# 'reverse_order': reverse_order, |
|
|
|
|
# }) |
|
|
|
|
|
|
|
|
|
# import code; code.interact(local=dict(globals(), **locals())) |
|
|
|
|
|
|
|
|
|
contr_count = contractors.count() |
|
|
|
|
display_msg = 'Найдено %s исполнителей' % contr_count if contr_count > 0 else 'Ничего не найдено' |
|
|
|
|
else: |
|
|
|
|
@ -120,12 +106,6 @@ class ContractorFilterView(BaseMixin, View): |
|
|
|
|
'<p>Произошла ошибка (form)</p>' |
|
|
|
|
'<pre>{form}</pre>' |
|
|
|
|
).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) |
|
|
|
|
@ -140,7 +120,6 @@ class ContractorFilterView(BaseMixin, View): |
|
|
|
|
|
|
|
|
|
context.update({ |
|
|
|
|
'form': form, |
|
|
|
|
# 'realty_form': realty_form, |
|
|
|
|
'contractors': contractors, |
|
|
|
|
'is_paginated': True, |
|
|
|
|
'page_obj': contractors, |
|
|
|
|
|