From bda56e1f271743444d24113cd71a75ee486df27f Mon Sep 17 00:00:00 2001 From: Ben C Date: Thu, 17 Mar 2022 06:47:24 -0700 Subject: [PATCH] Add return type hinting to Instructor --- Instructor/forms.py | 4 ++-- Instructor/views.py | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Instructor/forms.py b/Instructor/forms.py index 24b18a5..5d60a6b 100644 --- a/Instructor/forms.py +++ b/Instructor/forms.py @@ -220,7 +220,7 @@ class RubricForm(ModelForm): return "Please provide at least one row" return "Unknown Error" - def clean(self) -> dict: + def clean(self) -> dict[str, object]: """ This function is run to validate the entered data in the form. It ensures that the JSON is valid. If it isn't valid, it explains the error @@ -229,7 +229,7 @@ class RubricForm(ModelForm): :rtype: dict """ - super().clean() + super(ModelForm, self).clean() raw_json: str = self.cleaned_data.get("rubric") if raw_json is not None: diff --git a/Instructor/views.py b/Instructor/views.py index 40b5401..4ccced4 100644 --- a/Instructor/views.py +++ b/Instructor/views.py @@ -6,8 +6,8 @@ from django.conf import settings from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.core.exceptions import ValidationError -from django.db.models import Q -from django.http import Http404 +from django.db.models import Q, QuerySet +from django.http import Http404, HttpResponse from django.shortcuts import redirect from django.urls import reverse_lazy from django.views.generic import View, ListView, TemplateView, CreateView, UpdateView, DeleteView @@ -30,7 +30,7 @@ class UserClearView(LoginRequiredMixin, IsSuperUserMixin, View): http_method_names = ['post'] - def post(self, request): + def post(self, request) -> HttpResponse: """ This function is run when on a POST request. It clears out users that are not in the ActiveDirectory database. @@ -63,7 +63,7 @@ class AdminHomeView(LoginRequiredMixin, IsSuperUserMixin, TemplateView): template_name = "admin_home.html" - def get_context_data(self, **kwargs) -> dict: + def get_context_data(self, **kwargs) -> dict[str, object]: """ This function defines additional context to pass to the template in `AdminHomeView.template_name` @@ -94,7 +94,7 @@ class UserListView(LoginRequiredMixin, IsSuperUserMixin, TemplateView): http_method_names = ['get', 'post'] @staticmethod - def get_queryset(): + def get_queryset() -> QuerySet: """ This defines what objects from the database to list. We don't want Instructors to be listed, so we exclude them @@ -105,7 +105,7 @@ class UserListView(LoginRequiredMixin, IsSuperUserMixin, TemplateView): return User.objects.filter(is_superuser=False) - def post(self, *args, **kwargs): + def post(self, *args, **kwargs) -> HttpResponse: """ This function defines back-end behaviour when the user uses the POST method. It updates sessions and reviewers based off user input. @@ -123,7 +123,7 @@ class UserListView(LoginRequiredMixin, IsSuperUserMixin, TemplateView): - def get_context_data(self, **kwargs): + def get_context_data(self, **kwargs) -> dict[str, object]: """ This function gives additional context to pass to the template @@ -190,7 +190,7 @@ class RubricEditView(LoginRequiredMixin, IsSuperUserMixin, FormNameMixin, FormAl template_name = 'form_base.html' success_message = "Rubric Updated" - def form_valid(self, form): + def form_valid(self, form) -> HttpResponse: """ This function is run when the form is valid. This handles when an Instructor changes a Rubric that is used in a Review that has been graded. @@ -223,7 +223,7 @@ class RubricDupeView(LoginRequiredMixin, IsSuperUserMixin, View): http_method_names = ['post'] - def post(self, request, *args, **kwargs): + def post(self, request, *args, **kwargs) -> HttpResponse: """ This method is run when the view receives a POST request @@ -271,7 +271,7 @@ class RubricDeleteView(LoginRequiredMixin, IsSuperUserMixin, SuccessDeleteMixin, success_url = reverse_lazy('rubric-list') success_message = "Rubric Deleted" - def get_context_data(self, **kwargs): + def get_context_data(self, **kwargs) -> dict[str, object]: """ This function defines additional data that is passed to the template -- knotmirror 0.0.1