Skip to content

Commit

Permalink
add LoginRequiredMixins
Browse files Browse the repository at this point in the history
  • Loading branch information
tmvfb committed Jul 11, 2023
1 parent 531a05e commit c05be13
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions english_exercises_app/exercises/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# from django.urls import reverse
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import redirect, render
from django.template.defaulttags import register
from django.utils.translation import gettext_lazy as _
Expand All @@ -24,11 +25,13 @@ def split(value, key):
return value.split(key)


class ExerciseUploadView(TemplateView):
class ExerciseUploadView(LoginRequiredMixin, TemplateView):
"""
This class defines logic of file upload.
"""

login_url = "/users/login/"

def get(self, request):
form = FileForm()
return render(request, "exercises/upload.html", {"form": form})
Expand All @@ -49,11 +52,13 @@ def post(self, request):
return redirect("exercise_upload")


class ExerciseCreateView(TemplateView):
class ExerciseCreateView(LoginRequiredMixin, TemplateView):
"""
This class defines the parameters that are sent to text_processing module.
"""

login_url = "/users/login/"

def get(self, request):
form = FilterForm()
return render(request, "exercises/create.html", {"form": form})
Expand All @@ -75,12 +80,14 @@ def post(self, request):
return redirect("exercise_create")


class ExerciseShowView(TemplateView):
class ExerciseShowView(LoginRequiredMixin, TemplateView):
"""
This class shows exercises
and adds user input to database to maintain stats.
"""

login_url = "/users/login/"

def get(self, request):
# check if any file was uploaded
file = File.objects.filter(user=request.user).first()
Expand Down Expand Up @@ -205,11 +212,13 @@ def post(self, request):
)


class ExerciseStatsView(TemplateView):
class ExerciseStatsView(LoginRequiredMixin, TemplateView):
"""
Show exercise stats for the current user.
"""

login_url = "/users/login/"

def get(self, request):
user_stats = Exercise.objects.filter(user=request.user).order_by("-pk")

Expand Down

0 comments on commit c05be13

Please sign in to comment.