forked from DGNum/gestioCOF
Frontend tout en JS
This commit is contained in:
parent
46f343b1ab
commit
0fcb29252b
7 changed files with 205 additions and 313 deletions
|
@ -7,7 +7,7 @@ from django.views.generic import ListView, DetailView
|
|||
from django.views.generic.list import BaseListView, MultipleObjectTemplateResponseMixin
|
||||
from django.views.generic.detail import BaseDetailView, SingleObjectTemplateResponseMixin
|
||||
from django.views.generic.edit import CreateView, UpdateView, DeleteView, FormView
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.core.urlresolvers import reverse, reverse_lazy
|
||||
from django.contrib import messages
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.contrib.auth import authenticate, login
|
||||
|
@ -1983,6 +1983,14 @@ class JSONResponseMixin(object):
|
|||
return context
|
||||
|
||||
|
||||
class JSONDetailView(JSONResponseMixin,
|
||||
BaseDetailView):
|
||||
"""
|
||||
Returns a DetailView that renders a JSON
|
||||
"""
|
||||
def render_to_response(self, context):
|
||||
return self.render_to_json_response(context)
|
||||
|
||||
class HybridDetailView(JSONResponseMixin,
|
||||
SingleObjectTemplateResponseMixin,
|
||||
BaseDetailView):
|
||||
|
@ -2013,12 +2021,11 @@ class HybridListView(JSONResponseMixin,
|
|||
return super(HybridListView, self).render_to_response(context)
|
||||
|
||||
|
||||
class ObjectResumeStat(DetailView):
|
||||
class ObjectResumeStat(JSONDetailView):
|
||||
"""
|
||||
Summarize all the stats of an object
|
||||
DOES NOT RETURN A JSON RESPONSE
|
||||
Handles JSONResponse
|
||||
"""
|
||||
template_name = 'kfet/object_stat_resume.html'
|
||||
context_object_name = ''
|
||||
id_prefix = ''
|
||||
# nombre de vues à résumer
|
||||
|
@ -2049,7 +2056,7 @@ class ObjectResumeStat(DetailView):
|
|||
'btn': "btn_%s_%d_%d" % (self.id_prefix,
|
||||
object_id,
|
||||
i),
|
||||
'url': reverse_lazy(self.stat_urls[i],
|
||||
'url': reverse(self.stat_urls[i],
|
||||
kwargs=dict(
|
||||
self.get_object_url_kwargs(),
|
||||
**url_kwargs[i]
|
||||
|
@ -2072,7 +2079,7 @@ ID_PREFIX_ACC_BALANCE = "balance_acc"
|
|||
|
||||
|
||||
# Un résumé de toutes les vues ArticleStatBalance
|
||||
# NE REND PAS DE JSON
|
||||
# REND DU JSON
|
||||
class AccountStatBalanceAll(ObjectResumeStat):
|
||||
model = Account
|
||||
context_object_name = 'account'
|
||||
|
@ -2105,9 +2112,9 @@ class AccountStatBalanceAll(ObjectResumeStat):
|
|||
return super(AccountStatBalanceAll, self).dispatch(*args, **kwargs)
|
||||
|
||||
|
||||
class AccountStatBalance(HybridDetailView):
|
||||
class AccountStatBalance(JSONDetailView):
|
||||
"""
|
||||
Returns a graph (or a JSON Response) of the evolution a the personnal
|
||||
Returns a JSON containing the evolution a the personnal
|
||||
balance of a trigramme between timezone.now() and `nb_days`
|
||||
ago (specified to the view as an argument)
|
||||
takes into account the Operations and the Transfers
|
||||
|
@ -2116,7 +2123,6 @@ class AccountStatBalance(HybridDetailView):
|
|||
model = Account
|
||||
trigramme_url_kwarg = 'trigramme'
|
||||
nb_date_url_kwargs = 'nb_date'
|
||||
template_name = 'kfet/account_stat_balance.html'
|
||||
context_object_name = 'account'
|
||||
id_prefix = ""
|
||||
|
||||
|
@ -2223,10 +2229,10 @@ class AccountStatBalance(HybridDetailView):
|
|||
nb_days_string = 'anytime'
|
||||
else:
|
||||
nb_days_string = str(int(nb_days))
|
||||
context['changes'] = changes
|
||||
context['chart_id'] = "%s_%s_%s_days" % (self.id_prefix,
|
||||
self.object.id,
|
||||
nb_days_string)
|
||||
context['charts'] = [ { "color": "rgb(255, 99, 132)",
|
||||
"label": "Balance",
|
||||
"values": changes } ]
|
||||
context['is_time_chart'] = True
|
||||
context['min_date'] = changes[len(changes)-1]['at']
|
||||
context['max_date'] = changes[0]['at']
|
||||
# TODO: offset
|
||||
|
@ -2272,14 +2278,13 @@ class AccountStatLastAll(ObjectResumeStat):
|
|||
return super(AccountStatLastAll, self).dispatch(*args, **kwargs)
|
||||
|
||||
|
||||
class AccountStatLast(HybridDetailView):
|
||||
class AccountStatLast(JSONDetailView):
|
||||
"""
|
||||
Returns a graph (or a JSON Response) of the evolution a the personnal
|
||||
Returns a JSON containing the evolution a the personnal
|
||||
consommation of a trigramme at the diffent dates specified
|
||||
"""
|
||||
model = Account
|
||||
trigramme_url_kwarg = 'trigramme'
|
||||
template_name = 'kfet/account_stat_last.html'
|
||||
context_object_name = 'account'
|
||||
end_date = timezone.now()
|
||||
id_prefix = ""
|
||||
|
@ -2331,10 +2336,9 @@ class AccountStatLast(HybridDetailView):
|
|||
operations = self.sort_operations()
|
||||
for i in operations:
|
||||
nb_ventes[i] = tot_ventes(operations[i])
|
||||
context['nb_ventes'] = nb_ventes
|
||||
# ID unique
|
||||
context['chart_id'] = "%s_%d" % (self.id_prefix,
|
||||
self.object.id)
|
||||
context['charts'] = [ { "color": "rgb(255, 99, 132)",
|
||||
"label": "NB items achetés",
|
||||
"values": nb_ventes } ]
|
||||
return context
|
||||
|
||||
@method_decorator(login_required)
|
||||
|
@ -2411,13 +2415,12 @@ class ArticleStatLastAll(ObjectResumeStat):
|
|||
return super(ArticleStatLastAll, self).dispatch(*args, **kwargs)
|
||||
|
||||
|
||||
class ArticleStatLast(HybridDetailView):
|
||||
class ArticleStatLast(JSONDetailView):
|
||||
"""
|
||||
Returns a graph (or a JSON Response) of the consommation
|
||||
Returns a JSON containing the consommation
|
||||
of an article at the diffent dates precised
|
||||
"""
|
||||
model = Article
|
||||
template_name = 'kfet/article_stat_last.html'
|
||||
context_object_name = 'article'
|
||||
end_date = timezone.now()
|
||||
id_prefix = ""
|
||||
|
@ -2478,12 +2481,15 @@ class ArticleStatLast(HybridDetailView):
|
|||
operations[i]
|
||||
.exclude(group__on_acc__trigramme='LIQ')
|
||||
)
|
||||
context['nb_ventes'] = nb_ventes
|
||||
context['nb_accounts'] = nb_accounts
|
||||
context['nb_liq'] = nb_liq
|
||||
# ID unique
|
||||
context['chart_id'] = "%s_%d" % (self.id_prefix,
|
||||
self.object.id)
|
||||
context['charts'] = [ { "color": "rgb(255, 99, 132)",
|
||||
"label": "Toutes consommations",
|
||||
"values": nb_ventes },
|
||||
{ "color": "rgb(54, 162, 235)",
|
||||
"label": "LIQ",
|
||||
"values": nb_liq },
|
||||
{ "color": "rgb(255, 205, 86)",
|
||||
"label": "Comptes K-Fêt",
|
||||
"values": nb_accounts } ]
|
||||
return context
|
||||
|
||||
@method_decorator(login_required)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue