views.py 835 B

12345678910111213141516171819202122232425
  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_week
  7. class ChartDataByMonth(APIView):
  8. def get(self, request, *args, **kwargs):
  9. location_id = request.GET['location_id']
  10. time_interval = request.GET['time_interval']
  11. if time_interval == 'month':
  12. res = get_review_count_by_month(location_id)
  13. else:
  14. res = get_review_count_by_week(location_id)
  15. return Response(res)
  16. class AnalyticsData(View):
  17. def get(self, request, *args, **kwargs):
  18. locations = Location.objects.all()
  19. return render(request, 'charts.html', {'location_list': locations})