Prechádzať zdrojové kódy

login required functionality added

Mohidul Islam 5 rokov pred
rodič
commit
4f10eb6e46
4 zmenil súbory, kde vykonal 25 pridanie a 8 odobranie
  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.response import Response
 from django.views.generic import View
+from django.contrib.auth.mixins import LoginRequiredMixin
 
 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
+from .utils import (
+    get_review_count_by_month,
+    get_review_count_by_week,
+    last_month_reviews
+)
 
 
 class ChartDataByMonth(APIView):
@@ -20,7 +25,7 @@ class ChartDataByMonth(APIView):
         return Response(res)
 
 
-class AnalyticsData(View):
+class AnalyticsData(LoginRequiredMixin, View):
     def get(self, request, *args, **kwargs):
         locations = Location.objects.all()
         return render(request, 'charts.html', {'location_list': locations})
@@ -29,7 +34,9 @@ class AnalyticsData(View):
 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')
+    staffs = Staff.objects.filter(location_id=location_id).\
+        exclude(name_mentioned=0).order_by('-total_units')
+
     context = {
 
         '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 review.review_utils import sync_all_review, reply_review
 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):
         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)
 
 
-class ReviewListView(View):
+class ReviewListView(LoginRequiredMixin, View):
 
     def get(self, request, *args, **kwargs):
         reviews = Review.objects.all().order_by('-update_time')
@@ -46,7 +48,7 @@ class ReviewListView(View):
         return render(request, 'review_list.html', context)
 
 
-class UnRepliedReviewList(View):
+class UnRepliedReviewList(LoginRequiredMixin, View):
 
     def post(self, request, *args, **kwargs):
         form = ReplyForm(self.request.POST)
@@ -101,7 +103,7 @@ class UnRepliedReviewList(View):
         return render(request, 'dashboard.html', context=context)
 
 
-class ReportView(View):
+class ReportView(LoginRequiredMixin, View):
 
     def get(self, request, *args, **kwargs):
         locations = Location.objects.all()

+ 2 - 0
name_extractor/views.py

@@ -1,8 +1,10 @@
 from django.shortcuts import render
 from gauth.models import Location
 from name_extractor.models import Staff
+from django.contrib.auth.decorators import login_required
 
 
+@login_required
 def leader_board(request, location_id):
     if location_id == '12345':
         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.models import Review, CustomReply
 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):
     review = Review.objects.filter(review_id=review_id).first()
     if review is None: