From f041ae9966ac2ca87b605568b535c35c36ef2e5c Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 14 May 2019 17:48:27 -0400 Subject: [PATCH] Force evaluation of statistic data for Python 3 Signed-off-by: Roberto Rosario --- mayan/apps/mayan_statistics/classes.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mayan/apps/mayan_statistics/classes.py b/mayan/apps/mayan_statistics/classes.py index 2455acaaf0..1ba7be3414 100644 --- a/mayan/apps/mayan_statistics/classes.py +++ b/mayan/apps/mayan_statistics/classes.py @@ -46,6 +46,17 @@ class Statistic(object): _registry = {} renderer = None + @staticmethod + def evaluate(data): + try: + for key, value in data.items(): + return {key: Statistic.evaluate(data=value)} + except AttributeError: + if type(data) == map: + data = list(data) + + return data + @staticmethod def purge_schedules(): PeriodicTask = apps.get_model( @@ -119,7 +130,12 @@ class Statistic(object): return force_text(self.label) def execute(self): - self.store_results(results=self.func()) + results=self.func() + # Force evaluation of results to be able to store it serialized + # Needed for Python 3 + # PY3 + results = Statistic.evaluate(data=results) + self.store_results(results=results) def get_chart_data(self): return self.renderer(data=self.get_results()).get_chart_data()