views.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. weekly_reviews_summary
  13. )
  14. class ChartDataByMonth(APIView):
  15. def get(self, request, *args, **kwargs):
  16. location_id = request.GET['location_id']
  17. time_interval = request.GET['time_interval']
  18. if time_interval == 'month':
  19. res = get_review_count_by_month(location_id)
  20. else:
  21. res = get_review_count_by_week(location_id)
  22. return Response(res)
  23. class AnalyticsData(LoginRequiredMixin, View):
  24. def get(self, request, *args, **kwargs):
  25. locations = Location.objects.all()
  26. return render(request, 'charts.html', {'location_list': locations})
  27. def monthly_report(requests, location_id):
  28. last_month_data = last_month_reviews(location_id=location_id)
  29. staffs = Staff.objects.filter(location_id=location_id).\
  30. exclude(name_mentioned=0).order_by('-total_units')
  31. context = {
  32. 'this_month': last_month_data,
  33. 'staffs': staffs
  34. }
  35. return render(requests, 'last_month_report.html', context)
  36. def weekly_report(requests, location_id):
  37. g_reviews, g_ratings = weekly_reviews_summary(location_id=location_id)
  38. g_staff_names = [
  39. 'montgomery', 'sarah', 'sarrah', 'sarra',
  40. 'moss', 'katy', 'neal', 'linda', 'narinesingh', 'rajesh',
  41. 'neal-domanski', 'kimberly'
  42. ]
  43. g_bad_reviews = g_reviews.filter(star_rating__lte=2)
  44. context = {
  45. 'google_ratings': g_ratings,
  46. 'google_staffs': g_staff_names,
  47. 'google_bad_reviews': g_bad_reviews
  48. }
  49. return render(requests, 'weekly_report.html', context)