Реализована страница для отображения результатов фильтрации, реализована фильтрация по типу [Выставка, Конференция].

remotes/origin/stage5
Alexander Burdeiny 10 years ago
parent 2cf1428450
commit f2816d4827
  1. 0
      events/__init__.py
  2. 40
      events/forms.py
  3. 3
      events/models.py
  4. 16
      events/tests.py
  5. 9
      events/urls.py
  6. 39
      events/views.py
  7. 12
      functions/custom_views.py
  8. 25
      functions/model_utils.py
  9. 1
      proj/urls.py
  10. 4
      templates/client/base_catalog.html
  11. 41
      templates/client/events/filter_listview.html
  12. 14
      templates/client/includes/events/filter_form.html
  13. 141
      templates/client/includes/events/filter_result.html
  14. 96
      templates/client/includes/exposition/search_result.html

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
from django import forms
from django.utils.translation import ugettext as _
from haystack.query import SearchQuerySet
from functions.model_utils import EnumChoices
from exposition.models import Exposition
from conference.models import Conference
class FilterForm(forms.Form):
# class Meta:
# widgets = {
# 'model': forms.CheckboxSelectMultiple(),
# }
TYPES = EnumChoices(
EXPO=(1, _(u'Выставки')),
CONF=(2, _(_(u'Конференции'))),
)
model = forms.TypedMultipleChoiceField(label=_(u'Тип события'), coerce=int, choices=TYPES, required=False, widget=forms.CheckboxSelectMultiple())
def get_models(self):
val = self.cleaned_data.get('model')
models = []
if val:
if self.TYPES.EXPO in val:
models.append(Exposition)
if self.TYPES.CONF in val:
models.append(Conference)
else:
models = [Conference, Exposition]
return models
def filter(self):
qs = SearchQuerySet().models(*self.get_models()).all()
d = self.cleaned_data
return qs

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

@ -0,0 +1,16 @@
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)

@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
from django.conf.urls import include, patterns, url
from .views import FilterListView
urlpatterns = patterns('',
url(r'^$', FilterListView.as_view(), name='main'),
)

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
from django.views.generic.edit import FormMixin
from django.conf import settings
from haystack.query import SearchQuerySet
from functions.custom_views import ContextMixin
from functions.custom_views import ListView
from exposition.models import Exposition
from conference.models import Conference
from .forms import FilterForm
class FilterListView(ContextMixin, FormMixin, ListView):
initial_ctx = {'filtering': True}
form_class = FilterForm
paginate_by = settings.CLIENT_PAGINATION
template_name = 'events/filter_listview.html'
def get_form_kwargs(self):
kwargs = super(FilterListView, self).get_form_kwargs()
kwargs.update({'data': self.request.GET})
return kwargs
def get_queryset(self):
if self.form.is_valid():
qs = self.form.filter()
else:
qs = SearchQuerySet().models(Exposition, Conference).all()
return qs
def get(self, request, *args, **kwargs):
self.form = self.get_form(self.get_form_class())
self.extra_ctx['form'] = self.form
return super(FilterListView, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)

