From f68d462a402a9252926f5327474185631be40781 Mon Sep 17 00:00:00 2001 From: Nazar Kotyuk Date: Mon, 7 Jul 2014 16:38:44 +0300 Subject: [PATCH] Commit --- .gitignore | 1 + exposition/models.py | 6 +- exposition/search_indexes.py | 23 +++++ exposition/urls.py | 9 +- exposition/views.py | 23 ++++- functions/search_forms.py | 99 +++++++++++++++++-- place_exposition/models.py | 2 +- proj/local.py | 19 ++++ proj/production.py | 14 +++ proj/settings.py | 12 ++- static/client/js/main.js | 24 +++++ .../admin/exposition/exposition_add.html | 9 +- templates/client/blank.html | 12 ++- .../client/exposition/exposition_by_city.html | 28 ++++++ .../exposition/exposition_by_country.html | 27 +++++ .../exposition/exposition_by_theme.html | 27 +++++ templates/client/includes/catalog_search.html | 6 +- templates/client/includes/event_steps.html | 6 +- templates/client/includes/footer.html | 10 +- templates/client/includes/header.html | 28 ++---- templates/client/popups/period.html | 6 +- templates/client/popups/place.html | 32 +----- templates/client/popups/register.html | 14 +-- 23 files changed, 352 insertions(+), 85 deletions(-) create mode 100644 proj/local.py create mode 100644 proj/production.py create mode 100644 templates/client/exposition/exposition_by_city.html create mode 100644 templates/client/exposition/exposition_by_country.html create mode 100644 templates/client/exposition/exposition_by_theme.html diff --git a/.gitignore b/.gitignore index aba19a52..f696f2ad 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ *.gif *.doc .idea/ +/proj/local.py diff --git a/exposition/models.py b/exposition/models.py index 3d9c2c8b..a9c86cb0 100644 --- a/exposition/models.py +++ b/exposition/models.py @@ -50,8 +50,10 @@ class Exposition(TranslatableModel, EventMixin, ExpoMixin): quality_label = BitField(flags=['ufi', 'rsva', 'exporating']) audience = BitField(flags=[k for k, v in BIT_AUDIENCE]) # relations - country = models.ForeignKey('country.Country', verbose_name='Страна', on_delete=models.PROTECT) - city = models.ForeignKey('city.City', verbose_name='Город', on_delete=models.PROTECT) + country = models.ForeignKey('country.Country', verbose_name='Страна', on_delete=models.PROTECT, + related_name='exposition_country') + city = models.ForeignKey('city.City', verbose_name='Город', on_delete=models.PROTECT, + related_name='exposition_city') place = models.ForeignKey('place_exposition.PlaceExposition', verbose_name='Место проведения', blank=True, null=True, on_delete=models.PROTECT, related_name='exposition_place') theme = models.ManyToManyField('theme.Theme', verbose_name='Тематики', diff --git a/exposition/search_indexes.py b/exposition/search_indexes.py index a864bd30..af583d49 100644 --- a/exposition/search_indexes.py +++ b/exposition/search_indexes.py @@ -5,6 +5,29 @@ from models import Exposition class ExpositionIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) where = indexes.MultiValueField() + data_begin = indexes.DateField(model_attr='data_begin') + data_end = indexes.DateField(model_attr='data_end') + theme = indexes.MultiValueField() + tag = indexes.MultiValueField() + country_id = indexes.IntegerField() + city_id = indexes.IntegerField() + area_id = indexes.IntegerField() + + def prepare_area_id(self, obj): + return obj.country.area.id + + def prepare_country_id(self, obj): + return obj.country.id + + def prepare_city_id(self, obj): + return obj.city.id + + def prepare_theme(self, obj): + return [th.id for th in obj.theme.filter()] + + def prepare_tag(self, obj): + return [th.id for th in obj.tag.filter()] + def prepare_where(self, obj): country = [tr.name for tr in obj.country.translations.all()] city = [tr.name for tr in obj.city.translations.all()] diff --git a/exposition/urls.py b/exposition/urls.py index c29a150a..63857514 100644 --- a/exposition/urls.py +++ b/exposition/urls.py @@ -1,13 +1,20 @@ # -*- coding: utf-8 -*- from django.conf.urls import patterns, include, url from views import ExpositionView, ExpositionVisitors, ExpositionMembers, ExpositionStatistic, ExpositionPrice,\ - ExpositionProgramme, ExpositionSearchView + ExpositionProgramme, ExpositionSearchView, ExpositionByCountry, ExpositionByTheme, ExpositionByCity + +from django.http import HttpResponse from views import ExpositionServiceView +def test(request): + return HttpResponse('123') urlpatterns = patterns('', url(r'expositions/search/', ExpositionSearchView.as_view()), + url(r'expositions/country/', ExpositionByCountry.as_view()), + url(r'expositions/city/', ExpositionByCity.as_view()), + url(r'expositions/theme/', ExpositionByTheme.as_view()), url(r'expositions/(?P.*)/(?P\d+)/$', ExpositionView.as_view()), url(r'expositions/(?P\d+)/$', ExpositionView.as_view()), diff --git a/exposition/views.py b/exposition/views.py index 05e479ad..d77b9910 100644 --- a/exposition/views.py +++ b/exposition/views.py @@ -20,6 +20,27 @@ import json from django.utils.translation import ugettext as _ +class ExpositionByCountry(ListView): + model = Country + template_name = 'exposition/exposition_by_country.html' + def get_queryset(self): + return self.model.objects.select_related('exposition_country').filter(exposition_country__country__isnull=False).all().distinct() + +class ExpositionByTheme(ListView): + model = Theme + template_name = 'exposition/exposition_by_theme.html' + + def get_queryset(self): + return self.model.objects.select_related('exposition_themes').filter(exposition_themes__theme__isnull=False).all().distinct() + + +class ExpositionByCity(ListView): + model = City + template_name = 'exposition/exposition_by_city.html' + + def get_queryset(self): + return self.model.objects.select_related('exposition_city').filter(exposition_city__city__isnull=False).all().distinct() + class ExpositionServiceView(FormView, ExpoMixin): params = None search_form = ExpositionSearchForm @@ -110,7 +131,7 @@ class ExpositionServiceView(FormView, ExpoMixin): class ExpositionSearchView(ListView): - paginate_by = 2 + paginate_by = 10 template_name = 'exposition/search.html' search_form = ExpositionSearchForm model = Exposition diff --git a/functions/search_forms.py b/functions/search_forms.py index 06f59eba..df75154c 100644 --- a/functions/search_forms.py +++ b/functions/search_forms.py @@ -13,6 +13,7 @@ from country.models import Country from city.models import City import ast + class AbstactSearchForm(forms.Form): q = forms.CharField(label=_(u'Поиск'), required=False) w = forms.CharField(label=_(u'Где'), required=False) @@ -75,12 +76,70 @@ class CompanySearchForm(AbstactSearchForm): return sqs +from country.models import Area class ExpositionSearchForm(forms.Form): q = forms.CharField(label=_(u'Поиск'), required=False) w = forms.CharField(label=_(u'Где'), required=False) -# fr = forms.DateField(required=False) -# to = forms.DateField(required=False) + + th = forms.CharField(label=_(u'Тематика'), required=False, widget=forms.SelectMultiple()) + tg = forms.CharField(label=_(u'Теги'), required=False, widget=forms.SelectMultiple()) + + area = forms.MultipleChoiceField(label=_(u'Регион'), choices=[(item.id, item.name) for item in Area.objects.all()], + required=False, widget=forms.CheckboxSelectMultiple()) + co = forms.CharField(label=_(u'Страна'), required=False, widget=forms.SelectMultiple()) + ci = forms.CharField(label=_(u'Город'), required=False, widget=forms.SelectMultiple()) + + fr = forms.DateField(required=False, + widget=forms.DateInput(attrs={'class': 'date', 'id': 'dateFrom', + 'placeholder': _(u'дд.мм.гггг')})) + to = forms.DateField(required=False, + widget=forms.DateInput(attrs={'class': 'date', 'id': 'dateTo', + 'placeholder': _(u'дд.мм.гггг')})) + + """ + def clean_area(self): + + area = self.cleaned_data.get('area') + if area: + res = ast.literal_eval(area) + return res + return area + """ + + def clean_co(self): + + co = self.cleaned_data.get('co') + if co: + res = ast.literal_eval(co) + return res + return co + + def clean_ci(self): + + ci = self.cleaned_data.get('ci') + if ci: + res = ast.literal_eval(ci) + return res + return ci + + def clean_th(self): + + th = self.cleaned_data.get('th') + if th: + res = ast.literal_eval(th) + return res + return th + + def clean_tg(self): + + tg = self.cleaned_data.get('tg') + if tg: + res = ast.literal_eval(tg) + return res + return tg + + def search(self): @@ -88,26 +147,50 @@ class ExpositionSearchForm(forms.Form): return EmptySearchQuerySet() q = self.cleaned_data.get('q') w = self.cleaned_data.get('w') + fr = self.cleaned_data.get('fr') + to = self.cleaned_data.get('to') + th = self.cleaned_data.get('th') + tg = self.cleaned_data.get('tg') + co = self.cleaned_data.get('co') + ci = self.cleaned_data.get('ci') + area = self.cleaned_data.get('area') - if not q and not w: - return EmptySearchQuerySet() - sqs = SearchQuerySet().models(Exposition) + sqs = SearchQuerySet().models(Exposition).all() if q: sqs = sqs.auto_query(q) if w: sqs = sqs.filter(where__contains=w) + if fr: + sqs = sqs.filter(data_begin__gte=fr) + if to: + sqs = sqs.filter(data_begin__lte=to) + if area: + sqs = sqs.filter(area_id__in=area) + if co: + sqs = sqs.filter(country_id__in=co) + if ci: + sqs = sqs.filter(city_id__in=ci) + if th: + sqs = sqs.filter(theme__in=th) + if tg: + sqs = sqs.filter(tag__in=tg) + - return sqs + return sqs.order_by('data_begin') class EventSearchForm(forms.Form): q = forms.CharField(label=_(u'Поиск'), required=False) w = forms.CharField(label=_(u'Где'), required=False) - fr = forms.DateField(required=False) - to = forms.DateField(required=False) + fr = forms.DateField(required=False, + widget=forms.DateInput(attrs={'class': 'date', 'id': 'dateFrom', + 'placeholder': _(u'дд.мм.гггг')})) + to = forms.DateField(required=False, + widget=forms.DateInput(attrs={'class': 'date', 'id': 'dateTo', + 'placeholder': _(u'дд.мм.гггг')})) def search(self): diff --git a/place_exposition/models.py b/place_exposition/models.py index a0121140..677d85d8 100644 --- a/place_exposition/models.py +++ b/place_exposition/models.py @@ -31,7 +31,7 @@ class PlaceExposition(TranslatableModel, ExpoMixin): url = models.SlugField(unique=True, max_length=255) country = models.ForeignKey('country.Country', on_delete=models.PROTECT) - city = models.ForeignKey('city.City', on_delete=models.PROTECT) + city = models.ForeignKey('city.City', on_delete=models.PROTECT, related_name='place_expostions') #type uses EnumField for creating Enum type field in Mysql database type = EnumField(values = [item1 for item1, item2 in EXPOSITION_TYPE]) #information diff --git a/proj/local.py b/proj/local.py new file mode 100644 index 00000000..ea65fb79 --- /dev/null +++ b/proj/local.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Django local settings + +DEBUG = True + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'test', + 'USER': 'root', + 'PASSWORD': 'qazedc', + 'HOST': '', + 'PORT': '', + } +} + +INSTALLED_APPS += ( + 'debug_toolbar', +) diff --git a/proj/production.py b/proj/production.py new file mode 100644 index 00000000..8fd4509b --- /dev/null +++ b/proj/production.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Django local settings +DEBUG = True # изменить когда будет продакшн + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'test', + 'USER': 'kotzilla', + 'PASSWORD': 'qazedc', + 'HOST': '', + 'PORT': '', + } +} \ No newline at end of file diff --git a/proj/settings.py b/proj/settings.py index 28bb4013..81f00dc7 100644 --- a/proj/settings.py +++ b/proj/settings.py @@ -8,7 +8,7 @@ DJANGO_ROOT = os.path.dirname(os.path.realpath(django.__file__)) SITE_ROOT = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0] DEBUG = True -TEMPLATE_DEBUG = DEBUG + ADMINS = ( # ('Your Name', 'your_email@example.com'), @@ -329,7 +329,7 @@ INSTALLED_APPS = ( 'translator', 'webinar', #django modules - + 'sorl.thumbnail', 'hvad', 'tinymce', 'ckeditor', @@ -382,3 +382,11 @@ LOGGING = { }, } } + + +try: + from local import * +except ImportError, e: + from production import * + +TEMPLATE_DEBUG = DEBUG \ No newline at end of file diff --git a/static/client/js/main.js b/static/client/js/main.js index 99cf7506..be4ae405 100644 --- a/static/client/js/main.js +++ b/static/client/js/main.js @@ -52,6 +52,30 @@ function addError(inputId, msg){ /* submiting registration form */ $(function () { + + $('.search_form').on('submit', function(e){ + e.preventDefault(); + var action = $(this).attr('action'); + var formData = '' + $('.search_form').each(function(i){ + if (i==0){ + formData = formData+$(this).serialize(); + } + else{ + formData = formData+'&'+$(this).serialize() ; + } + }); + var url = action+'?'+formData.replace(/[^&]+=\.?(?:&|$)/g, '') + + //console.log(action+'?'+formData.replace(/[^&]+=\.?(?:&|$)/g, '')); + //console.log(url) + window.location = url + + + //var formData = $(this).serialize() + + //alert(window.location+formData); + }); $('#send_message_form').on('submit', function(event){ event.preventDefault(); $this = $(this); diff --git a/templates/admin/exposition/exposition_add.html b/templates/admin/exposition/exposition_add.html index b31596e7..09082370 100644 --- a/templates/admin/exposition/exposition_add.html +++ b/templates/admin/exposition/exposition_add.html @@ -1,5 +1,7 @@ {% extends 'base.html' %} {% load static %} +{% load thumbnail %} + {# Displays exposition form and file form in modal window #} @@ -383,7 +385,12 @@ {{ file.id }} - + + {% thumbnail file.file_path "100x100" as im %} + + {% endthumbnail %} + + {{ file.file_name }} {{ file.purpose }} diff --git a/templates/client/blank.html b/templates/client/blank.html index aae6ca5c..d5d59fdc 100644 --- a/templates/client/blank.html +++ b/templates/client/blank.html @@ -87,9 +87,15 @@ This template include basic anf main styles and js files, {% include 'client/popups/login.html' %} {% include 'client/popups/register.html' %} {% endif %} - {% include 'client/popups/theme.html' %} - {% include 'client/popups/place.html' %} - {% include 'client/popups/period.html' %} + + {% include 'client/popups/theme.html' %} + {% include 'client/popups/place.html' %} + {% if search_form.fr %} + {% with search_form=search_form search_action=search_action type=type%} + {% include 'client/popups/period.html' %} + {% endwith %} + {% endif %} + {% block popup %} {% endblock %} diff --git a/templates/client/exposition/exposition_by_city.html b/templates/client/exposition/exposition_by_city.html new file mode 100644 index 00000000..fef59fe7 --- /dev/null +++ b/templates/client/exposition/exposition_by_city.html @@ -0,0 +1,28 @@ +{% extends 'base_catalog.html' %} +{% load i18n %} + +{% block bread_scrumbs %} + +{% endblock %} + +{% block page_title %} +
+

