Commit c15ff9b5 authored by Christopher Løkken's avatar Christopher Løkken
Browse files

Pylinting of workout views

parent 73e26036
Pipeline #171123 failed with stages
in 35 seconds
backend/secfit/.vscode/
backend/secfit/*/migrations/__pycache__/
backend/secfit/*/__pycache__/
backend/secfit/**/__pycache__/
backend/secfit/db.sqlite3
venv/
backend/secfit/.coverage
.vscode
\ No newline at end of file
"""Contains views for the workouts application. These are mostly class-based views.
"""
import base64
import pickle
from collections import namedtuple
import re
from rest_framework import generics, mixins
from rest_framework import permissions
......@@ -9,8 +13,11 @@ from rest_framework.parsers import (
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.reverse import reverse
from django.db.models import Q
from rest_framework import filters
from rest_framework_simplejwt.tokens import RefreshToken
from django.db.models import Q
from django.core.exceptions import PermissionDenied
from django.core.signing import Signer
from workouts.parsers import MultipartJsonParser
from workouts.permissions import (
IsOwner,
......@@ -26,14 +33,6 @@ from workouts.models import Workout, Exercise, ExerciseInstance, WorkoutFile
from workouts.serializers import WorkoutSerializer, ExerciseSerializer
from workouts.serializers import RememberMeSerializer
from workouts.serializers import ExerciseInstanceSerializer, WorkoutFileSerializer
from django.core.exceptions import PermissionDenied
from rest_framework_simplejwt.tokens import RefreshToken
from rest_framework.response import Response
import json
from collections import namedtuple
import base64
import pickle
from django.core.signing import Signer
@api_view(["GET"])
......@@ -57,25 +56,24 @@ def api_root(request, format=None):
# Allow users to save a persistent session in their browser
class RememberMe(
mixins.ListModelMixin,
mixins.CreateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView,
):
mixins.ListModelMixin,
mixins.CreateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView,
):
serializer_class = RememberMeSerializer
def get(self, request):
if request.user.is_authenticated == False:
if not request.user.is_authenticated:
raise PermissionDenied
else:
return Response({"remember_me": self.rememberme()})
def post(self, request):
cookieObject = namedtuple("Cookies", request.COOKIES.keys())(
cookie_object = namedtuple("Cookies", request.COOKIES.keys())(
*request.COOKIES.values()
)
user = self.get_user(cookieObject)
user = self.get_user(cookie_object)
refresh = RefreshToken.for_user(user)
return Response(
{
......@@ -84,8 +82,8 @@ class RememberMe(
}
)
def get_user(self, cookieObject):
decode = base64.b64decode(cookieObject.remember_me)
def get_user(self, cookie_object):
decode = base64.b64decode(cookie_object.remember_me)
user, sign = pickle.loads(decode)
# Validate signature
......@@ -103,8 +101,10 @@ class RememberMe(
class WorkoutList(
mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView
):
mixins.ListModelMixin,
mixins.CreateModelMixin,
generics.GenericAPIView
):
"""Class defining the web response for the creation of a Workout, or displaying a list
of Workouts
......@@ -147,11 +147,11 @@ class WorkoutList(
class WorkoutDetail(
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView,
):
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView,
):
"""Class defining the web response for the details of an individual Workout.
HTTP methods: GET, PUT, DELETE
......@@ -176,8 +176,10 @@ class WorkoutDetail(
class ExerciseList(
mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView
):
mixins.ListModelMixin,
mixins.CreateModelMixin,
generics.GenericAPIView
):
"""Class defining the web response for the creation of an Exercise, or
a list of Exercises.
......@@ -196,11 +198,11 @@ class ExerciseList(
class ExerciseDetail(
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView,
):
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView,
):
"""Class defining the web response for the details of an individual Exercise.
HTTP methods: GET, PUT, PATCH, DELETE
......@@ -224,11 +226,11 @@ class ExerciseDetail(
class ExerciseInstanceList(
mixins.ListModelMixin,
mixins.CreateModelMixin,
CreateListModelMixin,
generics.GenericAPIView,
):
mixins.ListModelMixin,
mixins.CreateModelMixin,
CreateListModelMixin,
generics.GenericAPIView,
):
"""Class defining the web response for the creation"""
serializer_class = ExerciseInstanceSerializer
......@@ -255,11 +257,11 @@ class ExerciseInstanceList(
class ExerciseInstanceDetail(
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView,
):
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView,
):
serializer_class = ExerciseInstanceSerializer
permission_classes = [
permissions.IsAuthenticated
......@@ -283,11 +285,11 @@ class ExerciseInstanceDetail(
class WorkoutFileList(
mixins.ListModelMixin,
mixins.CreateModelMixin,
CreateListModelMixin,
generics.GenericAPIView,
):
mixins.ListModelMixin,
mixins.CreateModelMixin,
CreateListModelMixin,
generics.GenericAPIView,
):
queryset = WorkoutFile.objects.all()
serializer_class = WorkoutFileSerializer
......@@ -319,11 +321,11 @@ class WorkoutFileList(
class WorkoutFileDetail(
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView,
):
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView,
):
queryset = WorkoutFile.objects.all()
serializer_class = WorkoutFileSerializer
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment