views.py 780 B

123456789101112131415161718192021222324
  1. from django.shortcuts import render
  2. from rest_framework.views import APIView
  3. from rest_framework.response import Response
  4. from django.views.generic import View
  5. from gauth.models import Location
  6. from .utils import get_review_count_by_month, get_review_count_by_month_all
  7. class ChartDataByMonth(APIView):
  8. def get(self, request, *args, **kwargs):
  9. location_id = request.GET['location_id']
  10. if location_id == 'all':
  11. res = get_review_count_by_month_all()
  12. else:
  13. res = get_review_count_by_month(location_id)
  14. return Response(res)
  15. class AnalyticsData(View):
  16. def get(self, request, *args, **kwargs):
  17. locations = Location.objects.all()
  18. return render(request, 'analytics.html', {'location_list': locations})