1. multiple tags in select field fixed

2. admin statistic (section/event) date range error fixed; 'no data" message added
remotes/origin/stage3_release
Alexander Burdeiny 10 years ago
parent 19cae53c1c
commit 6991710efa
  1. 7
      article/admin_urls.py
  2. 2
      static/custom_js/select_tag.js
  3. 97
      stats_collector/admin.py
  4. 18
      stats_collector/forms.py
  5. 3
      templates/admin/stats/event_stat.html
  6. 110
      templates/admin/stats/section_stat.html
  7. 4
      theme/admin.py

@ -4,10 +4,13 @@ from admin import BlogList, BlogView, NewsList, NewsView, ArticleDeleteView
urlpatterns = patterns('article.admin',
url(r'^blog/all/$', BlogList.as_view()),
url(r'^blog/$', BlogView.as_view()),
url(r'^delete/(?P<slug>.*)/$', ArticleDeleteView.as_view()),
url(r'^news/all/$', NewsList.as_view()),
url(r'^delete/(?P<slug>.*)/$', ArticleDeleteView.as_view()),
url(r'^blog/$', BlogView.as_view()),
url(r'^news/$', NewsView.as_view()),
url(r'^blog/(?P<slug>.*)/$', BlogView.as_view()),
url(r'^news/(?P<slug>.*)/$', NewsView.as_view()),
)

@ -49,4 +49,4 @@ $(document).ready(function(){
});
});//end get
});//end change
});//end ready
});//end ready

@ -194,32 +194,32 @@ class StatSectionsView(StatBaseView):
if self.request.is_ajax():
return context
pt = self.get_pivot_table()
# change numpy.nan values to python's None (js null with json)
# result = pt.where(pt.notnull(), None)
result = pt.fillna(value=0)
result_summary = result.sum().to_dict()
context['columns'] = self.get_column_names()
# if self.pt_columns != 'kind':
# result.columns = list(map(lambda x: str(int(x)), result.columns.tolist()))
data = list(map(
# lambda x: {'date': pydate_to_js(x[0]), 'attrs': json.dumps(x[1:]).replace('[', '').replace(']', '')},
lambda x: json.dumps(list(x), cls=CustomJSEncoder),
result.itertuples()
))
data_summary = []
for key, val in result_summary.items():
data_summary.append({
'name': self.get_col_map()[key],
'val': val
})
context['data'] = data
context['data_summary'] = data_summary
if self.qs:
pt = self.get_pivot_table()
# change numpy.nan values to python's None (js null with json)
# result = pt.where(pt.notnull(), None)
result = pt.fillna(value=0)
result_summary = result.sum().to_dict()
context['columns'] = self.get_column_names()
# if self.pt_columns != 'kind':
# result.columns = list(map(lambda x: str(int(x)), result.columns.tolist()))
data = list(map(
# lambda x: {'date': pydate_to_js(x[0]), 'attrs': json.dumps(x[1:]).replace('[', '').replace(']', '')},
lambda x: json.dumps(list(x), cls=CustomJSEncoder),
result.itertuples()
))
data_summary = []
for key, val in result_summary.items():
data_summary.append({
'name': self.get_col_map()[key],
'val': val
})
context['data'] = data
context['data_summary'] = data_summary
return context
@ -257,6 +257,7 @@ class EventStatView(StatBaseView):
return self.render_to_response(self.get_context_data(form=form))
def get_params_form(self):
form_kwargs = {}
country_ids = set()
city_ids = set()
theme_ids = set()
@ -271,27 +272,29 @@ class EventStatView(StatBaseView):
'exposition__tag',
'conference__tag',
]
e_country_ids, c_country_ids, e_city_ids, c_city_ids, e_theme_ids, c_theme_ids, e_tag_ids, c_tag_ids = \
zip(*self.qs.values_list(*val_list))
country_ids.update(e_country_ids)
country_ids.update(c_country_ids)
city_ids.update(e_city_ids)
city_ids.update(c_city_ids)
theme_ids.update(e_theme_ids)
theme_ids.update(e_theme_ids)
tag_ids.update(e_tag_ids)
tag_ids.update(c_tag_ids)
for ids_set in [country_ids, city_ids, theme_ids, tag_ids]:
if None in ids_set:
ids_set.remove(None)
form_kwargs = {
'country_choices': Country.objects.language().filter(pk__in=country_ids).values_list('pk', 'name').order_by('name'),
'city_choices': City.objects.language().filter(pk__in=city_ids).values_list('pk', 'name').order_by('name'),
'theme_choices': Theme.objects.language().filter(pk__in=theme_ids).values_list('pk', 'name').order_by('name'),
'tag_choices': Tag.objects.language().filter(pk__in=tag_ids).values_list('pk', 'name').order_by('name'),
'data': self.request.POST
}
values_list = self.qs.values_list(*val_list)
if values_list:
e_country_ids, c_country_ids, e_city_ids, c_city_ids, e_theme_ids, c_theme_ids, e_tag_ids, c_tag_ids = \
zip(*values_list)
country_ids.update(e_country_ids)
country_ids.update(c_country_ids)
city_ids.update(e_city_ids)
city_ids.update(c_city_ids)
theme_ids.update(e_theme_ids)
theme_ids.update(e_theme_ids)
tag_ids.update(e_tag_ids)
tag_ids.update(c_tag_ids)
for ids_set in [country_ids, city_ids, theme_ids, tag_ids]:
if None in ids_set:
ids_set.remove(None)
form_kwargs = {
'country_choices': Country.objects.language().filter(pk__in=country_ids).values_list('pk', 'name').order_by('name'),
'city_choices': City.objects.language().filter(pk__in=city_ids).values_list('pk', 'name').order_by('name'),
'theme_choices': Theme.objects.language().filter(pk__in=theme_ids).values_list('pk', 'name').order_by('name'),
'tag_choices': Tag.objects.language().filter(pk__in=tag_ids).values_list('pk', 'name').order_by('name'),
'data': self.request.POST
}
form = self.params_form_cls(**form_kwargs)
return form

@ -27,8 +27,14 @@ class BaseDateFilter(forms.Form):
date_end = forms.DateField(label=_(u'Дата окончания'), input_formats=['%Y-%m-%d', '%d.%m.%Y'], required=False)
def clean(self):
if not self.cleaned_data['date_begin'] and self.cleaned_data['date_end']:
self.cleaned_data['date_begin'] = self.cleaned_data['date_end'] - timedelta(days=14)
date_begin = self.cleaned_data['date_begin']
date_end = self.cleaned_data['date_end']
if not date_begin and date_end:
self.cleaned_data['date_begin'] = date_end - timedelta(days=14)
elif date_begin and date_end and date_begin >= date_end:
raise forms.ValidationError(
_(u'Дата начала должна быть меньше даты окончания.'),
code='invalid')
return self.cleaned_data
@ -70,10 +76,10 @@ class EventsParamsFilter(forms.Form):
tag = forms.TypedMultipleChoiceField(label=_(u'Тег'), required=False, coerce=int)
def __init__(self, *args, **kwargs):
country_choices = kwargs.pop('country_choices')
city_choices = kwargs.pop('city_choices')
theme_choices = kwargs.pop('theme_choices')
tag_choices = kwargs.pop('tag_choices')
country_choices = kwargs.pop('country_choices', [])
city_choices = kwargs.pop('city_choices', [])
theme_choices = kwargs.pop('theme_choices', [])
tag_choices = kwargs.pop('tag_choices', [])
super(EventsParamsFilter, self).__init__(*args, **kwargs)

@ -146,6 +146,9 @@
</div>
<div class="span9">
{% if not data %}
{% trans "Нет данных" %}
{% endif %}
<div id="curve_chart"></div>
<div id="bar_chart"></div>
</div>

@ -7,58 +7,62 @@
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart'], 'language': '{{ LANGUAGE_CODE }}'});
{% if data %}
function drawChart() {
var data = google.visualization.arrayToDataTable([
{% autoescape off %}
[{type: 'date', label: '{% trans "Дата" %}'}, {{ columns }}],
{% for item in data %}
{{ item }},
{% endfor %}
{% endautoescape %}
]);
var options = {
title: 'Статистика разделов',
legend: { position: 'bottom' },
vAxis: {
title: '{% trans "Просмотры" %}'
},
width: 900,
height: 500,
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
google.charts.setOnLoadCallback(drawChart);
{% endif %}
{% if data_summary %}
function drawSummaryChart() {
var data = google.visualization.arrayToDataTable([
{% autoescape off %}
['name', '{% trans "Просмотры" %}', { role: 'annotation' }],
{% for item in data_summary %}
['{{ item.name }}', {{ item.val }}, {{ item.val }}],
{% endfor %}
{% endautoescape %}
]);
var options = {
title: '{% trans "Сумарные данные" %}',
// legend: { position: 'bottom' },
// xAxis: {
// title: '{% trans "Просмотры" %}'
// },
legend: { position: "none" },
width: 900,
height: 500,
};
var rchart = new google.visualization.BarChart(document.getElementById('bar_chart'));
rchart.draw(data, options);
}
google.charts.setOnLoadCallback(drawSummaryChart);
{% endif %}
function drawChart() {
var data = google.visualization.arrayToDataTable([
{% autoescape off %}
[{type: 'date', label: '{% trans "Дата" %}'}, {{ columns }}],
{% for item in data %}
{{ item }},
{% endfor %}
{% endautoescape %}
]);
var options = {
title: 'Статистика разделов',
legend: { position: 'bottom' },
vAxis: {
title: '{% trans "Просмотры" %}'
},
width: 900,
height: 500,
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
function drawSummaryChart() {
var data = google.visualization.arrayToDataTable([
{% autoescape off %}
['name', '{% trans "Просмотры" %}', { role: 'annotation' }],
{% for item in data_summary %}
['{{ item.name }}', {{ item.val }}, {{ item.val }}],
{% endfor %}
{% endautoescape %}
]);
var options = {
title: '{% trans "Сумарные данные" %}',
// legend: { position: 'bottom' },
// xAxis: {
// title: '{% trans "Просмотры" %}'
// },
legend: { position: "none" },
width: 900,
height: 500,
};
var rchart = new google.visualization.BarChart(document.getElementById('bar_chart'));
rchart.draw(data, options);
}
google.charts.setOnLoadCallback(drawChart);
google.charts.setOnLoadCallback(drawSummaryChart);
function initStatFilterForm() {
form = $('form#stat_filter_form');
@ -95,7 +99,6 @@
}
});
}
console.log(data);
})
});
}
@ -185,6 +188,9 @@
</div>
<div class="span9">
{% if not data %}
{% trans "Нет данных" %}
{% endif %}
<div id="curve_chart"></div>
<div id="bar_chart"></div>
</div>

@ -157,9 +157,9 @@ def search_tag(request):
if not term:
qs = Tag.objects.filter(theme__id__in=theme_ids).order_by('translations__name')
qs = Tag.objects.filter(theme__id__in=theme_ids).order_by('translations__name').distinct()
else:
qs = Tag.objects.filter(theme__id__in=theme_ids, translations__name__contains=term)
qs = Tag.objects.filter(theme__id__in=theme_ids, translations__name__contains=term).distinct()
tags = [{'id': tag.id, 'label': '%s(%s)'%(tag.name, tag.theme.name)} for tag in qs]

Loading…
Cancel
Save