Реализована страница для отображения результатов фильтрации, реализована фильтрация по типу [Выставка, Конференция].
parent
2cf1428450
commit
f2816d4827
14 changed files with 407 additions and 34 deletions
@ -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) |
||||
@ -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 %} |
||||
Loading…
Reference in new issue