-
Notifications
You must be signed in to change notification settings - Fork 3
/
views.py
33 lines (27 loc) · 970 Bytes
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- coding: utf-8 -*-
from django.views.generic import TemplateView
from chartflo.utils import ChartDataPack
class ChartsView(TemplateView):
template_name = 'chartflo/charts.html'
graph_type = "pie"
title = ""
def get_data(self):
return {}
def get_context_data(self, **kwargs):
context = super(ChartsView, self).get_context_data(**kwargs)
# get data
P = ChartDataPack()
dataset = self.get_data()
# package the data
datapack = P.package("chart_id", self.title, dataset)
# options
datapack['legend'] = True
datapack['export'] = False
context['datapack'] = datapack
context["graph_type"] = self.graph_type
context["title"] = context["label"] = self.title
context["chart_url"] = self._get_chart_url()
return context
def _get_chart_url(self):
url = "chartflo/charts/" + self.graph_type + ".html"
return url