1326: Этап №3 - Рубрикатор раздела «Места»

done
remotes/origin/search
Alexander Burdeiny 10 years ago
parent 80c88f6357
commit ed095384dc
  1. 26
      country/manager.py
  2. 25
      functions/models_methods.py
  3. 1
      place_exposition/models.py
  4. 36
      place_exposition/urls.py
  5. 71
      place_exposition/views.py
  6. 2
      templates/client/base_catalog.html
  7. 13
      templates/client/includes/side_places.html
  8. 44
      templates/client/place/catalog_by.html

@ -50,6 +50,32 @@ class CountryManager(TranslationManager):
cache.set(key, countries, self.cache_time)
return countries
def place_countries_with_count(self, cached=True):
lang = translation.get_language()
key = 'used_place_countries_count_%s'%lang
cached_countries = cache.get(key)
if cached and cached_countries:
return cached_countries
else:
from place_exposition.models import PlaceExposition
sql = {'place_count':
"""SELECT COUNT(*)
FROM place_exposition_placeexposition
WHERE place_exposition_placeexposition.country_id = country_country.id
AND place_exposition_placeexposition.is_published = 1"""}
now = datetime.datetime.now().date()
# id of unique countries
countries_id = set(
PlaceExposition.objects\
.filter(is_published=True)\
.values_list('country_id', flat=True)
)
countries = set(list(self.language().filter(id__in=countries_id).extra(select=sql)))
countries = sorted(countries, key=lambda x: x.name)
cache.set(key, countries, self.cache_time)
return countries
def conference_countries_with_count(self, cached=True):
lang = translation.get_language()
key = 'used_conference_countries_count_%s'%lang

@ -106,6 +106,31 @@ class CityManager(TranslationManager):
cache.set(key, cities, self.cache_time)
return cities
def place_cities_with_count(self, cached=True):
lang = translation.get_language()
key = 'used_place_cities_count_%s' % lang
if cached and key in cache:
cached_cities = cache.get(key)
return cached_cities
else:
from place_exposition.models import PlaceExposition
sql = {'place_count':
"""SELECT COUNT(*)
FROM place_exposition_placeexposition
WHERE place_exposition_placeexposition.city_id = city_city.id
AND place_exposition_placeexposition.is_published = 1"""}
now = datetime.datetime.now().date()
# id of unique countries
cities_id = set(
PlaceExposition.objects\
.filter(is_published=True)\
.values_list('city_id', flat=True)
)
cities = set(list(self.language().filter(id__in=cities_id).extra(select=sql)))
cities = sorted(cities, key=lambda x: x.name)
cache.set(key, cities, self.cache_time)
return cities
def conference_cities_with_count(self, cached=True):
lang = translation.get_language()
key = 'used_conference_cities_count_%s' % lang

@ -178,7 +178,6 @@ class PlaceExposition(TranslatableModel, ExpoMixin):
scheme = self.files.filter(purpose='scheme teritory')
return scheme
def events(self):
events = Exposition.objects.filter(place=self)[:6]
return events

@ -1,18 +1,30 @@
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, include, url
from views import PlaceDetail, PlaceList, PlaceCityCatalog, PlaceCountryCatalog, PlacePhoto
from django.conf.urls import include, patterns, url
from .views import (
PlaceCityCatalog,
PlaceCountryCatalog,
PlaceDetail,
PlaceList,
PlacePhoto,
PlaceByCountry,
PlaceByCity,
)
urlpatterns = patterns('',
url(r'country/(?P<slug>.*)/page/(?P<page>\d+)/$', PlaceCountryCatalog.as_view(), {'meta_id': 49}),
url(r'country/(?P<slug>.*)/$', PlaceCountryCatalog.as_view(), {'meta_id': 49}),
url(r'city/(?P<slug>.*)/page/(?P<page>\d+)/$', PlaceCityCatalog.as_view(), {'meta_id': 48}),
url(r'city/(?P<slug>.*)/$', PlaceCityCatalog.as_view(), {'meta_id': 48}),
url(r'(?P<slug>.*)/photo/page/(?P<page>\d+)/$', PlacePhoto.as_view(), {'meta_id': 91}),
url(r'(?P<slug>.*)/photo/$', PlacePhoto.as_view(), {'meta_id': 91}),
url(r'page/(?P<page>\d+)/$', PlaceList.as_view(), {'meta_id': 46}),
url(r'(?P<slug>.*)/$', PlaceDetail.as_view(), {'meta_id': 47}),
url(r'$', PlaceList.as_view(), {'meta_id':46}),
url(r'^country/$', PlaceByCountry.as_view(), {'meta_id': 49}),
url(r'^country/(?P<slug>.*)/page/(?P<page>\d+)/$', PlaceCountryCatalog.as_view(), {'meta_id': 49}),
url(r'^country/(?P<slug>.*)/$', PlaceCountryCatalog.as_view(), {'meta_id': 49}),
url(r'^city/$', PlaceByCity.as_view(), {'meta_id': 48}),
url(r'^city/(?P<slug>.*)/page/(?P<page>\d+)/$', PlaceCityCatalog.as_view(), {'meta_id': 48}),
url(r'^city/(?P<slug>.*)/$', PlaceCityCatalog.as_view(), {'meta_id': 48}),
url(r'^(?P<slug>.*)/photo/page/(?P<page>\d+)/$', PlacePhoto.as_view(), {'meta_id': 91}),
url(r'^(?P<slug>.*)/photo/$', PlacePhoto.as_view(), {'meta_id': 91}),
url(r'^page/(?P<page>\d+)/$', PlaceList.as_view(), {'meta_id': 46}),
url(r'^(?P<slug>.*)/$', PlaceDetail.as_view(), {'meta_id': 47}),
url(r'^$', PlaceList.as_view(), {'meta_id':46}),
)

