Преглед на файлове

login required functionality added

Mohidul Islam преди 5 години
родител
ревизия
4f10eb6e46
променени са 4 файла, в които са добавени 25 реда и са изтрити 8 реда
  1. 10 3
      analytics/views.py
  2. 6 4
      dashboard/views.py
  3. 2 0
      name_extractor/views.py
  4. 7 1
      nlu_job/views.py

+ 10 - 3
analytics/views.py

@@ -2,11 +2,16 @@ from django.shortcuts import render
 from rest_framework.views import APIView
 from rest_framework.views import APIView
 from rest_framework.response import Response
 from rest_framework.response import Response
 from django.views.generic import View
 from django.views.generic import View
+from django.contrib.auth.mixins import LoginRequiredMixin
 
 
 from gauth.models import Location
 from gauth.models import Location
 from name_extractor.models import Staff
 from name_extractor.models import Staff
 
 
-from .utils import get_review_count_by_month, get_review_count_by_week, last_month_reviews
+from .utils import (
+    get_review_count_by_month,
+    get_review_count_by_week,
+    last_month_reviews
+)
 
 
 
 
 class ChartDataByMonth(APIView):
 class ChartDataByMonth(APIView):
@@ -20,7 +25,7 @@ class ChartDataByMonth(APIView):
         return Response(res)
         return Response(res)
 
 
 
 
-class AnalyticsData(View):
+class AnalyticsData(LoginRequiredMixin, View):
     def get(self, request, *args, **kwargs):
     def get(self, request, *args, **kwargs):
         locations = Location.objects.all()
         locations = Location.objects.all()
         return render(request, 'charts.html', {'location_list': locations})
         return render(request, 'charts.html', {'location_list': locations})
@@ -29,7 +34,9 @@ class AnalyticsData(View):
 def monthly_report(requests, location_id):
 def monthly_report(requests, location_id):
     last_month_data = last_month_reviews(location_id=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')
+    staffs = Staff.objects.filter(location_id=location_id).\
+        exclude(name_mentioned=0).order_by('-total_units')
+
     context = {
     context = {
 
 
         'this_month': last_month_data,
         'this_month': last_month_data,

+ 6 - 4
dashboard/views.py

@@ -8,9 +8,11 @@ from review.forms import ReplyForm
 from gauth.models import Location
 from gauth.models import Location
 from review.review_utils import sync_all_review, reply_review
 from review.review_utils import sync_all_review, reply_review
 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
+from django.contrib.auth.mixins import LoginRequiredMixin
 
 
 
 
-class ReviewListByLocationView(View):
+
+class ReviewListByLocationView(LoginRequiredMixin, View):
 
 
     def get(self, request, location_id, *args, **kwargs):
     def get(self, request, location_id, *args, **kwargs):
         reviews = Review.objects.filter(location_id=location_id).order_by('-update_time')
         reviews = Review.objects.filter(location_id=location_id).order_by('-update_time')
@@ -28,7 +30,7 @@ class ReviewListByLocationView(View):
         return render(request, 'review_list.html', context)
         return render(request, 'review_list.html', context)
 
 
 
 
-class ReviewListView(View):
+class ReviewListView(LoginRequiredMixin, View):
 
 
     def get(self, request, *args, **kwargs):
     def get(self, request, *args, **kwargs):
         reviews = Review.objects.all().order_by('-update_time')
         reviews = Review.objects.all().order_by('-update_time')
@@ -46,7 +48,7 @@ class ReviewListView(View):
         return render(request, 'review_list.html', context)
         return render(request, 'review_list.html', context)
 
 
 
 
-class UnRepliedReviewList(View):
+class UnRepliedReviewList(LoginRequiredMixin, View):
 
 
     def post(self, request, *args, **kwargs):
     def post(self, request, *args, **kwargs):
         form = ReplyForm(self.request.POST)
         form = ReplyForm(self.request.POST)
@@ -101,7 +103,7 @@ class UnRepliedReviewList(View):
         return render(request, 'dashboard.html', context=context)
         return render(request, 'dashboard.html', context=context)
 
 
 
 
-class ReportView(View):
+class ReportView(LoginRequiredMixin, View):
 
 
     def get(self, request, *args, **kwargs):
     def get(self, request, *args, **kwargs):
         locations = Location.objects.all()
         locations = Location.objects.all()

+ 2 - 0
name_extractor/views.py

@@ -1,8 +1,10 @@
 from django.shortcuts import render
 from django.shortcuts import render
 from gauth.models import Location
 from gauth.models import Location
 from name_extractor.models import Staff
 from name_extractor.models import Staff
+from django.contrib.auth.decorators import login_required
 
 
 
 
+@login_required
 def leader_board(request, location_id):
 def leader_board(request, location_id):
     if location_id == '12345':
     if location_id == '12345':
         staffs = Staff.objects.all().exclude(total_units=0.00).order_by('-total_units')
         staffs = Staff.objects.all().exclude(total_units=0.00).order_by('-total_units')

+ 7 - 1
nlu_job/views.py

@@ -4,11 +4,17 @@ from django.shortcuts import redirect
 from review.forms import ReplyForm
 from review.forms import ReplyForm
 from review.models import Review, CustomReply
 from review.models import Review, CustomReply
 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
+from django.contrib.auth.decorators import login_required
 
 
 
 
-from .nlu_utils import model_inference, analyze_inference, filter_with_last_ten_reviews
+from .nlu_utils import (
+    model_inference,
+    analyze_inference,
+    filter_with_last_ten_reviews
+)
 
 
 
 
+@login_required
 def predict_report(request, review_id):
 def predict_report(request, review_id):
     review = Review.objects.filter(review_id=review_id).first()
     review = Review.objects.filter(review_id=review_id).first()
     if review is None:
     if review is None: