1234567891011121314151617181920212223242526272829303132333435363738 |
- from django.shortcuts import render
- from rest_framework.views import APIView
- from rest_framework.response import Response
- from django.views.generic import View
- from gauth.models import Location
- from name_extractor.models import Staff
- from .utils import get_review_count_by_month, get_review_count_by_week, last_month_reviews
- class ChartDataByMonth(APIView):
- def get(self, request, *args, **kwargs):
- location_id = request.GET['location_id']
- time_interval = request.GET['time_interval']
- if time_interval == 'month':
- res = get_review_count_by_month(location_id)
- else:
- res = get_review_count_by_week(location_id)
- return Response(res)
- class AnalyticsData(View):
- def get(self, request, *args, **kwargs):
- locations = Location.objects.all()
- return render(request, 'charts.html', {'location_list': locations})
- def monthly_report(requests, location_id):
- last_month_data = last_month_reviews(location_id=location_id)
- staffs = Staff.objects.filter(location_id=location_id).exclude(name_mentioned=0).order_by('-total_units')
- context = {
- 'this_month': last_month_data,
- 'staffs': staffs
- }
- return render(requests, 'last_month_report.html', context)
|