Expobanners. Top: Hardcoded for js

remotes/origin/1203
Kotiuk Nazarii 11 years ago
parent 897b23b592
commit e002028cab
  1. 19
      expobanner/admin.py
  2. 5
      expobanner/admin_urls.py
  3. 59
      expobanner/forms.py
  4. 10
      expobanner/managers.py
  5. 21
      expobanner/models.py
  6. 1
      expobanner/urls.py
  7. 2
      expobanner/utils.py
  8. 34
      expobanner/views.py
  9. 1
      exposition/models.py
  10. 84
      templates/admin/expobanner/top_create.html
  11. 36
      templates/admin/expobanner/top_list.html
  12. 1
      templates/admin/includes/admin_nav.html
  13. 13
      templates/client/includes/banners/tops.html
  14. 102
      templates/client/includes/exposition/expo_top.html
  15. 3
      templates/client/includes/exposition/exposition_list.html

@ -5,7 +5,7 @@ from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from expobanner.models import URL, BannerGroup, Banner, Paid
from expobanner.forms import UrlCreateForm, BannerCreateGroupForm, BannerCreateForm, BannerGroupUpdateForm,\
PaidCreateForm, PaidUpdateForm
PaidCreateForm, PaidUpdateForm, TopCreateForm
from exposition.models import Exposition
@ -138,4 +138,19 @@ def paid_turn(request, pk, status):
class PaidStat(DetailView):
model = Paid
template_name = 'admin/expobanner/paid_stat.html'
template_name = 'admin/expobanner/paid_stat.html'
class TopList(ListView):
model = Exposition
template_name = 'admin/expobanner/top_list.html'
paginate_by = settings.ADMIN_PAGINATION
def get_queryset(self):
return self.model.objects.language().filter(top__isnull=False)
class TopCreate(CreateView):
form_class = TopCreateForm
template_name = 'admin/expobanner/top_create.html'
success_url = '/admin/expobanners/top/list/'

@ -21,4 +21,9 @@ urlpatterns = patterns('expobanner.admin',
url(r'^paid/$', PaidCreate.as_view(), name='expobanner-create_paid'),
url(r'^paid/turn/(?P<pk>\d+)/(?P<status>.*)/$', paid_turn, name='expobanner-paid-turn'),
url(r'^paid/(?P<pk>\d+)/stat/$', PaidStat.as_view(), name='expobanner_stat_paid'),
# top
url(r'^top/list/$', TopList.as_view(), name='expobanner-list_top'),
url(r'^top/(?P<pk>\d+)/edit/$', PaidUpdate.as_view(), name='expobanner-update_top'),
url(r'^top/$', TopCreate.as_view(), name='expobanner-create_top'),
url(r'^top/(?P<pk>\d+)/stat/$', PaidStat.as_view(), name='expobanner_stat_top'),
)

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from django import forms
from expobanner.models import URL, BannerGroup, Banner, Paid
from expobanner.models import URL, BannerGroup, Banner, Paid, Top
from exposition.models import Exposition
from country.models import Country
from city.models import City
@ -123,4 +123,59 @@ class PaidUpdateForm(forms.ModelForm):
paid.save()
return paid
return paid
class TopCreateForm(forms.ModelForm):
verbose = u'Создать выставку в топе'
exposition = forms.CharField(label=u'Выставка', widget=forms.HiddenInput())
country = forms.MultipleChoiceField(label=u'Страна', choices=[('', ' ')] + [(c.id, c.name) for c in Country.objects.all()], required=False)
theme = forms.MultipleChoiceField(label=u'Тематика', required=False,
choices=[('', ' ')] + [(item.id, item.name) for item in Theme.objects.language().all()])
excluded_cities = forms.CharField(label=u'Город', widget=forms.HiddenInput(), required=False)
excluded_tags = forms.CharField(label=u'Тег', widget=forms.HiddenInput(), required=False)
class Meta:
model = Top
fields = ['catalog', 'position', 'theme', 'excluded_tags', 'country', 'excluded_cities', 'fr', 'to']
def save(self, commit=True):
top = super(TopCreateForm, self).save(commit=False)
# Prepare a 'save_m2m' method for the form,
old_save_m2m = self.save_m2m
def save_m2m():
old_save_m2m()
# This is where we actually link the pizza with toppings
top.theme.clear()
for theme in self.cleaned_data['theme']:
top.theme.add(theme)
self.save_m2m = save_m2m
if commit:
expo = self.cleaned_data['exposition']
top.save()
self.save_m2m()
expo.top = top
expo.save()
return top
def clean_theme(self):
theme_ids = self.cleaned_data['theme']
if theme_ids:
return Theme.objects.filter(id__in=theme_ids)
return None
def clean_country(self):
country_ids = self.cleaned_data['country']
if country_ids:
return Country.objects.filter(id__in=country_ids)
return None
def clean_exposition(self):
expo_id = self.cleaned_data['exposition']
try:
expo = Exposition.objects.get(id=expo_id)
except Exposition.DoesNotExist:
raise forms.ValidationError(u'Такой выставки не существует')
return expo

