WIP articleCategory stat
This commit is contained in:
parent
d19daa04b1
commit
14f021b5b0
6 changed files with 110 additions and 89 deletions
16
kfet/static/kfet/js/statistic.js
Normal file
16
kfet/static/kfet/js/statistic.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
jQuery(document).ready(function() {
|
||||
// FONCTIONS
|
||||
// Permet de raffraichir un champ, étant donné :
|
||||
// thing_url : l'url contenant le contenu
|
||||
// thing_div : le div où le mettre
|
||||
// empty_... : le truc à dire si on a un contenu vide
|
||||
function get_thing(thing_url, thing_div, empty_thing_message) {
|
||||
$.get(thing_url, function(data) {
|
||||
if(jQuery.trim(data).length==0) {
|
||||
thing_div.html(empty_thing_message);
|
||||
} else {
|
||||
thing_div.html(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
|
@ -83,13 +83,7 @@
|
|||
<div class="col-sm-12 col-md-6 nopadding">
|
||||
<div class="panel-md-margin">
|
||||
<h3>Ventes de {{ article.name }}</h3>
|
||||
<canvas id="myChart1" width="200" height="200"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-6 nopadding">
|
||||
<div class="panel-md-margin">
|
||||
<h3>Répartition des câlins</h3>
|
||||
<canvas id="myChart2" width="200" height="200"></canvas>
|
||||
<div id="stat_last"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /row -->
|
||||
|
@ -103,43 +97,23 @@
|
|||
<script src="{% static 'kfet/js/Chart.bundle.js' %}"></script>
|
||||
<script>
|
||||
jQuery(document).ready(function() {
|
||||
var ctx1 = $("#myChart1");
|
||||
var myChart = new Chart(ctx1, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
|
||||
datasets: [{
|
||||
label: '# of Votes',
|
||||
data: [12, 19, 3, 5, 2, 3],
|
||||
backgroundColor: [
|
||||
'rgba(255, 99, 132, 0.2)',
|
||||
'rgba(54, 162, 235, 0.2)',
|
||||
'rgba(255, 206, 86, 0.2)',
|
||||
'rgba(75, 192, 192, 0.2)',
|
||||
'rgba(153, 102, 255, 0.2)',
|
||||
'rgba(255, 159, 64, 0.2)'
|
||||
],
|
||||
borderColor: [
|
||||
'rgba(255,99,132,1)',
|
||||
'rgba(54, 162, 235, 1)',
|
||||
'rgba(255, 206, 86, 1)',
|
||||
'rgba(75, 192, 192, 1)',
|
||||
'rgba(153, 102, 255, 1)',
|
||||
'rgba(255, 159, 64, 1)'
|
||||
],
|
||||
borderWidth: 1
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
yAxes: [{
|
||||
ticks: {
|
||||
beginAtZero:true
|
||||
}
|
||||
}]
|
||||
}
|
||||
var stat_last = $("#stat_last");
|
||||
var stat_last_url = "{% url 'kfet.article.stat.last' article.id %}";
|
||||
get_thing(stat_last_url, stat_last, "Stat non trouvées :(");
|
||||
// FONCTIONS
|
||||
// Permet de raffraichir un champ, étant donné :
|
||||
// thing_url : l'url contenant le contenu
|
||||
// thing_div : le div où le mettre
|
||||
// empty_... : le truc à dire si on a un contenu vide
|
||||
function get_thing(thing_url, thing_div, empty_thing_message) {
|
||||
$.get(thing_url, function(data) {
|
||||
if(jQuery.trim(data).length==0) {
|
||||
thing_div.html(empty_thing_message);
|
||||
} else {
|
||||
thing_div.html(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
<!doctype html>
|
||||
{% load staticfiles %}
|
||||
|
||||
<body>
|
||||
<canvas id="{{ chart_id }}"></canvas>
|
||||
|
||||
{% comment %}
|
||||
TODO : supprimer les fichiers script jQuery et Chart.js
|
||||
{% endcomment %}
|
||||
<script src="{% static 'kfet/js/Chart.bundle.js' %}"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
|
||||
<script>
|
||||
jQuery(document).ready(function() {
|
||||
var ctx1 = $({{ chart_id }});
|
||||
|
|
|
@ -1,23 +1,6 @@
|
|||
<!doctype html>
|
||||
{% load staticfiles %}
|
||||
{% load dictionary_extras %}
|
||||
|
||||
<!-- TODO: SUPPRIMER-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
{# CSS #}
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
||||
<link href='https://fonts.googleapis.com/css?family=Roboto:400,700|Oswald:400,700|Roboto+Mono:400,700' rel='stylesheet' type='text/css'>
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'kfet/css/jquery-confirm.css' %}">
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'kfet/css/index.css' %}">
|
||||
|
||||
{# JS #}
|
||||
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
|
||||
</head>
|
||||
<!-- END TODO -->
|
||||
<body>
|
||||
<div class="btn-group btn-group-justified" role="group" aria-label="select-period">
|
||||
{% for k,stat in stats.items %}
|
||||
|
@ -32,17 +15,17 @@
|
|||
jQuery(document).ready(function() {
|
||||
// VARIABLES
|
||||
// défaut
|
||||
content_id = $("#{{content_id}}");
|
||||
{{if_prefix}}_content_id = $("#{{content_id}}");
|
||||
{% for k,stat in stats.items %}
|
||||
{% if k == default_stat %}
|
||||
default_url_{{id_prefix}} = "{{ stat | get_item:'url' }}";
|
||||
{{id_prefix}}_default_url = "{{ stat | get_item:'url' }}";
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
// INIT
|
||||
get_thing(default_url_{{id_prefix}}, content_id, "Ouppss ?");
|
||||
get_thing({{id_prefix}}_default_url, {{if_prefix}}_content_id, "Ouppss ?");
|
||||
{% for k,stat in stats.items %}
|
||||
$("#{{stat|get_item:'btn'}}").on('click', function() {
|
||||
get_thing("{{stat|get_item:'url'}}", content_id, "Ouuups ?")
|
||||
get_thing("{{stat|get_item:'url'}}", {{if_prefix}}_content_id, "Ouuups ?")
|
||||
});
|
||||
{% endfor %}
|
||||
// FONCTIONS
|
||||
|
|
|
@ -122,13 +122,13 @@ urlpatterns = [
|
|||
name = 'kfet.article.update'),
|
||||
|
||||
# Article - Statistics
|
||||
url('^articles/(?P<pk>\d+)/stat/last/$',
|
||||
url('^articles/(?P<pk>\d+)/stat/last$',
|
||||
views.ArticleStatLastAll.as_view(),
|
||||
name = 'kfet.article.stat.last'),
|
||||
url('^articles/(?P<pk>\d+)/stat/last/week/$',
|
||||
url('^articles/(?P<pk>\d+)/stat/last/week$',
|
||||
views.ArticleStatLastWeek.as_view(),
|
||||
name = 'kfet.article.stat.last.week'),
|
||||
url('^articles/(?P<pk>\d+)/stat/last/day/$',
|
||||
url('^articles/(?P<pk>\d+)/stat/last/day$',
|
||||
views.ArticleStatLastDay.as_view(),
|
||||
name = 'kfet.article.stat.last.day'),
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ from django.shortcuts import render, get_object_or_404, redirect
|
|||
from django.core.exceptions import PermissionDenied, ValidationError
|
||||
from django.core.cache import cache
|
||||
from django.views.generic import ListView, DetailView
|
||||
from django.views.generic.detail import BaseDetailView, SingleObjectTemplateResponseMixin
|
||||
from django.views.generic.detail import BaseListView, BaseDetailView, SingleObjectTemplateResponseMixin, MultipleObjectTemplateResponseMixin
|
||||
from django.views.generic.edit import CreateView, UpdateView, DeleteView, FormView
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.contrib import messages
|
||||
|
@ -1993,6 +1993,19 @@ class HybridDetailView(JSONResponseMixin,
|
|||
return super(HybridDetailView, self).render_to_response(context)
|
||||
|
||||
|
||||
# Rend un ListView en html sauf si on lui précise dans
|
||||
# l'appel à get que l'on veut un json auquel cas il en rend un
|
||||
class HybridListView(JSONResponseMixin,
|
||||
MultipleObjectTemplateResponseMixin,
|
||||
BaseListView):
|
||||
def render_to_response(self, context):
|
||||
# Look for a 'format=json' GET argument
|
||||
if self.request.GET.get('format') == 'json':
|
||||
return self.render_to_json_response(context)
|
||||
else:
|
||||
return super(HybridListView, self).render_to_response(context)
|
||||
|
||||
|
||||
# Un résume des toutes les vues de stat d'un objet
|
||||
# NE REND PAS DE JSON
|
||||
class ObjectResumeStat(DetailView):
|
||||
|
@ -2157,3 +2170,44 @@ class ArticleStatLastWeek(ArticleStatLast):
|
|||
def get_labels(self, **kwargs):
|
||||
weeks = lastweeks(7)
|
||||
return weeksnames(weeks)
|
||||
|
||||
# ------------------------------
|
||||
# Article Statistique Catégories
|
||||
# ------------------------------
|
||||
|
||||
class DurationStat(HybridListView):
|
||||
lookup_duration_type = 'day' # 'day' || 'week' || 'month'
|
||||
lookup_duration_number = 3 # ie ici : 3 jours
|
||||
|
||||
def get_end_date(self, **kwargs):
|
||||
if self.lookup_duration_type == 'day':
|
||||
return this_morning()
|
||||
elif self.lookup_duration_type == 'week':
|
||||
return this_monday_morning()
|
||||
elif self.lookup_duration_type == 'month':
|
||||
return this_first_month_day()
|
||||
else raise ValueError('duration_type invalid')
|
||||
|
||||
def get_begining_date(self, **kwargs):
|
||||
end_date = self.get_end_date(self, **kwargs)
|
||||
if self.lookup_duration_type == 'day':
|
||||
days = self.lookup_nb_duration
|
||||
elif self.lookup_duration_type == 'week':
|
||||
days = 7*self.lookup_nb_duration
|
||||
elif self.lookup_duration_type == 'month':
|
||||
days = 30*self.lookup_nb_duration
|
||||
else raise ValueError('this should not be happening.')
|
||||
delta = timezone.timedelta(days=days)
|
||||
return end_date - delta
|
||||
|
||||
|
||||
#TODO
|
||||
# class CategoryStatAll(DurationStat):
|
||||
# model = ArticleCategory
|
||||
# template_name = 'kfet/category_stat.html'
|
||||
#
|
||||
# def get_context_data(self, **kwargs):
|
||||
# context = {}
|
||||
# queryset = kwargs.pop('object_list', self.object_list)
|
||||
#
|
||||
# return context
|
||||
|
|
Loading…
Add table
Reference in a new issue