@ -516,3 +516,15 @@ class CreateUpdateView(SingleObjectTemplateResponseMixin, ModelFormMixin, Proces
def post(self, request, *args, **kwargs):
self.object = self.get_object()
return super(CreateUpdateView, self).post(request, *args, **kwargs)
class ContextMixin(object):
initial_ctx = {}
def dispatch(self, request, *args, **kwargs):
self.extra_ctx = self.initial_ctx.copy()
return super(ContextMixin, self).dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(ContextMixin, self).get_context_data(**kwargs)
context.update(self.extra_ctx)
return context

@ -1,3 +1,7 @@
# -*- coding: utf-8 -*-
from operator import itemgetter
def base_concrete_model(abstract, instance):
"""
Used in methods of abstract models to find the super-most concrete
@ -35,3 +39,24 @@ def base_concrete_model(abstract, instance):
if issubclass(cls, abstract) and not cls._meta.abstract:
return cls
return instance.__class__
class EnumChoices(list):
"""
A helper to create constants from choices tuples.
Usage:
CONNECTION_CHOICES = EnumChoices(
WIRED = (1, 'Wired connection'),
WIRELESS = (2, 'Wi-fi or other generic wireless type'),
MOBILE = (3, 'Mobile broadband'),
)
It will then return a list with the passed tuples so you can use in the
Django's fields choices option and, additionally, the returned object will
have the constant names as attributes (eg. CONNECTION_CHOICES.MOBILE == 3).
"""
def __init__(self, **data):
for item in sorted(data.items(), key=itemgetter(1)):
self.append((item[1][0], item[1][1]))
setattr(self, item[0], item[1][0])

@ -78,6 +78,7 @@ urlpatterns += solid_i18n_patterns('',
#url(r'^translators/', include('translator.urls')),
url(r'^translators/', include('specialist_catalog.urls')),
url(r'^newsletters/', include('emencia.django.newsletter.urls')),
url(r'^filter/', include('events.urls', namespace='events')),
url(r'^', include('accounts.urls')),
url(r'^', include('exposition.urls')),
url(r'^', include('settings.conference_old_urls')), # conference redirects from old version

@ -19,6 +19,10 @@
{# {% include 'client/includes/online_consult.html' %} #}
{% if filtering == True %}
{% include 'client/includes/events/filter_form.html' %}
{% endif %}
{% include 'client/includes/banners/aside_1.html' %}
{% include 'client/includes/services.html' %}

@ -0,0 +1,41 @@
{% extends 'base_catalog.html' %}
{% load i18n %}
{% load template_filters %}
{% block bread_scrumbs %}
<div class="bread-crumbs">
<a href="/">{% trans 'Главная страница' %}</a>
<strong>{% trans 'Фильтрация' %}</strong>
</div>
{% endblock %}
{% block page_title %}
<div class="page-title">
<h1>{% trans 'Фильтрация' %}:</h1>
</div>
{% endblock %}
{% block content_list %}
{% with query=object_list %}
{% if query %}
{% include 'client/includes/events/filter_result.html' %}
{% else %}
<p class="message-not-found">
<span>
<i class="fa fa-exclamation-triangle"></i>
</span>
<span class="message">
{% trans "Увы, событий, соответствующих выбранным фильтрам, нет в каталоге.<br> Попробуйте укрупнить параметры фильтрации" %}
</span>
</p>
{% endif %}
{% endwith %}
{% endblock %}
{% block paginator %}
{% with page_obj=page_obj queries=queries %}
{% include 'client/includes/search_paginator.html' %}
{% endwith %}
{% endblock %}

@ -0,0 +1,14 @@
{% load i18n %}
<form action="{% url 'events:main' %}" method="get">
{% csrf_token %}
{% for field in form %}
{{ field.label_tag }}
{{ field }}
{% endfor %}
{# {{ form.as_p }} #}
<button type="submit">{% trans "Применить" %}</button>
</form>

@ -0,0 +1,141 @@
{% load static %}
{% load i18n %}
{% load template_filters %}
<ul class="cat-list cl-exhibitions">
{# START FOR #}
{% for result in query %}
<li class="cl-item {% if result.object.canceled %}canceled{% endif %}">
<div class="cl-item-wrap clearfix">
<a target="_blank" href="{{ result.object.get_permanent_url }}">
{% if result.object.canceled %}
<div class="cancel"></div>
{% elif result.object.expohit %}
<div class="hit"></div>
{% endif %}
<div class="cli-pict">
{% with obj=result.object %}
{% include 'client/includes/show_logo.html' %}
{% endwith %}
</div>
</a>
<div class="cli-info">
<div class="cli-top clearfix">
{% if result.object.quality_label.ufi.is_set %}
<div class="cli-approved">
<img src="{% static 'client/img/approved-logo.png' %}" alt="" title="Approved Event" />
</div>
{% endif %}
<header>
<div class="cli-title"><a target="_blank" href="{{ result.object.get_permanent_url }}">{{ result.object.name|safe }}</a></div>
</header>
<div class="cli-descr">
{{ result.object.main_title|safe }}
</div>
</div>
<div class="cli-bot clearfix">
<div class="cli-date">
{% with obj=result.object %}
{% include 'client/includes/show_date_block.html' %}
{% endwith %}
</div>
{% if result.object.country %}
<div class="cli-place">
<a href="{{ result.object.catalog }}country/{{ result.object.country.url }}/">{{ result.object.country }}</a>, <a href="{{ result.object.catalog }}city/{{ result.object.city.url }}/">{{ result.object.city }}</a>
{% if result.object.place %}
, <a href="{{ result.object.place.get_permanent_url }}">{{ result.object.place }}</a>
{% endif %}
</div>
{% endif %}
</div>
</div>
<div class="cli-buttons clearfix">
<div class="cli-m-buttons">
{% include 'client/includes/exposition/services.html' with obj=result.object %}
{% include 'client/includes/calendar_button.html' with obj=result.object %}
<div class="{% if request.user.is_authenticated%}note-wrap{% else %}note-wrap-disabled{% endif %}">
{% with note=result.object|note_by_user:request.user %}
<a class="button green icon-note {% if note %}active{% endif %} note-button" href="/expo/add-note/{{ result.object.url }}/">{% trans 'заметка' %}</a>
<div class="note-overlay">
<form action="">
<textarea name="note_text" class="note-text"> {{ note }}</textarea>
</form>
</div>
{% endwith %}
</div>
</div>
<div class="cli-s-buttons">
{% include 'client/buttons/booking_button.html' with object=result.object %}
</div>
</div>
</div>
<footer class="clearfix">
<div class="cli-stats">
{% if result.object.visitors %}
<span class="visitors" title="Посетители">{{ result.object.visitors }}</span>
{% endif %}
{% if result.object.members %}
<span class="participants" title="Участники">{{ result.object.members }}</span>
{% endif %}
</div>
<div class="cli-tags">
{% include 'client/includes/exposition/tags.html' with obj=result.object %}
</div>
</footer>
</li>
{% if forloop.counter == 5 or objects|length < 5 %}
{% include 'client/includes/banners/catalog_inner_2.html' %}
{% endif %}
{% if forloop.counter == 10 %}
{% include 'client/includes/banners/catalog_inner.html' %}
{%endif %}
{% endfor %}
{# END FOR #}
</ul>
{% block scripts %}
{% if request.GET.debug == '1' %}
<script src="{% static 'client/js/_modules/block.exposition.list.js' %}"></script>
{% else %}
<script src="{% static 'client/js_min/_modules/block.exposition.list.min.js' %}"></script>
{% endif %}
<script>
EXPO.exposition.list.init({
note:{
wrapClass:'note-wrap',
wrapDisabledClass:'note-wrap-disabled',
buttonClass:'note-button',
inputClass:'note-text'
},
addCalendarText:"{% trans 'В расписание' %}",
removeCalendarText:"{% trans 'Из расписания' %}"
});
</script>
{% endblock %}

@ -1,31 +1,37 @@
{% load static %}
{% load i18n %}
{% load template_filters %}
<ul class="cat-list cl-exhibitions">
{# START FOR #}
{% for result in query %}
<li class="cl-item {% if result.object.canceled %}canceled{% endif %}">
<div class="cl-item-wrap clearfix">
<a target="_blank" href="{{ result.object.get_permanent_url }}">
{% if result.object.canceled %}
<div class="cancel"></div>
{% else %}
{% if result.object.expohit %}
{% elif result.object.expohit %}
<div class="hit"></div>
{% endif %}
{% endif %}
<div class="cli-pict">
{% with obj=result.object %}
{% include 'client/includes/show_logo.html' %}
{% endwith %}
</div>
</a>
<div class="cli-info">
<div class="cli-top clearfix">
{% if result.object.quality_label.ufi.is_set %}
{% if result.object.quality_label.ufi.is_set %}
<div class="cli-approved">
<img src="{% static 'client/img/approved-logo.png' %}" alt="" title="Approved Event" />
</div>
{% endif %}
{% endif %}
<header>
<div class="cli-title"><a target="_blank" href="{{ result.object.get_permanent_url }}">{{ result.object.name|safe }}</a></div>
</header>
@ -33,35 +39,45 @@
{{ result.object.main_title|safe }}
</div>
</div>
<div class="cli-bot clearfix">
<div class="cli-date">
{% with obj=result.object %}
{% include 'client/includes/show_date_block.html' %}
{% endwith %}
</div>
{% if result.object.country %}
<div class="cli-place">
<a href="{{ result.object.catalog }}country/{{ result.object.country.url }}/">{{ result.object.country }}</a>, <a href="{{ result.object.catalog }}city/{{ result.object.city.url }}/">{{ result.object.city }}</a>
{% if result.object.place %}
, <a href="{{ result.object.place.get_permanent_url }}">{{ result.object.place }}</a>
{% endif %}
</div>
<div class="cli-place">
<a href="{{ result.object.catalog }}country/{{ result.object.country.url }}/">{{ result.object.country }}</a>, <a href="{{ result.object.catalog }}city/{{ result.object.city.url }}/">{{ result.object.city }}</a>
{% if result.object.place %}
, <a href="{{ result.object.place.get_permanent_url }}">{{ result.object.place }}</a>
{% endif %}
</div>
{% endif %}
</div>
</div>
<div class="cli-buttons clearfix">
<div class="cli-m-buttons">
{% include 'client/includes/exposition/services.html' with obj=result.object %}
{% include 'client/includes/calendar_button.html' with obj=result.object %}
<div class="{% if request.user.is_authenticated%}note-wrap{% else %}note-wrap-disabled{% endif %}">
{% with note=result.object|note_by_user:request.user %}
<a class="button green icon-note {% if note %}active{% endif %} note-button" href="/expo/add-note/{{ result.object.url }}/">{% trans 'заметка' %}</a>
<div class="note-overlay">
<form action="">
<textarea name="note_text" class="note-text"> {{ note }}</textarea>
</form>
</div>
<a class="button green icon-note {% if note %}active{% endif %} note-button" href="/expo/add-note/{{ result.object.url }}/">{% trans 'заметка' %}</a>
<div class="note-overlay">
<form action="">
<textarea name="note_text" class="note-text"> {{ note }}</textarea>
</form>
</div>
{% endwith %}
</div>
</div>
<div class="cli-s-buttons">
@ -69,20 +85,25 @@
</div>
</div>
</div>
<footer class="clearfix">
<div class="cli-stats">
{% if result.object.visitors %}
<span class="visitors" title="Посетители">{{ result.object.visitors }}</span>
{% endif %}
{% if result.object.members %}
<span class="participants" title="Участники">{{ result.object.members }}</span>
{% endif %}
</div>
<div class="cli-tags">
{% include 'client/includes/exposition/tags.html' with obj=result.object %}
</div>
</footer>
</li>
{% if forloop.counter == 5 or objects|length < 5 %}
{% include 'client/includes/banners/catalog_inner_2.html' %}
{% endif %}
@ -90,24 +111,31 @@
{% if forloop.counter == 10 %}
{% include 'client/includes/banners/catalog_inner.html' %}
{%endif %}
{% endfor %}
{# END FOR #}
</ul>
{% block scripts %}
{% if request.GET.debug == '1' %}
<script src="{% static 'client/js/_modules/block.exposition.list.js' %}"></script>
{% else %}
<script src="{% static 'client/js_min/_modules/block.exposition.list.min.js' %}"></script>
{% endif %}
<script>
EXPO.exposition.list.init({
note:{
wrapClass:'note-wrap',
wrapDisabledClass:'note-wrap-disabled',
buttonClass:'note-button',
inputClass:'note-text'
},
addCalendarText:"{% trans 'В расписание' %}",
removeCalendarText:"{% trans 'Из расписания' %}"
});
</script>
{% if request.GET.debug == '1' %}
<script src="{% static 'client/js/_modules/block.exposition.list.js' %}"></script>
{% else %}
<script src="{% static 'client/js_min/_modules/block.exposition.list.min.js' %}"></script>
{% endif %}
<script>
EXPO.exposition.list.init({
note:{
wrapClass:'note-wrap',
wrapDisabledClass:'note-wrap-disabled',
buttonClass:'note-button',
inputClass:'note-text'
},
addCalendarText:"{% trans 'В расписание' %}",
removeCalendarText:"{% trans 'Из расписания' %}"
});
</script>
{% endblock %}

Loading…
Cancel
Save