From 39c115a3a0b13a8141542bdce782448dfdac0b57 Mon Sep 17 00:00:00 2001 From: Slava Kyrachevsky Date: Thu, 2 Feb 2017 12:52:56 +0200 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B2=D0=BE=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D0=B9?= =?UTF-8?q?=20=D1=83=20=D0=BC=D0=B5=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/place_conference/models.py | 5 +- apps/place_exposition/models.py | 5 +- apps/place_exposition/views.py | 21 ++-- templates/client/includes/meta.html | 2 +- .../client/includes/place/place_list.html | 101 +++++++++--------- templates/client/place/place_detail.html | 2 +- 6 files changed, 69 insertions(+), 67 deletions(-) diff --git a/apps/place_conference/models.py b/apps/place_conference/models.py index 532c2461..1ebb4ee4 100644 --- a/apps/place_conference/models.py +++ b/apps/place_conference/models.py @@ -2,6 +2,7 @@ from django.db import models from django.contrib.contenttypes import generic from django.db.models.signals import post_save, pre_save +from django.utils import timezone from hvad.models import TranslatableModel, TranslatedFields, TranslationManager from functions.custom_fields import EnumField from functions.custom_fields import LocationField @@ -107,8 +108,8 @@ class PlaceConference(TranslatableModel, ExpoMixin): return '/places' def get_events_number(self): - exp = Conference.objects.filter(place=self) - return len(exp) + return Conference.objects.filter(place=self, + data_begin__gt=timezone.now()).count() def events(self): events = Conference.objects.filter(place=self)[:6] diff --git a/apps/place_exposition/models.py b/apps/place_exposition/models.py index 24f3a533..9632908c 100644 --- a/apps/place_exposition/models.py +++ b/apps/place_exposition/models.py @@ -4,6 +4,7 @@ from django.db.models import Q from django.contrib.contenttypes import generic from django.db.models.signals import post_save, pre_save from django.utils.translation import ugettext as _ +from django.utils import timezone from functools import partial from django.conf import settings from django.core.urlresolvers import reverse @@ -255,8 +256,8 @@ class PlaceExposition(TranslatableModel, ExpoMixin): return duplicate def get_events_number(self): - exp = Exposition.objects.filter(place=self) - return len(exp) + return Exposition.objects.filter(place=self, + data_begin__gt=timezone.now()).count() class Hall(TranslatableModel): diff --git a/apps/place_exposition/views.py b/apps/place_exposition/views.py index 286c3262..fae2ac85 100644 --- a/apps/place_exposition/views.py +++ b/apps/place_exposition/views.py @@ -10,11 +10,12 @@ from django.template import RequestContext from django.utils import translation from django.utils.translation import ugettext as _ from django.views.generic import DetailView, FormView +from django.utils import timezone from functions.cache_mixin import CacheMixin, JitterCacheMixin from functions.custom_views import ListView from meta.views import MetadataMixin from place_conference.models import PlaceConference - +from exposition.models import Exposition from .models import PlaceExposition @@ -131,15 +132,12 @@ class PlaceList(JitterCacheMixin, MetadataMixin, ListView): paginate_by = settings.CLIENT_PAGINATION template_name = 'client/place/place_list.html' - def get_queryset(self): - #qs = super(PlaceList, self).get_queryset().order_by('-rating') - qs= PlaceExposition.objects.language().select_related('country', 'city').all().order_by('-rating') - conf_qs = PlaceConference.objects.language().all() + qs = PlaceExposition.objects.language().select_related('country', 'city').order_by('-rating') + conf_qs = PlaceConference.objects.language().select_related('country', 'city') return list(qs)+list(conf_qs) - class PlaceCatalogBy(JitterCacheMixin, MetadataMixin, ListView): cache_range = [60*30, 60*60] template_name = 'client/place/catalog_by.html' @@ -232,20 +230,27 @@ class PlaceCityCatalog(PlaceCatalog): return context -class PlaceExpositionListView(ListView): +class PlaceExpositionListView(MetadataMixin, JitterCacheMixin, ListView): """ Представление перечня событий относительно места. Переход на эту страницу происходит со страницы подробного просмотра места, по ссылке "Все события" """ template_name = 'client/place/place_exposition_list.html' + cache_range = settings.CACHE_RANGE def get_object(self): slug = self.kwargs.get('slug') return get_object_or_404(PlaceExposition, url=slug) def get_queryset(self): - return self.get_object().exposition_place.all() + return Exposition.objects.filter( + place=self.get_object(), data_begin__gte=timezone.now() + ).select_related( + 'country', 'city' + ).prefetch_related( + 'tag' + ) def get_context_data(self, **kwargs): ctx = super(PlaceExpositionListView, self).get_context_data(**kwargs) diff --git a/templates/client/includes/meta.html b/templates/client/includes/meta.html index cfcbc5f7..aca926aa 100644 --- a/templates/client/includes/meta.html +++ b/templates/client/includes/meta.html @@ -32,6 +32,6 @@ {% else %} {% block title_head %}{% trans 'Expomap — выставки, конференции, семинары' %}{% endblock %} - + {% endif %} diff --git a/templates/client/includes/place/place_list.html b/templates/client/includes/place/place_list.html index 11a5ed46..4e5a3eff 100644 --- a/templates/client/includes/place/place_list.html +++ b/templates/client/includes/place/place_list.html @@ -1,61 +1,56 @@ -{% load static %} -{% load i18n %} +{% load static i18n %} -{% with objects=object_list %} - {% include 'client/includes/banners/tops.html' %} - -{% endwith %} + {% if forloop.counter == 10 %} + {% include 'client/includes/banners/catalog_inner.html' %} + {%endif %} + {% endfor %} + diff --git a/templates/client/place/place_detail.html b/templates/client/place/place_detail.html index 0b06f805..c82a8a2d 100644 --- a/templates/client/place/place_detail.html +++ b/templates/client/place/place_detail.html @@ -114,7 +114,7 @@ {% endif %} - {# TODO: request optization #} + {# TODO: request optimization #} {% if object.halls.count %}