From 10d2b58fa7e01fa1ddbecc969b1aa1c460f8a3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Mon, 3 Apr 2017 17:06:32 +0200 Subject: [PATCH] clean some comments - fix: error if actions are empty in balance stats --- kfet/views.py | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/kfet/views.py b/kfet/views.py index a82e5cea..17de388e 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -2049,9 +2049,10 @@ class PkUrlMixin(object): class SingleResumeStat(JSONDetailView): - """ - Summarize all the stats of an object - Handles JSONResponse + """Manifest for a kind of a stat about an object. + + Returns JSON whose payload is an array containing descriptions of a stat: + url to retrieve data, label, ... """ id_prefix = '' @@ -2095,9 +2096,8 @@ class SingleResumeStat(JSONDetailView): ID_PREFIX_ACC_BALANCE = "balance_acc" -# Un résumé de toutes les vues ArticleStatBalance -# REND DU JSON class AccountStatBalanceList(PkUrlMixin, SingleResumeStat): + """Manifest for balance stats of an account.""" model = Account context_object_name = 'account' pk_url_kwarg = 'trigramme' @@ -2138,12 +2138,10 @@ class AccountStatBalanceList(PkUrlMixin, SingleResumeStat): class AccountStatBalance(PkUrlMixin, JSONDetailView): - """ - 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 - does not takes into account the balance offset + """Datasets of balance of an account. + + Operations and Transfers are taken into account. + """ model = Account pk_url_kwarg = 'trigramme' @@ -2253,8 +2251,9 @@ class AccountStatBalance(PkUrlMixin, JSONDetailView): "values": changes, }] context['is_time_chart'] = True - context['min_date'] = changes[-1]['at'] - context['max_date'] = changes[0]['at'] + if len(changes) > 0: + context['min_date'] = changes[-1]['at'] + context['max_date'] = changes[0]['at'] # TODO: offset return context @@ -2278,9 +2277,8 @@ ID_PREFIX_ACC_LAST_WEEKS = "last_weeks_acc" ID_PREFIX_ACC_LAST_MONTHS = "last_months_acc" -# Un résumé de toutes les vues ArticleStatLast -# NE REND PAS DE JSON class AccountStatOperationList(PkUrlMixin, SingleResumeStat): + """Manifest for operations stats of an account.""" model = Account context_object_name = 'account' pk_url_kwarg = 'trigramme' @@ -2301,10 +2299,7 @@ class AccountStatOperationList(PkUrlMixin, SingleResumeStat): class AccountStatOperation(ScaleMixin, PkUrlMixin, JSONDetailView): - """ - Returns a JSON containing the evolution a the personnal - consommation of a trigramme at the diffent dates specified - """ + """Datasets of operations of an account.""" model = Account pk_url_kwarg = 'trigramme' context_object_name = 'account' @@ -2363,9 +2358,8 @@ ID_PREFIX_ART_LAST_WEEKS = "last_weeks_art" ID_PREFIX_ART_LAST_MONTHS = "last_months_art" -# Un résumé de toutes les vues ArticleStatLast -# NE REND PAS DE JSON class ArticleStatSalesList(SingleResumeStat): + """Manifest for sales stats of an article.""" model = Article context_object_name = 'article' id_prefix = ID_PREFIX_ART_LAST @@ -2379,10 +2373,7 @@ class ArticleStatSalesList(SingleResumeStat): class ArticleStatSales(ScaleMixin, JSONDetailView): - """ - Returns a JSON containing the consommation - of an article at the diffent dates precised - """ + """Datasets of sales of an article.""" model = Article context_object_name = 'article'