forked from DGNum/gestioCOF
resuming views for stat
This commit is contained in:
commit
d19daa04b1
56 changed files with 1326 additions and 243 deletions
|
@ -1948,11 +1948,13 @@ class SupplierUpdate(SuccessMessageMixin, UpdateView):
|
|||
return super(SupplierUpdate, self).form_valid(form)
|
||||
|
||||
|
||||
# -----
|
||||
# ==========
|
||||
# Statistics
|
||||
# -----
|
||||
# ==========
|
||||
|
||||
# ---------------
|
||||
# Vues génériques
|
||||
# ---------------
|
||||
# source : docs.djangoproject.com/fr/1.10/topics/class-based-views/mixins/
|
||||
class JSONResponseMixin(object):
|
||||
"""
|
||||
|
@ -1991,12 +1993,72 @@ class HybridDetailView(JSONResponseMixin,
|
|||
return super(HybridDetailView, self).render_to_response(context)
|
||||
|
||||
|
||||
# Article Statistiques
|
||||
# Un résume des toutes les vues de stat d'un objet
|
||||
# NE REND PAS DE JSON
|
||||
class ObjectResumeStat(DetailView):
|
||||
template_name = 'kfet/object_stat_resume.html'
|
||||
context_object_name = 'lul'
|
||||
id_prefix = 'id_a_definir'
|
||||
# nombre de vues à résumer
|
||||
nb_stat = 2
|
||||
# Le combienième est celui par defaut ?
|
||||
# (entre 0 et nb_stat-1)
|
||||
nb_default = 0
|
||||
stat_labels = ['stat_1', 'stat_2']
|
||||
stat_urls = ['url_1', 'url_2']
|
||||
|
||||
|
||||
class ArticleStat(HybridDetailView):
|
||||
def get_context_data(self, **kwargs):
|
||||
# On hérite
|
||||
# Pas besoin, c'est essentiellement inutile
|
||||
# context = super(ObjectResumeStat, self).get_context_data(**kwargs)
|
||||
object_id = self.object.id
|
||||
context = {}
|
||||
stats = {}
|
||||
for i in range(self.nb_stat):
|
||||
stats[i] = {
|
||||
'label': self.stat_labels[i],
|
||||
'btn': "btn_%s_%d_%d" % (self.id_prefix,
|
||||
object_id,
|
||||
i),
|
||||
'url': reverse_lazy(self.stat_urls[i],
|
||||
args=[object_id]),
|
||||
}
|
||||
prefix = "%s_%d" % (self.id_prefix, object_id)
|
||||
context['id_prefix'] = prefix
|
||||
context['content_id'] = "content_%s" % prefix
|
||||
context['stats'] = stats
|
||||
context['default_stat'] = self.nb_default
|
||||
context['object_id'] = object_id
|
||||
return context
|
||||
|
||||
|
||||
# ------------------------
|
||||
# Article Satistiques Last
|
||||
# ------------------------
|
||||
ID_PREFIX_ART_LAST = "last_art"
|
||||
ID_PREFIX_ART_LAST_DAYS = "last_days_art"
|
||||
ID_PREFIX_ART_LAST_WEEKS = "last_weeks_art"
|
||||
|
||||
|
||||
# Un résumé de toutes les vues ArticleStatLast
|
||||
# NE REND PAS DE JSON
|
||||
class ArticleStatLastAll(ObjectResumeStat):
|
||||
model = Article
|
||||
template_name = 'kfet/article_stat.html'
|
||||
context_object_name = 'article'
|
||||
id_prefix = ID_PREFIX_ART_LAST
|
||||
nb_stat = 2
|
||||
nb_default = 1
|
||||
stat_labels = ["Dernières semaines", "Derniers jours"]
|
||||
stat_urls = ['kfet.article.stat.last.week',
|
||||
'kfet.article.stat.last.day']
|
||||
|
||||
|
||||
# Rend un graph des ventes sur une plage de temps à préciser.
|
||||
# Le graphique distingue les ventes sur LIQ et sur les autres trigrammes
|
||||
class ArticleStatLast(HybridDetailView):
|
||||
model = Article
|
||||
template_name = 'kfet/article_stat_last.html'
|
||||
context_object_name = 'article'
|
||||
end_date = timezone.now()
|
||||
id_prefix = "lol"
|
||||
|
@ -2006,7 +2068,7 @@ class ArticleStat(HybridDetailView):
|
|||
if self.request.GET.get('format') == 'json':
|
||||
return self.render_to_json_response(context)
|
||||
else:
|
||||
return super(ArticleStat, self).render_to_response(context)
|
||||
return super(ArticleStatLast, self).render_to_response(context)
|
||||
|
||||
# doit rendre un dictionnaire des dates
|
||||
# la première date correspond au début
|
||||
|
@ -2064,14 +2126,16 @@ class ArticleStat(HybridDetailView):
|
|||
context['nb_accounts'] = nb_accounts
|
||||
context['nb_liq'] = nb_liq
|
||||
# ID unique
|
||||
context['chart_id'] = "%s_%s" % (self.id_prefix,
|
||||
self.object.name)
|
||||
context['chart_id'] = "%s_%d" % (self.id_prefix,
|
||||
self.object.id)
|
||||
return context
|
||||
|
||||
|
||||
class ArticleStatDay(ArticleStat):
|
||||
# Rend les ventes des 7 derniers jours
|
||||
# Aujourd'hui non compris
|
||||
class ArticleStatLastDay(ArticleStatLast):
|
||||
end_date = this_morning()
|
||||
id_prefix = "last_week"
|
||||
id_prefix = ID_PREFIX_ART_LAST_DAYS
|
||||
|
||||
def get_dates(self, **kwargs):
|
||||
return lastdays(7)
|
||||
|
@ -2081,9 +2145,11 @@ class ArticleStatDay(ArticleStat):
|
|||
return daynames(days)
|
||||
|
||||
|
||||
class ArticleStatWeek(ArticleStat):
|
||||
# Rend les ventes de 7 dernières semaines
|
||||
# La semaine en cours n'est pas comprise
|
||||
class ArticleStatLastWeek(ArticleStatLast):
|
||||
end_date = this_monday_morning()
|
||||
id_prefix = "last_weeks"
|
||||
id_prefix = ID_PREFIX_ART_LAST_WEEKS
|
||||
|
||||
def get_dates(self, **kwargs):
|
||||
return lastweeks(7)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue