|
|
|
|
@ -1,14 +1,17 @@ |
|
|
|
|
import json |
|
|
|
|
from pprint import pprint, pformat |
|
|
|
|
import pydash as _ |
|
|
|
|
|
|
|
|
|
from django.conf import settings |
|
|
|
|
from django.contrib import messages |
|
|
|
|
from django.contrib.auth.mixins import PermissionRequiredMixin, LoginRequiredMixin |
|
|
|
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger |
|
|
|
|
from django.core.urlresolvers import reverse, reverse_lazy |
|
|
|
|
from django.db.models import Q |
|
|
|
|
from django.http import HttpResponseForbidden, HttpResponseRedirect, HttpResponse, Http404 |
|
|
|
|
from django.shortcuts import render, get_object_or_404, redirect |
|
|
|
|
from django.views.generic import ListView, DetailView, CreateView, View, UpdateView, TemplateView, FormView |
|
|
|
|
from django.views.generic.base import ContextMixin |
|
|
|
|
from pprint import pprint, pformat |
|
|
|
|
import json |
|
|
|
|
import pydash as _ |
|
|
|
|
import re |
|
|
|
|
|
|
|
|
|
from .mixins import LastAccessMixin |
|
|
|
|
from .models import Project, ProjectFile, Portfolio, Candidate, Answer, Realty, Order |
|
|
|
|
@ -28,6 +31,7 @@ from .forms import ( |
|
|
|
|
RealtyForm, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProjectFilterView(BaseMixin, View): |
|
|
|
|
template_name = 'project_filter.html' |
|
|
|
|
form_class = ProjectFilterForm |
|
|
|
|
@ -37,11 +41,11 @@ class ProjectFilterView(BaseMixin, View): |
|
|
|
|
form = self.form_class(request.GET, request=request) |
|
|
|
|
realty_form = self.realty_form(request.GET, request=request, prefix='realty_form') |
|
|
|
|
context = self.get_context_data(**_.merge({}, request.GET, kwargs)) |
|
|
|
|
display_msg = 'Список проектов' |
|
|
|
|
|
|
|
|
|
projects = Project.objects |
|
|
|
|
|
|
|
|
|
if form.is_valid() and realty_form.is_valid(): |
|
|
|
|
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') |
|
|
|
|
@ -50,9 +54,16 @@ class ProjectFilterView(BaseMixin, View): |
|
|
|
|
construction_type = realty_form.cleaned_data.get('construction_type') |
|
|
|
|
location = realty_form.cleaned_data.get('location') |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
if work_type: |
|
|
|
|
projects = projects.filter(work_type=work_type) |
|
|
|
|
|
|
|
|
|
if specialization: |
|
|
|
|
projects = projects.filter( |
|
|
|
|
@ -60,8 +71,11 @@ class ProjectFilterView(BaseMixin, View): |
|
|
|
|
specialization__rght__lte=specialization.rght, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if building_classification: projects = projects.filter(realty__building_classification=building_classification) |
|
|
|
|
if construction_type: projects = projects.filter(realty__construction_type=construction_type) |
|
|
|
|
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( |
|
|
|
|
@ -69,6 +83,26 @@ class ProjectFilterView(BaseMixin, View): |
|
|
|
|
realty__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') |
|
|
|
|
|
|
|
|
|
if order_by: |
|
|
|
|
if order_by == last_order_by: |
|
|
|
|
reverse_order = not reverse_order |
|
|
|
|
else: |
|
|
|
|
reverse_order = False |
|
|
|
|
|
|
|
|
|
projects = projects.order_by('-%s' % order_by if reverse_order else order_by) |
|
|
|
|
last_order_by = order_by |
|
|
|
|
elif last_order_by: |
|
|
|
|
projects = projects.order_by('-%s' % last_order_by if reverse_order else last_order_by) |
|
|
|
|
|
|
|
|
|
context.update({ |
|
|
|
|
'last_order_by': last_order_by, |
|
|
|
|
'reverse_order': reverse_order, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
project_count = projects.count() |
|
|
|
|
display_msg = 'Найдено %s проектов' % project_count if project_count > 0 else 'Ничего не найдено' |
|
|
|
|
else: |
|
|
|
|
@ -86,17 +120,24 @@ class ProjectFilterView(BaseMixin, View): |
|
|
|
|
'<pre>{realty_form}</pre>' |
|
|
|
|
).format(realty_form=pformat(realty_form.errors))) |
|
|
|
|
|
|
|
|
|
order_by = request.GET.get('order_by') # TODO: Validate |
|
|
|
|
|
|
|
|
|
if order_by: |
|
|
|
|
projects = projects.order_by(order_by) |
|
|
|
|
paginator = Paginator(projects.all(), settings.PAGE_SIZE) |
|
|
|
|
page = request.GET.get('page') |
|
|
|
|
|
|
|
|
|
projects = projects[:10] |
|
|
|
|
try: |
|
|
|
|
projects = paginator.page(page) |
|
|
|
|
except PageNotAnInteger: |
|
|
|
|
projects = paginator.page(1) |
|
|
|
|
except EmptyPage: |
|
|
|
|
projects = paginator.page(paginator.num_pages) |
|
|
|
|
|
|
|
|
|
# import code; code.interact(local=dict(globals(), **locals())) |
|
|
|
|
|
|
|
|
|
context.update({ |
|
|
|
|
'form': form, |
|
|
|
|
'realty_form': realty_form, |
|
|
|
|
'projects': projects, |
|
|
|
|
'is_paginated': True, |
|
|
|
|
'display_msg': display_msg, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
@ -157,6 +198,8 @@ class CustomerProjectCreateView(BaseMixin, View): |
|
|
|
|
project.save() |
|
|
|
|
form.save_m2m() |
|
|
|
|
|
|
|
|
|
Order.objects.create(project=project) |
|
|
|
|
|
|
|
|
|
for file in request.FILES.getlist('new_files'): |
|
|
|
|
proj_file = ProjectFile.objects.create(file=file, project=project) |
|
|
|
|
proj_file.save() |
|
|
|
|
|