{% trans 'Выставки мира по городам' %}:

+
+{% endblock %} + +{% block content_list %} +
    + {% for obj in object_list %} +
  • + {{ obj.name }} +
  • + {% endfor %} +
+ +{% endblock %} + diff --git a/templates/client/exposition/exposition_by_country.html b/templates/client/exposition/exposition_by_country.html new file mode 100644 index 00000000..0d061f89 --- /dev/null +++ b/templates/client/exposition/exposition_by_country.html @@ -0,0 +1,27 @@ +{% extends 'base_catalog.html' %} +{% load i18n %} + +{% block bread_scrumbs %} + +{% endblock %} + +{% block page_title %} +
+

{% trans 'Выставки мира по странам' %}:

+
+{% endblock %} + +{% block content_list %} +
    + {% for obj in object_list %} +
  • + {{ obj.name }} +
  • + {% endfor %} +
+ +{% endblock %} diff --git a/templates/client/exposition/exposition_by_theme.html b/templates/client/exposition/exposition_by_theme.html new file mode 100644 index 00000000..c4bac769 --- /dev/null +++ b/templates/client/exposition/exposition_by_theme.html @@ -0,0 +1,27 @@ +{% extends 'base_catalog.html' %} +{% load i18n %} + +{% block bread_scrumbs %} + +{% endblock %} + +{% block page_title %} +
+