@ -59,4 +59,14 @@ class URLCached(models.Manager):
if not result:
result = list(self.filter(public=True))
cache.set(key, result, 150)
return result
class TopCached(models.Manager):
def all(self):
key = 'expo_b_top_all'
result = cache.get(key)
if not result:
result = list(self.prefetch_related('theme', 'country', 'excluded_tags', 'excluded_cities').all())
cache.set(key, result, 80)
return result

@ -7,7 +7,7 @@ from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.contrib.sites.models import Site
from django.db.models.signals import post_save
from .managers import BiasedManager, BannerGroupCached, URLCached
from .managers import BiasedManager, BannerGroupCached, URLCached, TopCached
from .mixins import StatMixin
from theme.models import Theme
from country.models import Country
@ -239,16 +239,19 @@ class PaidStat(models.Model):
class Top(models.Model, StatMixin):
catalog = models.CharField(max_length=16)
position = models.PositiveIntegerField(blank=True, null=True)
theme = models.ManyToManyField('theme.Theme', blank=True, null=True)
excluded_tags = models.ManyToManyField('theme.Tag', blank=True, null=True)
country = models.ManyToManyField('country.Country', blank=True, null=True)
excluded_cities = models.ManyToManyField('city.City', blank=True, null=True)
fr = models.DateField(default=date.today())
to = models.DateField(blank=True, null=True)
catalog = models.CharField(max_length=16, verbose_name=u'Каталог для топа')
position = models.PositiveIntegerField(blank=True, default=2, null=True, verbose_name=u'Позиция')
theme = models.ManyToManyField('theme.Theme', blank=True, null=True, verbose_name=u'Тематики')
excluded_tags = models.ManyToManyField('theme.Tag', blank=True, null=True, verbose_name=u'Исключить теги')
country = models.ManyToManyField('country.Country', blank=True, null=True, verbose_name=u'Страны')
excluded_cities = models.ManyToManyField('city.City', blank=True, null=True, verbose_name=u'Исключить города')
fr = models.DateField(default=date.today(), verbose_name=u'Начало')
to = models.DateField(blank=True, null=True, verbose_name=u'Конец')
stat_pswd = models.CharField(max_length=16)
objects = models.Manager()
cached = TopCached()
class Meta:
ordering = ['position']

@ -7,6 +7,7 @@ urlpatterns = [
#url(r'^view/(?P<banner_id>\d+)/$', views.view, name='banner_view'),
#
url(r'^get-banners/$', views.get_banners),
url(r'^get-tops/$', views.get_top),
url(r'^banner/(?P<pk>\d+)/stat/$', BannerStat.as_view(), name='banner_stat_client'),
url(r'^paid/(?P<pk>\d+)/stat/$', PaidStat.as_view(), name='paid_stat_client'),
]

@ -21,7 +21,7 @@ def get_by_sort(banner_list):
def get_banner_by_params(banners_list, urls, params):
print('START. NUMBER of queries = %d'%len(connection.queries))
#print('START. NUMBER of queries = %d'%len(connection.queries))
thematic_banners = []
url_banners = []