@ -1,22 +1,21 @@
# -*- coding: utf-8 -*-
from django.shortcuts import render_to_response
from django.views.generic import DetailView, FormView
from functions.custom_views import ListView
from django.utils import translation
from django.http import HttpResponseRedirect, HttpResponse
from django.template import RequestContext
from city.models import City
from country.models import Country
from django.conf import settings
from django.core.context_processors import csrf
from django.http import Http404
from django.shortcuts import get_object_or_404
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
from django.utils import translation
from django.utils.translation import ugettext as _
#models
from place_conference.models import PlaceConference
from country.models import Country
from city.models import City
from models import PlaceExposition
from django.views.generic import DetailView, FormView
from functions.cache_mixin import CacheMixin, JitterCacheMixin
from functions.custom_views import ListView
from meta.views import MetadataMixin
from django.conf import settings
from functions.cache_mixin import JitterCacheMixin, CacheMixin
from place_conference.models import PlaceConference
from .models import PlaceExposition
def catalog(request):
@ -140,6 +139,46 @@ class PlaceList(JitterCacheMixin, MetadataMixin, ListView):
return list(qs)+list(conf_qs)
class PlaceCatalogBy(JitterCacheMixin, MetadataMixin, ListView):
cache_range = [60*30, 60*60]
template_name = 'client/place/catalog_by.html'
title1 = '' # bread_scrumbs
title2 = '' # page_title
"""
abstact class
"""
def get_context_data(self, **kwargs):
context = super(PlaceCatalogBy, self).get_context_data(**kwargs)
context.update({
'title1': self.title1,
'title2': self.title2,
'catalog': self.catalog,
'place_catalog': '/places/'
})
return context
class PlaceByCountry(PlaceCatalogBy):
model = Country
title1 = _(u'По странам')
title2 = _(u'Места по странам')
catalog = 'country/'
def get_queryset(self):
return self.model.objects.place_countries_with_count()
class PlaceByCity(PlaceCatalogBy):
model = City
title1 = _(u'По городам')
title2 = _(u'Места по городам')
catalog = 'city/'
def get_queryset(self):
return self.model.used.place_cities_with_count()
class PlaceCatalog(JitterCacheMixin, MetadataMixin, ListView):
cache_range = settings.CACHE_RANGE
model = PlaceExposition
@ -190,4 +229,4 @@ class PlaceCityCatalog(PlaceCatalog):
def get_context_data(self, **kwargs):
context = super(PlaceCityCatalog, self).get_context_data(**kwargs)
context['city'] = str(self.kwargs['city'].id)
return context
return context

@ -27,6 +27,8 @@
{% include 'client/includes/announces.html' %}
{% include 'client/includes/side_confs.html' %}
{% include 'client/includes/side_places.html' %}
{% include 'client/includes/banners/aside_2.html' %}

@ -0,0 +1,13 @@
{% load i18n %}
<div class="mps-sect">
<header>{% trans 'Места' %}</header>
<nav>
<ul>
<li><a href="/places/country/">{% trans 'По странам' %}</a></li>
<li><a href="/places/city/">{% trans 'По городам' %}</a></li>
<li><a href="/places/city/moscow/">{% trans 'Конференции в Москве' %}</a></li>
<li><a href="/places/city/saint-petersburg/">{% trans 'Конференции в Петербурге' %}</a></li>
<li><a href="/places/country/russia/">{% trans 'Конференции в России' %}</a></li>
</ul>
</nav>
</div>

@ -0,0 +1,44 @@
{% extends 'base_catalog.html' %}
{% load static %}
{% load i18n %}
{% load template_filters %}
{% block style %}
<link rel="stylesheet" href="{% static 'client/css/pages/exposition_by.css' %}">
{% endblock %}
{% block bread_scrumbs %}
<div class="bread-crumbs">
<a href="/">{% trans 'Главная страница' %}</a>
<a href="{{ place_catalog }}">{% trans 'Места' %}</a>
<strong>{{ title1 }}</strong>
</div>
{% endblock %}
{% block page_title %}
<div class="page-title">
<h1>{{ title2 }}:</h1>
</div>
{% endblock %}
{% block content_list %}
{% with objects=object_list %}
{% for obj in objects %}
{% set cur_word = obj.name %}
{% if cur_word|slice:":1"|lower != prev_word|slice:":1"|lower and forloop.counter != 1 %}
</ul>
{% endif %}
{% if cur_word|slice:":1"|lower != prev_word|slice:":1"|lower %}
<ul class="leter-list">
<div class="leter"><font size="5">{{ cur_word|slice:":1"|upper }}</font></div>
{% endif %}
<li>
<a href="{{ place_catalog }}{{ catalog }}{{ obj.url }}/">{{ obj.name }}&nbsp;({{ obj.place_count }})</a>
</li>
{% set prev_word = obj.name %}
{% endfor %}
{% endwith %}
{% endblock %}
Loading…
Cancel
Save