Add separate libraries
This commit is contained in:
86
core/views/charts.py
Normal file
86
core/views/charts.py
Normal file
@@ -0,0 +1,86 @@
|
||||
import pprint
|
||||
from datetime import datetime
|
||||
|
||||
import stripe
|
||||
from chartjs.views.lines import BaseLineChartView
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.shortcuts import redirect, render
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import View
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.generic.edit import CreateView
|
||||
from rest_framework.parsers import JSONParser
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from core.forms import NewUserForm
|
||||
from core.lib.products import assemble_plan_map
|
||||
from core.models import Plan, Session, User
|
||||
|
||||
class CSRFExemptMixin(object):
|
||||
@method_decorator(csrf_exempt)
|
||||
def dispatch(self, *args, **kwargs):
|
||||
return super(CSRFExemptMixin, self).dispatch(*args, **kwargs)
|
||||
|
||||
|
||||
class VolumeChartJSONView(CSRFExemptMixin, LoginRequiredMixin, BaseLineChartView):
|
||||
def post(self, request, *args, **kwargs):
|
||||
print("POST")
|
||||
context = self.get_context_data(**kwargs)
|
||||
return self.render_to_response(context)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super(VolumeChartJSONView, self).get_context_data(**kwargs)
|
||||
# data["colors"] = islice(next_color(), 0, 50)
|
||||
print("KWARGS", kwargs)
|
||||
return data
|
||||
|
||||
def get_labels(self):
|
||||
"""Return 7 labels for the x-axis."""
|
||||
return ["January", "February", "March", "April", "May", "June", "July"]
|
||||
|
||||
def get_providers(self):
|
||||
"""Return names of datasets."""
|
||||
return ["Central", "Eastside", "Westside"]
|
||||
|
||||
def get_data(self):
|
||||
"""Return 3 datasets to plot."""
|
||||
|
||||
return [
|
||||
[75, 44, 92, 11, 44, 95, 35],
|
||||
[41, 92, 18, 3, 73, 87, 92],
|
||||
[87, 21, 94, 3, 90, 13, 65],
|
||||
]
|
||||
|
||||
|
||||
class SentimentChartJSONView(CSRFExemptMixin, LoginRequiredMixin, BaseLineChartView):
|
||||
def post(self, request, *args, **kwargs):
|
||||
print("POST")
|
||||
print(request.POST)
|
||||
context = self.get_context_data(**kwargs)
|
||||
return self.render_to_response(context)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super(SentimentChartJSONView, self).get_context_data(**kwargs)
|
||||
# data["colors"] = islice(next_color(), 0, 50)
|
||||
print("KWARGS", kwargs)
|
||||
return data
|
||||
|
||||
def get_labels(self):
|
||||
"""Return 7 labels for the x-axis."""
|
||||
return ["January", "February", "March", "April", "May", "June", "July"]
|
||||
|
||||
def get_providers(self):
|
||||
"""Return names of datasets."""
|
||||
return ["Central", "Eastside", "Westside"]
|
||||
|
||||
def get_data(self):
|
||||
"""Return 3 datasets to plot."""
|
||||
|
||||
return [
|
||||
[75, 44, 92, 11, 44, 95, 35],
|
||||
[41, 92, 18, 3, 73, 87, 92],
|
||||
[87, 21, 94, 3, 90, 13, 65],
|
||||
]
|
||||
Reference in New Issue
Block a user