@ -3,7 +3,7 @@ import json
import re
from django.http import HttpResponse
from django.shortcuts import redirect, get_object_or_404
from .models import Banner, BannerGroup, URL
from .models import Banner, BannerGroup, URL, Top
from expobanner.utils import get_by_sort, get_banner_by_params, get_client_ip
@ -67,4 +67,34 @@ def get_banners(request):
# add view log
banner.log(request, 1)
return HttpResponse(json.dumps(result, indent=4), content_type='application/json')
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'),
'tag': request.GET.get('tag'),
'country': request.GET.get('country'),
'city': request.GET.get('city'),
'catalog': request.GET.get('catalog')}
tops = Top.cached.all()
events = get_top_events(tops, params)
expos = Exposition.objects.filter(top__isnull=False)
context = {'objects': expos}
return render_to_response('client/includes/exposition/expo_top.html', context, context_instance=RequestContext(request))

@ -157,6 +157,7 @@ class Exposition(TranslatableModel, EventMixin, ExpoMixin):
registration_payment = models.PositiveIntegerField(verbose_name='Регистрационный взнос', blank=True, null=True)
paid_new = models.ForeignKey('expobanner.Paid', blank=True, null=True, on_delete=models.SET_NULL)
top = models.ForeignKey('expobanner.Top', blank=True, null=True, on_delete=models.SET_NULL)
#set manager of this model(fisrt manager is default)
objects = ExpoManager()
enable = ClientManager()

