|
|
|
@ -1,12 +1,16 @@ |
|
|
|
import json |
|
|
|
import json |
|
|
|
|
|
|
|
import re |
|
|
|
import pydash as _; |
|
|
|
import pydash as _; |
|
|
|
|
|
|
|
|
|
|
|
_.map = _.map_; |
|
|
|
_.map = _.map_; |
|
|
|
_.filter = _.filter_ |
|
|
|
_.filter = _.filter_ |
|
|
|
from pprint import pprint, pformat |
|
|
|
from pprint import pprint, pformat |
|
|
|
from django.shortcuts import render, redirect |
|
|
|
from django.shortcuts import render, redirect |
|
|
|
|
|
|
|
from django.conf import settings |
|
|
|
from django.contrib import messages |
|
|
|
from django.contrib import messages |
|
|
|
|
|
|
|
from django.db.models import Q |
|
|
|
from django.core.urlresolvers import reverse |
|
|
|
from django.core.urlresolvers import reverse |
|
|
|
|
|
|
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger |
|
|
|
from django.http import JsonResponse, HttpResponse |
|
|
|
from django.http import JsonResponse, HttpResponse |
|
|
|
from django.core.files.base import ContentFile |
|
|
|
from django.core.files.base import ContentFile |
|
|
|
from django.views.generic import ListView, DetailView, CreateView, View, \ |
|
|
|
from django.views.generic import ListView, DetailView, CreateView, View, \ |
|
|
|
@ -14,10 +18,10 @@ from django.views.generic import ListView, DetailView, CreateView, View, \ |
|
|
|
|
|
|
|
|
|
|
|
from projects.models import BuildingClassfication, ConstructionType |
|
|
|
from projects.models import BuildingClassfication, ConstructionType |
|
|
|
from .models import WorkSell, Picture, WorkSellPhoto |
|
|
|
from .models import WorkSell, Picture, WorkSellPhoto |
|
|
|
from .forms import WorkSellForm, ContractorWorkSellTrashForm |
|
|
|
from .forms import WorkSellForm, WorkSellFilterForm, ContractorWorkSellTrashForm |
|
|
|
from .serialize import serialize |
|
|
|
from .serialize import serialize |
|
|
|
from .response import JSONResponse, response_mimetype |
|
|
|
from .response import JSONResponse, response_mimetype |
|
|
|
|
|
|
|
from archilance.mixins import BaseMixin |
|
|
|
|
|
|
|
|
|
|
|
class PictureCreateView(CreateView): |
|
|
|
class PictureCreateView(CreateView): |
|
|
|
model = Picture |
|
|
|
model = Picture |
|
|
|
@ -63,15 +67,69 @@ class WorkSellsView(ListView): |
|
|
|
return context |
|
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorkSellFilterView(View): |
|
|
|
class WorkSellFilterView(BaseMixin,View): |
|
|
|
template_name = 'worksells_list.html' |
|
|
|
template_name = 'worksells_list.html' |
|
|
|
|
|
|
|
form_class = WorkSellFilterForm |
|
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
context = {} |
|
|
|
form = self.form_class(request.GET, request=request) |
|
|
|
|
|
|
|
context = self.get_context_data(**_.merge({}, request.GET,kwargs)) |
|
|
|
|
|
|
|
work_sells = WorkSell.objects |
|
|
|
|
|
|
|
if form.is_valid(): |
|
|
|
|
|
|
|
keywords = form.cleaned_data.get('keywords') |
|
|
|
|
|
|
|
specialization = form.cleaned_data.get('specialization') |
|
|
|
|
|
|
|
building_classification = form.cleaned_data.get('building_classification') |
|
|
|
|
|
|
|
construction_type = form.cleaned_data.get('construction_type') |
|
|
|
|
|
|
|
location = form.cleaned_data.get('location') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if keywords: |
|
|
|
|
|
|
|
keywords = tuple(filter(None, re.split(r'\s|,|;', keywords))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for k in keywords: |
|
|
|
|
|
|
|
work_sells = work_sells.filter(Q(name__icontains=k) | Q(text__icontains=k)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if specialization: |
|
|
|
|
|
|
|
work_sells = work_sells.filter( |
|
|
|
|
|
|
|
specialization__lft__gte=specialization.lft, |
|
|
|
|
|
|
|
specialization__rght__lte=specialization.rght, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if building_classification: |
|
|
|
|
|
|
|
work_sells = work_sells.filter(building_classification=building_classification) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if construction_type: |
|
|
|
|
|
|
|
work_sells = work_sells.filter(construction_type=construction_type) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if location: |
|
|
|
|
|
|
|
work_sells = work_sells.filter( |
|
|
|
|
|
|
|
location__lft__gte=location.lft, |
|
|
|
|
|
|
|
location__rght__lte=location.rght, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
paginator = Paginator(work_sells.all(), settings.PAGE_SIZE) |
|
|
|
|
|
|
|
page = request.GET.get('page') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
work_sells = paginator.page(page) |
|
|
|
|
|
|
|
except PageNotAnInteger: |
|
|
|
|
|
|
|
work_sells = paginator.page(1) |
|
|
|
|
|
|
|
except EmptyPage: |
|
|
|
|
|
|
|
work_sells = paginator.page(paginator.num_pages) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.update({ |
|
|
|
|
|
|
|
'form': form, |
|
|
|
|
|
|
|
'work_sells': work_sells, |
|
|
|
|
|
|
|
'is_paginated': True, |
|
|
|
|
|
|
|
'page_obj': work_sells, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return render(request, self.template_name, context) |
|
|
|
return render(request, self.template_name, context) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorkSellDetail(DetailView): |
|
|
|
class WorkSellDetail(DetailView): |
|
|
|
model = WorkSell |
|
|
|
model = WorkSell |
|
|
|
template_name = 'worksell_detail.html' |
|
|
|
template_name = 'worksell_detail.html' |
|
|
|
@ -87,7 +145,9 @@ def work_sell_create(request): |
|
|
|
form = WorkSellForm(data=request.POST) |
|
|
|
form = WorkSellForm(data=request.POST) |
|
|
|
if form.is_valid(): |
|
|
|
if form.is_valid(): |
|
|
|
instance = form.save(commit=False) |
|
|
|
instance = form.save(commit=False) |
|
|
|
|
|
|
|
# import code; code.interact(local=dict(globals(), **locals())) |
|
|
|
instance.save() |
|
|
|
instance.save() |
|
|
|
|
|
|
|
form.save_m2m() |
|
|
|
images_ids = request.POST.get('images-ids').split(';')[:-1] |
|
|
|
images_ids = request.POST.get('images-ids').split(';')[:-1] |
|
|
|
for pk in images_ids: |
|
|
|
for pk in images_ids: |
|
|
|
picture = Picture.objects.get(pk=pk) |
|
|
|
picture = Picture.objects.get(pk=pk) |
|
|
|
|