количество событий у мест

remotes/origin/HEAD
Slava Kyrachevsky 9 years ago
parent 88184cfb2d
commit 39c115a3a0
  1. 5
      apps/place_conference/models.py
  2. 5
      apps/place_exposition/models.py
  3. 21
      apps/place_exposition/views.py
  4. 15
      templates/client/includes/place/place_list.html
  5. 2
      templates/client/place/place_detail.html

@ -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]

@ -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):

@ -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)

@ -1,7 +1,5 @@
{% load static %}
{% load i18n %}
{% load static i18n %}
{% with objects=object_list %}
{% include 'client/includes/banners/tops.html' %}
<ul class="cat-list cl-places">
{% for object in object_list %}
@ -9,9 +7,7 @@
<div class="cl-item-wrap clearfix">
<a target="_blank" href="{{ object.get_permanent_url }}">
<div class="cli-pict">
{% with obj=object %}
{% include 'client/includes/show_logo.html' %}
{% endwith %}
{% include 'client/includes/show_logo.html' with obj=object %}
</div>
</a>
<div class="cli-info">
@ -19,7 +15,7 @@
<header>
<div class="cli-title"><a target="_blank" href="{{ object.get_permanent_url }}">{{ object.name|safe }}</a></div>
<!--<div class="cli-rate">{{ object.rating }}</div>-->
{# <div class="cli-rate">{{ object.rating }}</div>#}
</header>
<div class="cli-descr">{{ object.get_type }}</div>
@ -38,7 +34,7 @@
<div class="cli-m-buttons">
<a class="button icon-info" href="{{ object.get_permanent_url }}">{% trans 'описание' %}</a>
{% if object.get_events_number %}
<a class="button green icon-list" href="#">{% trans 'события' %} ({{ object.get_events_number }})</a>
<a class="button green icon-list" href="{% url 'place_exposition_list' object.url %}">{% trans 'события' %} ({{ object.get_events_number }})</a>
{% endif %}
{% if object.photogallery %}
<a class="button blue icon-photo" href="{{ object.get_permanent_url }}photo/">{% trans 'фото' %}</a>
@ -49,7 +45,7 @@
</div>
</div>
</li>
{% if forloop.counter == 5 or objects|length < 5 %}
{% if forloop.counter == 5 or object_list|length < 5 %}
{% include 'client/includes/banners/catalog_inner_2.html' %}
{% endif %}
@ -58,4 +54,3 @@
{%endif %}
{% endfor %}
</ul>
{% endwith %}

@ -114,7 +114,7 @@
</div>
{% endif %}
{# TODO: request optization #}
{# TODO: request optimization #}
{% if object.halls.count %}
<div class="eni-areas clearfix">
<div class="enis-col">

Loading…
Cancel
Save