views.py 1.2 KB

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