diff --git a/conference/views.py b/conference/views.py index 6e4eda6e..17c33c8c 100644 --- a/conference/views.py +++ b/conference/views.py @@ -19,7 +19,7 @@ from django.views.generic import DetailView from django.views.generic.edit import FormMixin from functions.cache_mixin import CacheMixin, JitterCacheMixin -from functions.custom_views import ListView +from functions.custom_views import ListView, ReverseOrderMixin from functions.views_help import get_side_items from functions.utils import CachedSting @@ -129,7 +129,7 @@ class ConferenceByCity(ConferenceBy): # .order_by('translations__name').distinct() -class ConferenceCatalog(ConfFilterMixin, ConfSectionKindMixin, JitterCacheMixin, MetadataMixin, ListView): +class ConferenceCatalog_(ConfFilterMixin, ConfSectionKindMixin, JitterCacheMixin, MetadataMixin, ListView): cache_range = settings.CACHE_RANGE model = Conference paginate_by = settings.CLIENT_PAGINATION @@ -201,13 +201,17 @@ class ConferenceCatalog(ConfFilterMixin, ConfSectionKindMixin, JitterCacheMixin, return qs.order_by('data_begin') def get_context_data(self, **kwargs): - context = super(ConferenceCatalog, self).get_context_data(**kwargs) + context = super(ConferenceCatalog_, self).get_context_data(**kwargs) context['filter_object'] = self.filter_object context['year'] = self.year context['month'] = self.month context['catalog_url'] = self.catalog_url return context +class ConferenceCatalog(ReverseOrderMixin, ConferenceCatalog_): + pass + + class ConferenceCountryCatalog(ConferenceCatalog): catalog_url = '/conference/country/' stat_kind = 'country' @@ -466,7 +470,7 @@ class ConferenceDetail(ObjectStatMixin, JitterCacheMixin, MetadataMixin, DetailV return context -class ConferenceList(ConfFilterMixin, ConfSectionMixin, MetadataMixin, JitterCacheMixin, ListView): +class ConferenceList(ReverseOrderMixin, ConfFilterMixin, ConfSectionMixin, MetadataMixin, JitterCacheMixin, ListView): cache_range = settings.CACHE_RANGE model = Conference paginate_by = settings.CLIENT_PAGINATION @@ -496,6 +500,8 @@ class ConferenceList(ConfFilterMixin, ConfSectionMixin, MetadataMixin, JitterCac 'link': '%s%s/%s/'%(self.catalog_url, year, month), 'slug': self.kwargs.get('month') } + if not qs.exists(): + qs = self.get_reversed_qs(qs) return qs def get_context_data(self, **kwargs): diff --git a/events/views.py b/events/views.py index 5d51439d..aee1c73f 100644 --- a/events/views.py +++ b/events/views.py @@ -7,6 +7,7 @@ from django.template import RequestContext from haystack.query import SearchQuerySet from functions.custom_views import ContextMixin +from functions.custom_views import ReverseOrderMixin from functions.custom_views import ListView from functions.http import JsonResponse @@ -16,7 +17,7 @@ from conference.models import Conference from .forms import FilterForm -class FilterListView(ContextMixin, FormMixin, ListView): +class FilterListView_(ContextMixin, FormMixin, ListView): initial_ctx = {'filtering': True} form_class = FilterForm paginate_by = settings.CLIENT_PAGINATION @@ -25,7 +26,7 @@ class FilterListView(ContextMixin, FormMixin, ListView): _ajax_form_template_name = 'includes/events/filter_form.html' def get_form_kwargs(self): - kwargs = super(FilterListView, self).get_form_kwargs() + kwargs = super(FilterListView_, self).get_form_kwargs() kwargs.update({'data': self.request.GET}) return kwargs @@ -60,13 +61,13 @@ class FilterListView(ContextMixin, FormMixin, ListView): return JsonResponse(data) # usual get - return super(FilterListView, self).get(request, *args, **kwargs) + return super(FilterListView_, self).get(request, *args, **kwargs) def post(self, request, *args, **kwargs): return self.get(request, *args, **kwargs) def get_context_data(self, **kwargs): - context = super(FilterListView, self).get_context_data(**kwargs) + context = super(FilterListView_, self).get_context_data(**kwargs) # get params for paginator get = self.form.data.copy() if 'page' in get: @@ -74,3 +75,6 @@ class FilterListView(ContextMixin, FormMixin, ListView): context['GETparams'] = get.urlencode() if hasattr(get, 'urlencode') else '' return context + +class FilterListView(ReverseOrderMixin, FilterListView_): + pass diff --git a/exposition/views.py b/exposition/views.py index b1df396a..83caae27 100644 --- a/exposition/views.py +++ b/exposition/views.py @@ -22,7 +22,7 @@ from django.views.generic import DetailView from django.views.generic.edit import FormMixin from functions.cache_mixin import JitterCacheMixin -from functions.custom_views import ExpoSearchView, ListView +from functions.custom_views import ExpoSearchView, ListView, ReverseOrderMixin from functions.search_forms import ExpositionSearchForm from functions.views_help import get_side_items from functions.utils import CachedSting @@ -132,7 +132,7 @@ class ExpositionByCity(ExpositionBy): # .order_by('translations__name').distinct() -class ExpositionSearchView(SearchFilterMixin, ExpoSearchView): +class ExpositionSearchView(ReverseOrderMixin, SearchFilterMixin, ExpoSearchView): #paginate_by = 10 template_name = 'client/exposition/search.html' search_form = ExpositionSearchForm @@ -350,7 +350,7 @@ class ExpositionServiceView(JitterCacheMixin, MetadataMixin, FormMixin, DetailVi return self.initial.copy() -class ExpoList(ExpoFilterMixin, ExpoSectionMixin, MetadataMixin, JitterCacheMixin, ListView): +class ExpoList_(ExpoFilterMixin, ExpoSectionMixin, MetadataMixin, JitterCacheMixin, ListView): cache_range = [60*30, 60*60] model = Exposition paginate_by = settings.CLIENT_PAGINATION @@ -382,14 +382,17 @@ class ExpoList(ExpoFilterMixin, ExpoSectionMixin, MetadataMixin, JitterCacheMixi return qs def get_context_data(self, **kwargs): - context = super(ExpoList, self).get_context_data(**kwargs) + context = super(ExpoList_, self).get_context_data(**kwargs) context['catalog_url'] = self.catalog_url context['year'] = self.year context['month'] = self.month return context +class ExpoList(ReverseOrderMixin, ExpoList_): + pass -class ExpoCatalog(ExpoFilterMixin, ExpoSectionKindMixin, JitterCacheMixin, MetadataMixin, ListView): + +class ExpoCatalog_(ExpoFilterMixin, ExpoSectionKindMixin, JitterCacheMixin, MetadataMixin, ListView): model = Exposition paginate_by = settings.CLIENT_PAGINATION template_name = 'client/exposition/catalog.html' @@ -452,7 +455,7 @@ class ExpoCatalog(ExpoFilterMixin, ExpoSectionKindMixin, JitterCacheMixin, Metad return qs.order_by('data_begin') def get_context_data(self, **kwargs): - context = super(ExpoCatalog, self).get_context_data(**kwargs) + context = super(ExpoCatalog_, self).get_context_data(**kwargs) context['filter_object'] = self.filter_object context['year'] = self.year context['month'] = self.month @@ -461,6 +464,9 @@ class ExpoCatalog(ExpoFilterMixin, ExpoSectionKindMixin, JitterCacheMixin, Metad context['tag_for_filter'] = self.kwargs['tag'] return context +class ExpoCatalog(ReverseOrderMixin, ExpoCatalog_): + pass + class ExpoCountryCatalog(ExpoCatalog): catalog_url = '/expo/country/' diff --git a/functions/custom_views.py b/functions/custom_views.py index acb4f081..e70ef018 100644 --- a/functions/custom_views.py +++ b/functions/custom_views.py @@ -1,11 +1,7 @@ # -*- coding: utf-8 -*- import random +from datetime import datetime -from accounts.models import User -from city.models import City -from company.models import Company -from conference.models import Conference -from country.models import Country from django.conf import settings from django.contrib.admin.views.decorators import staff_member_required from django.contrib.auth.decorators import login_required @@ -20,6 +16,7 @@ from django.core.paginator import ( from django.core.urlresolvers import reverse_lazy from django.db.models.deletion import ProtectedError from django.db.models.loading import get_model +from django.db.models.query import QuerySet from django.http import Http404, HttpResponse, HttpResponseRedirect from django.shortcuts import render_to_response from django.utils.translation import get_language as lang @@ -31,13 +28,20 @@ from django.views.generic.detail import ( SingleObjectTemplateResponseMixin ) from django.views.generic.edit import ModelFormMixin, ProcessFormView + +from accounts.models import User +from city.models import City +from company.models import Company +from conference.models import Conference +from country.models import Country from exposition.models import Exposition from file.forms import FileModelForm from file.models import TmpFile from functions.forms import AdminSearchForm from functions.views_help import split_params from functions.http import JsonResponse -from haystack.query import EmptySearchQuerySet +from haystack.query import EmptySearchQuerySet, SearchQuerySet +from haystack.backends import SearchNode from hvad.utils import get_translation_aware_manager from meta.models import MetaSetting from meta.views import Meta @@ -547,3 +551,39 @@ class ContextMixin(object): context = super(ContextMixin, self).get_context_data(**kwargs) context.update(self.extra_ctx) return context + + +class ReverseOrderMixin(ContextMixin): + def get_reversed_qs(self, qs): + # exclude_fields + ef = ['data_begin', 'data_end'] + children = list(filter(lambda x: not set([y[0].col for y in x.children]).intersection(ef), qs.query.where.children)) + qs.query.where.children = children + self.extra_ctx['events_reversed'] = True + return qs.filter(data_begin__lte=datetime.now()).order_by('-data_begin') + + def get_reversed_sqs(self, qs): + # exclude_fields + ef = ['data_begin'] + childrens = [] + for children in qs.query.query_filter.children: + if isinstance(children, tuple): + if children[0].startswith('data_begin'): + continue + elif isinstance(children, SearchNode): + node_childrens = list(filter(lambda x: not x[0].startswith('data_begin'), children.children)) + if node_childrens: + children.children = node_childrens + childrens.append(children) + qs.query.query_filter.children = childrens + self.extra_ctx['events_reversed'] = True + qs.query.clear_order_by() + return qs.filter(data_begin__lte=datetime.now()).order_by('-data_begin') + + def get_queryset(self): + qs = super(ReverseOrderMixin, self).get_queryset() + if isinstance(qs, SearchQuerySet) and qs.count() == 0: + qs = self.get_reversed_sqs(qs) + elif isinstance(qs, QuerySet) and not qs.exists(): + qs = self.get_reversed_qs(qs) + return qs diff --git a/support/dev/settings.py b/support/dev/settings.py index 2d16966b..b6bfbea5 100644 --- a/support/dev/settings.py +++ b/support/dev/settings.py @@ -256,9 +256,11 @@ SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True SOCIAL_AUTH_PIPELINE = ( 'social.pipeline.social_auth.social_details', 'social.pipeline.social_auth.social_uid', + 'functions.pipeline.get_email', # vk 'functions.pipeline.load_user', 'social.pipeline.social_auth.auth_allowed', 'social.pipeline.social_auth.social_user', + 'social.pipeline.social_auth.load_extra_data', 'social.pipeline.user.get_username', 'functions.pipeline.require_email', #'social.pipeline.mail.mail_validation', @@ -266,7 +268,6 @@ SOCIAL_AUTH_PIPELINE = ( #'social.pipeline.user.create_user', 'social.pipeline.social_auth.associate_by_email', 'social.pipeline.social_auth.associate_user', - 'social.pipeline.social_auth.load_extra_data', 'social.pipeline.user.user_details' ) @@ -513,6 +514,12 @@ C_CITY_CATALOG_KEY = 'conf_city_catalog' C_COUNTRY_CATALOG_KEY = 'conf_country_catalog' E_CITY_CATALOG_KEY = 'expo_city_catalog' E_COUNTRY_CATALOG_KEY = 'expo_country_catalog' +DEFAULT_DESCRIPTION = { + 'e_description_ru': 'templates/client/includes/conference/default_description_ru.html', + 'e_description_en': 'templates/client/includes/conference/default_description_en.html', + 'c_description_ru': 'templates/client/includes/exposition/default_description_ru.html', + 'c_description_en': 'templates/client/includes/exposition/default_description_en.html', +} try: from local import * diff --git a/support/prod/settings.py b/support/prod/settings.py index cb2159d5..b7f5956a 100644 --- a/support/prod/settings.py +++ b/support/prod/settings.py @@ -256,9 +256,11 @@ SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True SOCIAL_AUTH_PIPELINE = ( 'social.pipeline.social_auth.social_details', 'social.pipeline.social_auth.social_uid', + 'functions.pipeline.get_email', # vk 'functions.pipeline.load_user', 'social.pipeline.social_auth.auth_allowed', 'social.pipeline.social_auth.social_user', + 'social.pipeline.social_auth.load_extra_data', 'social.pipeline.user.get_username', 'functions.pipeline.require_email', #'social.pipeline.mail.mail_validation', @@ -266,7 +268,6 @@ SOCIAL_AUTH_PIPELINE = ( #'social.pipeline.user.create_user', 'social.pipeline.social_auth.associate_by_email', 'social.pipeline.social_auth.associate_user', - 'social.pipeline.social_auth.load_extra_data', 'social.pipeline.user.user_details' ) @@ -512,6 +513,12 @@ C_CITY_CATALOG_KEY = 'conf_city_catalog' C_COUNTRY_CATALOG_KEY = 'conf_country_catalog' E_CITY_CATALOG_KEY = 'expo_city_catalog' E_COUNTRY_CATALOG_KEY = 'expo_country_catalog' +DEFAULT_DESCRIPTION = { + 'e_description_ru': 'templates/client/includes/conference/default_description_ru.html', + 'e_description_en': 'templates/client/includes/conference/default_description_en.html', + 'c_description_ru': 'templates/client/includes/exposition/default_description_ru.html', + 'c_description_en': 'templates/client/includes/exposition/default_description_en.html', +} try: from local import * diff --git a/templates/client/base_catalog.html b/templates/client/base_catalog.html index eb823e9b..bde2f835 100644 --- a/templates/client/base_catalog.html +++ b/templates/client/base_catalog.html @@ -86,6 +86,13 @@ {% block page_body %}
+ + {% block exclude_events_revesred %} + {% if events_reversed %} + {% include "client/includes/reverseorder_warning.html" %} + {% endif %} + {% endblock exclude_events_revesred %} + {% block content_list %} {% endblock %} diff --git a/templates/client/events/filter_listview.html b/templates/client/events/filter_listview.html index c3282148..913123a4 100644 --- a/templates/client/events/filter_listview.html +++ b/templates/client/events/filter_listview.html @@ -15,6 +15,9 @@
{% endblock %} +{% block exclude_events_revesred %} +{% endblock exclude_events_revesred %} + {% block content_list %} {% with query=object_list %} {% if query %} diff --git a/templates/client/includes/events/filter_result.html b/templates/client/includes/events/filter_result.html index 9b6cf23d..03f852ce 100644 --- a/templates/client/includes/events/filter_result.html +++ b/templates/client/includes/events/filter_result.html @@ -2,6 +2,11 @@ {% load i18n %} {% load template_filters %} + +{% if events_reversed %} + {% include "client/includes/reverseorder_warning.html" %} +{% endif %} +