|
|
|
|
@ -9,8 +9,11 @@ from django.http import HttpResponseForbidden, HttpResponseRedirect, HttpRespons |
|
|
|
|
from django.shortcuts import render, get_object_or_404, redirect |
|
|
|
|
from django.views.generic import ListView, DetailView, CreateView, DeleteView, View, UpdateView, TemplateView, FormView |
|
|
|
|
from django.views.generic.base import ContextMixin |
|
|
|
|
from hitcount.models import HitCount |
|
|
|
|
from hitcount.views import HitCountMixin |
|
|
|
|
from pprint import pprint, pformat |
|
|
|
|
import json |
|
|
|
|
import natsort |
|
|
|
|
import pydash as _; _.map = _.map_; _.filter = _.filter_ |
|
|
|
|
import re |
|
|
|
|
|
|
|
|
|
@ -45,6 +48,9 @@ class ProjectDetailWithAnswerView(BaseMixin, View): |
|
|
|
|
project = get_object_or_404(Project, pk=kwargs.get('pk')) |
|
|
|
|
context.update({'project': project}) |
|
|
|
|
|
|
|
|
|
hit_count = HitCount.objects.get_for_object(project) |
|
|
|
|
HitCountMixin.hit_count(request, hit_count) |
|
|
|
|
|
|
|
|
|
if request.user.is_authenticated() and request.user.is_contractor(): |
|
|
|
|
project_answers = project.answers.all() |
|
|
|
|
contractor = request.user |
|
|
|
|
@ -244,9 +250,9 @@ class ProjectFilterView(BaseMixin, View): |
|
|
|
|
for k in keywords: |
|
|
|
|
projects = projects.filter(Q(name__icontains=k) | Q(text__icontains=k)) |
|
|
|
|
|
|
|
|
|
# projects = projects.filter(cro=cro) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if cro: |
|
|
|
|
projects = projects.filter(cro=cro) |
|
|
|
|
|
|
|
|
|
if work_type: |
|
|
|
|
projects = projects.filter(work_type=work_type) |
|
|
|
|
|
|
|
|
|
@ -279,7 +285,12 @@ class ProjectFilterView(BaseMixin, View): |
|
|
|
|
elif last_order_by: |
|
|
|
|
ord = last_order_by |
|
|
|
|
|
|
|
|
|
if ord: |
|
|
|
|
manual_sort = None |
|
|
|
|
|
|
|
|
|
if ord and ord == 'views': |
|
|
|
|
projects = natsort.natsorted(projects.all(), key=lambda p: p.hit_count.hits, reverse=reverse_order) |
|
|
|
|
manual_sort = True |
|
|
|
|
elif ord: |
|
|
|
|
projects = projects.order_by('-%s' % ord if reverse_order else ord) |
|
|
|
|
|
|
|
|
|
context.update({ |
|
|
|
|
@ -287,7 +298,7 @@ class ProjectFilterView(BaseMixin, View): |
|
|
|
|
'reverse_order': reverse_order, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
project_count = projects.count() |
|
|
|
|
project_count = len(projects) if manual_sort else projects.count() |
|
|
|
|
display_msg = 'Найдено %s проектов' % project_count if project_count > 0 else 'Ничего не найдено' |
|
|
|
|
else: |
|
|
|
|
display_msg = 'Пожалуйста, введите корректные данные' |
|
|
|
|
@ -304,7 +315,7 @@ class ProjectFilterView(BaseMixin, View): |
|
|
|
|
'<pre>{realty_form}</pre>' |
|
|
|
|
).format(realty_form=pformat(realty_form.errors))) |
|
|
|
|
|
|
|
|
|
paginator = Paginator(projects.all(), settings.PAGE_SIZE) |
|
|
|
|
paginator = Paginator(projects if manual_sort else projects.all(), settings.PAGE_SIZE) |
|
|
|
|
page = request.GET.get('page') |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|