From b990914d5174d0bc3ad6355c2d0bc64b9afc075e Mon Sep 17 00:00:00 2001 From: Kotiuk Nazarii Date: Wed, 2 Sep 2015 00:20:25 +0300 Subject: [PATCH] Pre deployed commit --- expobanner/forms.py | 4 +- expobanner/models.py | 5 ++ expobanner/utils.py | 55 ++++++++++++++++--- expobanner/views.py | 28 ++-------- exposition/views.py | 16 +----- templates/client/exposition/catalog.html | 3 - .../client/exposition/catalog_theme.html | 5 -- .../client/includes/banners/aside_2.html | 20 +++++++ .../includes/banners/catalog_inner.html | 23 ++++++++ .../client/includes/banners/detail_inner.html | 24 +++++++- templates/client/includes/banners/header.html | 9 +++ 11 files changed, 138 insertions(+), 54 deletions(-) diff --git a/expobanner/forms.py b/expobanner/forms.py index f489d731..5c3b6473 100644 --- a/expobanner/forms.py +++ b/expobanner/forms.py @@ -164,13 +164,13 @@ class TopCreateForm(forms.ModelForm): theme_ids = self.cleaned_data['theme'] if theme_ids: return Theme.objects.filter(id__in=theme_ids) - return None + return Theme.objects.none() def clean_country(self): country_ids = self.cleaned_data['country'] if country_ids: return Country.objects.filter(id__in=country_ids) - return None + return Country.objects.none() def clean_exposition(self): expo_id = self.cleaned_data['exposition'] diff --git a/expobanner/models.py b/expobanner/models.py index e543b29e..b49c914f 100644 --- a/expobanner/models.py +++ b/expobanner/models.py @@ -255,6 +255,11 @@ class Top(models.Model, StatMixin): class Meta: ordering = ['position'] + def get_event(self): + try: + return self.exposition_set.all()[0] + except IndexError: + return None class TopStat(models.Model): date = models.DateField() diff --git a/expobanner/utils.py b/expobanner/utils.py index a7a9cd53..9c4222a2 100644 --- a/expobanner/utils.py +++ b/expobanner/utils.py @@ -21,22 +21,21 @@ def get_by_sort(banner_list): def get_banner_by_params(banners_list, urls, params): - #print('START. NUMBER of queries = %d'%len(connection.queries)) thematic_banners = [] url_banners = [] for banner in banners_list: - #print('-------------------------') - #print('number of queries = %d'%len(connection.queries)) - # check by theme banner_theme_ids = [str(theme.id) for theme in banner.theme.all()] - #print('number of queries = %d'%len(connection.queries)) - if banner_theme_ids: if params.get('theme'): theme = params['theme'] - if theme in banner_theme_ids: + + flag = False + for th in theme: + if th in banner_theme_ids: + flag = True + if flag: thematic_banners.append(banner) continue # check by country @@ -63,7 +62,7 @@ def get_banner_by_params(banners_list, urls, params): if common_urls: url_banners.append(banner) continue - print('-------------------------') + if thematic_banners: return random.choice(thematic_banners) if url_banners: @@ -71,3 +70,43 @@ def get_banner_by_params(banners_list, urls, params): return None #print('END. NUMBER of queries = %d'%len(connection.queries)) + +def get_top_events(tops, params): + catalog = params.get('catalog') + country = params.get('country', '') + theme = params.get('theme', []) + city = params.get('city', '') + tag = params.get('tag', '') + catalog_tops = [item for item in tops if item.catalog == catalog] + good_tops = [] + for top in catalog_tops: + + country_ids = [str(item.id) for item in top.country.all()] + theme_ids = [str(item.id) for item in top.theme.all()] + excluded_tags_ids = [str(item.id) for item in top.excluded_tags.all()] + excluded_cities_ids = [str(item.id) for item in top.excluded_cities.all()] + if not country_ids and not theme_ids: + # universal top + good_tops.append(top) + continue + # check country + if country in country_ids and city not in excluded_cities_ids : + good_tops.append(top) + continue + # check theme + if tag in excluded_tags_ids: + continue + flag = False + for th in theme: + if th in theme_ids: + flag = True + continue + if flag: + good_tops.append(top) + sorted_top = sorted(good_tops, key=lambda x: x.position) + events = [] + for top in sorted_top: + event = top.get_event() + if event: + events.append(event) + return events \ No newline at end of file diff --git a/expobanner/views.py b/expobanner/views.py index d0e38527..96540cdc 100644 --- a/expobanner/views.py +++ b/expobanner/views.py @@ -3,8 +3,10 @@ import json import re from django.http import HttpResponse from django.shortcuts import redirect, get_object_or_404 +from django.shortcuts import render_to_response +from django.template import RequestContext from .models import Banner, BannerGroup, URL, Top -from expobanner.utils import get_by_sort, get_banner_by_params, get_client_ip +from expobanner.utils import get_by_sort, get_banner_by_params, get_client_ip, get_top_events def click(request, banner_id): @@ -32,7 +34,7 @@ def get_banners(request): elif url == u.url: good_urls.append(u) # fill parameters dict - params = {'theme': request.GET.get('theme'), + params = {'theme': request.GET.getlist('theme', []), 'tag': request.GET.get('tag'), 'country': request.GET.get('country'), 'city': request.GET.get('city'), @@ -69,25 +71,8 @@ def get_banners(request): return HttpResponse(json.dumps(result, indent=4), content_type='application/json') -def get_top_events(tops, params): - catalog = params.get('catalog') - country = params.get('country', '') - theme = params.get('theme', []) - good_tops = [] - for top in tops: - - if top.catalog != catalog: - continue - country_ids = [str(item.id) for item in top.country.all()] - if not country in country_ids: - continue - - -from exposition.models import Exposition -from django.shortcuts import render_to_response -from django.template import RequestContext def get_top(request): - params = {'theme': request.GET.get('theme'), + params = {'theme': request.GET.getlist('theme', []), 'tag': request.GET.get('tag'), 'country': request.GET.get('country'), 'city': request.GET.get('city'), @@ -95,6 +80,5 @@ def get_top(request): tops = Top.cached.all() events = get_top_events(tops, params) - expos = Exposition.objects.filter(top__isnull=False) - context = {'objects': expos} + context = {'objects': events} return render_to_response('client/includes/exposition/expo_top.html', context, context_instance=RequestContext(request)) \ No newline at end of file diff --git a/exposition/views.py b/exposition/views.py index b6464599..721bd91c 100644 --- a/exposition/views.py +++ b/exposition/views.py @@ -303,7 +303,6 @@ class ExpoCatalog(MetadataMixin, ListView): month = None country = None city = None - paid = None def get_filtered_qs(self): # diferent for views @@ -355,8 +354,6 @@ class ExpoCatalog(MetadataMixin, ListView): def get_context_data(self, **kwargs): context = super(ExpoCatalog, self).get_context_data(**kwargs) - if self.paid: - context['paid'] = self.paid context['search_form'] = self.search_form context['filter_object'] = self.filter_object context['year'] = self.year @@ -411,11 +408,8 @@ class ExpoThemeCatalog(ExpoCatalog): city_slug = self.kwargs.get('city_slug') theme = get_object_or_404(Theme, url=slug) self.kwargs['theme'] = theme + qs = self.model.enable.upcoming().filter(theme=theme) - qs = self.model.enable.upcoming().filter(theme=theme).exclude(paid__isnull=False) - paid= list(self.model.enable.filter(theme=theme).filter(paid__isnull=False)) - if paid: - self.paid = paid if country_slug: country = get_object_or_404(Country, url=country_slug) self.country = country @@ -449,11 +443,7 @@ class ExpoTagCatalog(ExpoCatalog): slug = self.kwargs.get('slug') tag = get_object_or_404(Tag, url=slug) self.kwargs['tag'] = tag - qs = self.model.enable.upcoming().filter(tag=tag).exclude(paid__isnull=False) - paid= list(self.model.enable.filter(tag=tag).filter(paid__isnull=False)) - if paid: - self.paid = paid - + qs = self.model.enable.upcoming().filter(tag=tag) self.filter_object = tag return qs @@ -550,7 +540,7 @@ from django.core.mail import send_mail from django.core.mail import EmailMessage def send_to_organiser(request, slug): exposition = get_object_or_404(Exposition, url=slug) - mail_send = exposition.paid.organiser + mail_send = 'evm@expomap.ru' name = request.POST.get('person_inf') email = request.POST.get('person') phone = request.POST.get('phone', '') diff --git a/templates/client/exposition/catalog.html b/templates/client/exposition/catalog.html index de61d7eb..cb8941dc 100644 --- a/templates/client/exposition/catalog.html +++ b/templates/client/exposition/catalog.html @@ -33,9 +33,6 @@ {% endblock %} {% block content_list %} - {% if paid %} - {% include 'includes/exposition/expo_list_paid.html' with object_list=paid %} - {% endif %} {% include 'includes/exposition/exposition_list.html' with object_list=object_list %} {% endblock %} diff --git a/templates/client/exposition/catalog_theme.html b/templates/client/exposition/catalog_theme.html index ec72ee80..8d199340 100644 --- a/templates/client/exposition/catalog_theme.html +++ b/templates/client/exposition/catalog_theme.html @@ -49,18 +49,13 @@ {% block page_title %}
- {#

{% trans 'Выставки' %}: {{ filter_object.name }}

#}

{% if meta %}{{ meta.h1 }}{% else %}{% trans 'Выставки' %}: {{ filter_object.name }}{% endif %}

- {% include 'includes/exposition/catalog_filter_period.html' %} {% endblock %} {% block content_list %} - {% if paid %} - {% include 'includes/exposition/exposition_list.html' with object_list=paid %} - {% endif %} {% include 'includes/exposition/exposition_list.html' with object_list=object_list %} {% endblock %} diff --git a/templates/client/includes/banners/aside_2.html b/templates/client/includes/banners/aside_2.html index 9fdc80bd..439bfe68 100644 --- a/templates/client/includes/banners/aside_2.html +++ b/templates/client/includes/banners/aside_2.html @@ -1,4 +1,24 @@
+ + +
\ No newline at end of file diff --git a/templates/client/includes/banners/catalog_inner.html b/templates/client/includes/banners/catalog_inner.html index 591ea030..ccf1add4 100644 --- a/templates/client/includes/banners/catalog_inner.html +++ b/templates/client/includes/banners/catalog_inner.html @@ -1,3 +1,26 @@
+
\ No newline at end of file diff --git a/templates/client/includes/banners/detail_inner.html b/templates/client/includes/banners/detail_inner.html index fe2082ea..6d0760aa 100644 --- a/templates/client/includes/banners/detail_inner.html +++ b/templates/client/includes/banners/detail_inner.html @@ -1,3 +1,25 @@
- +
\ No newline at end of file diff --git a/templates/client/includes/banners/header.html b/templates/client/includes/banners/header.html index 41416632..89c7f5a2 100644 --- a/templates/client/includes/banners/header.html +++ b/templates/client/includes/banners/header.html @@ -1,3 +1,12 @@
+ + + +
\ No newline at end of file