{% trans 'Выставки мира по тематикам' %}:

+
+{% endblock %} + +{% block content_list %} +
    + {% for obj in object_list %} +
  • + {{ obj.name }} +
  • + {% endfor %} +
+ +{% endblock %} diff --git a/templates/client/includes/catalog_search.html b/templates/client/includes/catalog_search.html index e978411b..6039c73a 100644 --- a/templates/client/includes/catalog_search.html +++ b/templates/client/includes/catalog_search.html @@ -2,7 +2,7 @@ {% load i18n %}
-
+
{% if type %}{{ type }}{% else %}{% trans 'поиск событий' %}{% endif %}
@@ -19,7 +19,7 @@
- +
@@ -29,4 +29,4 @@
- \ No newline at end of file + diff --git a/templates/client/includes/event_steps.html b/templates/client/includes/event_steps.html index 8cad6640..de0c08e9 100644 --- a/templates/client/includes/event_steps.html +++ b/templates/client/includes/event_steps.html @@ -7,19 +7,19 @@ \ No newline at end of file diff --git a/templates/client/includes/footer.html b/templates/client/includes/footer.html index 73e4c913..8eb1d1c9 100644 --- a/templates/client/includes/footer.html +++ b/templates/client/includes/footer.html @@ -7,11 +7,11 @@ diff --git a/templates/client/includes/header.html b/templates/client/includes/header.html index b7dcae7d..8ce859de 100644 --- a/templates/client/includes/header.html +++ b/templates/client/includes/header.html @@ -15,7 +15,7 @@
{% if user.is_authenticated %} {% if user.organiser %} - + {% endif %} {% endif %} @@ -42,23 +42,15 @@
    -
  • RSS
  • -
  • Facebook' %}
  • -
  • LinkedIn' %}
  • -
  • В контакте' %}
  • -
  • Twitter' %}
  • +
  • RSS
  • +
  • Facebook' %}
  • +
  • LinkedIn' %}
  • +
  • В контакте' %}
  • +
  • Twitter' %}
{% if user.is_authenticated %}