views.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 django.contrib.auth.mixins import LoginRequiredMixin
  6. from gauth.models import Location
  7. from name_extractor.models import Staff
  8. from .utils import (
  9. get_review_count_by_month,
  10. get_review_count_by_week,
  11. last_month_reviews
  12. )
  13. class ChartDataByMonth(APIView):
  14. def get(self, request, *args, **kwargs):
  15. location_id = request.GET['location_id']
  16. time_interval = request.GET['time_interval']
  17. if time_interval == 'month':
  18. res = get_review_count_by_month(location_id)
  19. else:
  20. res = get_review_count_by_week(location_id)
  21. return Response(res)
  22. class AnalyticsData(LoginRequiredMixin, View):
  23. def get(self, request, *args, **kwargs):
  24. locations = Location.objects.all()
  25. return render(request, 'charts.html', {'location_list': locations})
  26. def monthly_report(requests, location_id):
  27. last_month_data = last_month_reviews(location_id=location_id)
  28. staffs = Staff.objects.filter(location_id=location_id).\
  29. exclude(name_mentioned=0).order_by('-total_units')
  30. context = {
  31. 'this_month': last_month_data,
  32. 'staffs': staffs
  33. }
  34. return render(requests, 'last_month_report.html', context)