@ -0,0 +1,84 @@
{% extends 'base.html' %}
{% load static %}
{% block scripts %}
{# selects #}
<link href="{% static 'js/select/select2.css' %}" rel="stylesheet"/>
<script src="{% static 'js/select/select2.js' %}"></script>
<script>
$(function(){
$('#id_fr').datetimepicker({
todayHighlight: true,
format : 'yyyy-mm-dd',
minView:2
});
$('#id_to').datetimepicker({
todayHighlight: true,
format : 'yyyy-mm-dd',
minView:2
});
$('#id_theme').select2({width: "element"});
$('#id_country').select2({width: "element"});
$('#id_exposition').select2({
placeholder: 'Найти',
width: 'element',
ajax: {
url: '/admin/exposition/search/',
dataType: "json",
quietMillis: 200,
multiple: true,
data: function(term, page, theme){
return {term: term,
page: page};
},
results: function (data) {
var results = [];
$.each(data, function(index, item){
results.push({
id: item.id,
text: item.label
});
});
return {results: results};
}
},
initSelection : function(element, callback) {
var id= $(element).val();
var text = $(element).attr('data-init-text');
callback({id: id, text:text});
}
});
});
</script>
{% endblock %}
{% block body %}
<form method="post" class="form-horizontal" name="form2" id="form2" enctype="multipart/form-data"> {% csrf_token %}
<fieldset>
<div class="box span8">
<div class="box-header well">
<h2><i class="icon-pencil"></i>{{ form.verbose }}</h2>
</div>
<div class="box-content">
{% for field in form %}
<div class="control-group {% if field.errors %}error{% endif %}">
<label class="control-label">{% if field.field.required %}<b>{{ field.label }}:</b>{% else %}{{ field.label }}{% endif %}</label>
<div class="controls">{{ field }}
<span class="help-inline">{{ field.errors }}</span>
</div>
</div>
{% endfor %}
</div>
</div>
</fieldset>
<div class="controls">
<input class="btn btn-large btn-primary" type="submit" value="Готово">
<input class="btn btn-large" type="reset" value="Отмена">
</div>
</form>
{% endblock %}

@ -0,0 +1,36 @@
{% extends 'base.html' %}
{% block body %}
<div class="box span8">
<div class="box-header well">
<h2><i class="icon-arrow-down"></i>Список выставок в топе</h2>
</div>
<div class="box-content">
{% block list_table %}
<a class="btn btn-success" href="{% url 'expobanner-create_top' %}"><i class="icon-plus-sign icon-white"></i> Добавить выставку</a>
<table class="table table-hover">
<thead>
<tr>
<th>Выставка</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
{% for item in object_list %}
<tr>
<td>{{ item }}</td>
<td><a href="{% url 'expobanner-update_top' item.top_id %}">Изменить</a> </td>
<td><a href="{% url 'expobanner_stat_top' item.top_id %}">Статистика</a> </td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
</div>
{# pagination #}
{% include 'admin/includes/admin_pagination.html' with page_obj=object_list %}
</div>
{% endblock %}

@ -110,6 +110,7 @@
<ul class="dropdown-menu">
<li><a href="/admin/expobanners/banners/control/">Управление банерами</a></li>
<li><a href="/admin/expobanners/paid/list/">Платные выставки</a></li>
<li><a href="/admin/expobanners/top/list/">Выставки в топе</a></li>
</ul>
</li>

@ -0,0 +1,13 @@
<div id="expo_top_events">
</div>
<script>
/* НУЖНО ЛИ??? */
window.sendData = {
"theme": [{% for item in themes %}{{ item }}{% endfor %}],
"country": "{{ country }}",
"city": "{{ city }}",
"tag": "{{ tag }}"
};
var url = "/expo-b/get-tops/";
</script>

@ -0,0 +1,102 @@
{% load static %}
{% load i18n %}
{% load template_filters %}
<ul class="cat-list cl-exhibitions">
{% for obj in objects %}
<li class="cl-item {% if obj.canceled %}canceled{% endif %}">
<div class="cl-item-wrap clearfix">
{% if not obj.canceled %}
<a href="{% if not obj.paid_new_id %}{{ obj.get_permanent_url }}{% else %}{{ obj.get_paid_catalog_url }}{% endif %}">
{% if obj.expohit %}
<div class="hit"></div>
{% endif %}
<div class="cli-pict">
{% with obj=obj %}
{% include 'client/includes/show_logo.html' %}
{% endwith %}
</div>
</a>
{% else %}
<div class="cancel"></div>
<div class="cli-pict">
{% with obj=obj %}
{% include 'client/includes/show_logo.html' %}
{% endwith %}
</div>
{% endif %}
<div class="cli-info">
<div class="cli-top clearfix">
{% if obj.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 href="{% if not obj.paid_new_id %}{{ obj.get_permanent_url }}{% else %}{{ obj.get_paid_catalog_url }}{% endif %}">{{ obj.name|safe }}</a></div>
</header>
<div class="cli-descr">
{{ obj.main_title|safe }}
</div>
</div>
<div class="cli-bot clearfix">
<div class="cli-date">
{% with obj=obj %}
{% include 'client/includes/show_date_block.html' %}
{% endwith %}
</div>
{% if obj.country %}
<div class="cli-place">
<a href="{{ obj.catalog }}country/{{ obj.country.url }}/">{{ obj.country }}</a>, <a href="{{ obj.catalog }}city/{{ obj.city.url }}/">{{ obj.city }}</a>
{% if obj.place %}
, <a href="/places/{{ obj.place.url }}/">{{ obj.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=obj %}
{% include 'client/includes/calendar_button.html' with obj=obj%}
<div class="{% if request.user.is_authenticated%}note-wrap{% else %}note-wrap-disabled{% endif %}">
{% with note=obj|note_by_user:request.user %}
<a class="button green icon-note {% if note %}active{% endif %} note-button" href="/expo/add-note/{{ obj.url }}/">{% trans 'заметка' %}</a>
<div class="note-overlay">
<form action="">
<textarea name="note_text" class="note-text"> {{ note }}</textarea>
</form>
</div>
{% endwith %}
</div>
{% if request.user.is_admin %}
<div class="note-wrap">
<a class="button green " href="/admin/exposition/{{ obj.url }}/">{% trans 'изменить' %}</a>
</div>
{% endif %}
<div></div>
</div>
<div class="cli-s-buttons">
{% include 'client/buttons/booking_button.html' with object=obj %}
</div>
</div>
</div>
<footer class="clearfix">
<div class="cli-stats">
{% if obj.visitors %}
<span class="visitors" title="Посетители">{{ obj.visitors }}</span>
{% endif %}
{% if obj.members %}
<span class="participants" title="Участники">{{ obj.members }}</span>
{% endif %}
</div>
<div class="cli-tags">
{% include 'client/includes/exposition/tags.html' with obj=obj %}
</div>
</footer>
</li>
{% endfor %}
</ul>

@ -3,7 +3,8 @@
{% load template_filters %}
{% with objects=object_list %}
{% if objects %}
<ul class="cat-list cl-exhibitions">
{% include 'client/includes/banners/tops.html' %}
<ul class="cat-list cl-exhibitions">
{% for obj in objects %}
<li class="cl-item {% if obj.canceled %}canceled{% endif %}">

Loading…
Cancel
Save