From 468d5df81fa7d77cd6daaaae7921f27f4a8404f7 Mon Sep 17 00:00:00 2001 From: Ben C Date: Thu, 11 Nov 2021 20:21:50 -0500 Subject: [PATCH] Touched up comments and best practices --- CodeReview/settings.py | 6 ++++-- CodeReview/urls.py | 2 +- Instructor/models.py | 13 +++++++------ Instructor/views.py | 20 +++++++++++--------- Main/forms.py | 5 +++-- Main/models.py | 17 ++++++++++------- Main/templates/base.html | 8 ++++++-- Main/templatetags/common_tags.py | 2 +- Main/views.py | 7 ++++--- Users/forms.py | 3 ++- Users/ldap_auth.py | 21 +++++++++++++-------- Users/models.py | 6 +++--- Users/views.py | 27 +++++++++++++++++++++++++-- tests/test_instructor.py | 2 -- tests/test_rubric.py | 3 ++- 15 files changed, 92 insertions(+), 50 deletions(-) diff --git a/CodeReview/settings.py b/CodeReview/settings.py index 19f378a..5ab05ab 100644 --- a/CodeReview/settings.py +++ b/CodeReview/settings.py @@ -20,6 +20,7 @@ DEBUG = STAGE != "Prod" # This option is used in encryption, if we're debugging, we don't care that people know what it is # But, if we're in Production, we'll load the key from the environment +# noinspection SpellCheckingInspection SECRET_KEY = 'django-insecure-1&=3d#^^j*!8)r5y8tuh(t#rp6*(jwbx%90k-ir5c*2j4$s$o%' if DEBUG else os.getenv("SECRET_KEY") # This option defines what url someone can type in to access this site. If we're debugging, it doesn't matter @@ -96,7 +97,7 @@ elif STAGE == "GH_TEST": DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'github_actions', + 'NAME': 'GitHub_actions', 'USER': 'postgres', 'PASSWORD': 'postgres', 'HOST': '127.0.0.1', @@ -104,7 +105,7 @@ elif STAGE == "GH_TEST": } } else: - # In development, we use an sqlite3 database file as the database backend + # In development, we use an SQLITE3 database file as the database backend DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', @@ -229,4 +230,5 @@ if DEBUG: # This next block of code tackles a strange issue where windows doesn't set JS mimetypes to 'text/javascript' # This causes the browser to incorrectly load the JavaScript import mimetypes + mimetypes.add_type("text/javascript", '.js') diff --git a/CodeReview/urls.py b/CodeReview/urls.py index 8c62564..c0542b2 100644 --- a/CodeReview/urls.py +++ b/CodeReview/urls.py @@ -1,5 +1,5 @@ """ - This file defines how url map to views and other apps + This file defines how urls map to views and other apps """ import debug_toolbar diff --git a/Instructor/models.py b/Instructor/models.py index 4d83dec..5462452 100644 --- a/Instructor/models.py +++ b/Instructor/models.py @@ -1,5 +1,5 @@ """ - This file defines models that will converted to tables in the database for the Instructor app + This file defines models that will be converted to tables in the database for the Instructor app """ from json import JSONEncoder @@ -29,7 +29,7 @@ class RubricCell(BaseModel): This internal class defines how the model will function in the database :cvar ordering: We order the cells by their index - :cvar unique_together: We dont want two cells at the same position on a row, + :cvar unique_together: We don't want two cells at the same position on a row, so we make `RubricCell.parent_row` and `RubricCell.index` unique together """ @@ -44,7 +44,7 @@ class RubricRow(BaseModel): :cvar name: The name of the row :cvar description: The description of the row :cvar max_score: The max score a row can have - :cvar parent_rubric: The `Rubric` that this row is inside of + :cvar parent_rubric: The `Rubric` that this row is inside :cvar index: The position of this row in the rubric """ @@ -59,7 +59,7 @@ class RubricRow(BaseModel): This internal class defines how the model will function in the database :cvar ordering: Rows should be ordered by their index - :cvar unique_together: We dont want two rows at the same position on a rubric, + :cvar unique_together: We don't want two rows at the same position on a rubric, so we make `RubricRow.parent_rubric` and `RubricRow.index` unique together """ @@ -89,7 +89,8 @@ class Rubric(BaseModel): :cvar max_score: The max possible score that a student can get with this rubric """ - name = models.CharField(max_length=20, help_text="The name the students will use to pick a rubric when requesting a review") + name = models.CharField(max_length=20, + help_text="The name the students will use to pick a rubric when requesting a review") max_score = models.FloatField() def to_json(self) -> str: @@ -112,7 +113,7 @@ class Rubric(BaseModel): def __str__(self) -> str: """ - This function defines how this object is casted to a string + This function defines how this object is cast to a string :returns: The name of the Rubric :rtype: str diff --git a/Instructor/views.py b/Instructor/views.py index 4e85203..2ecd1b8 100644 --- a/Instructor/views.py +++ b/Instructor/views.py @@ -10,14 +10,14 @@ from django.views.generic import View, ListView, TemplateView, CreateView, Updat from Main import models as main_models from Main.views import IsSuperUserMixin, FormNameMixin, FormAlertMixin, SuccessDeleteMixin -from Users.models import User from Users.ldap_auth import LDAPAuthentication, LDAPAuthException +from Users.models import User from . import models, forms class UserClearView(LoginRequiredMixin, IsSuperUserMixin, View): """ - This view is used to cleanup any users that are not in teh ActiveDirectory database. + This view is used to clean up any users that are not in teh ActiveDirectory database. :cvar http_method_names: The HTTP methods that this view takes """ @@ -83,9 +83,11 @@ class UserListView(LoginRequiredMixin, IsSuperUserMixin, TemplateView): template_name = "user_list.html" http_method_names = ['get', 'post'] - def get_queryset(self): + @staticmethod + def get_queryset(): """ - This defines what objects from the database to list, we don't want Instructors to be listed, so we exclude them + This defines what objects from the database to list. + We don't want Instructors to be listed, so we exclude them :returns: A QuerySet with non-instructor user :rtype: QuerySet @@ -172,7 +174,7 @@ class RubricEditView(LoginRequiredMixin, IsSuperUserMixin, FormNameMixin, FormAl success_url = reverse_lazy('rubric-list') template_name = 'form_base.html' success_message = "Rubric Updated" - + def form_valid(self, form): """ This function is run when the form is valid. @@ -182,11 +184,11 @@ class RubricEditView(LoginRequiredMixin, IsSuperUserMixin, FormNameMixin, FormAl :type form: Form """ - self.object = form.save() - row_count = self.object.rubricrow_set.count() - for review in main_models.Review.objects.filter(rubric=self.object, status=main_models.Review.Status.CLOSED): + edited_object = form.save() + row_count = edited_object.rubricrow_set.count() + for review in main_models.Review.objects.filter(rubric=edited_object, status=main_models.Review.Status.CLOSED): if review.scoredrow_set.count() != row_count: - for row in self.object.rubricrow_set.all(): + for row in edited_object.rubricrow_set.all(): try: review.scoredrow_set.get(source_row__index=row.index) except models.ScoredRow.DoesNotExist: diff --git a/Main/forms.py b/Main/forms.py index c574320..017c4cb 100644 --- a/Main/forms.py +++ b/Main/forms.py @@ -119,7 +119,8 @@ class GradeReviewForm(ModelForm): """ scores = CharField(max_length=200, widget=GradeReviewWidget(), - help_text="Please fill out each row in the rubric. If a row does not apply to this specific assignment, select \"N/A\"") + help_text="Please fill out each row in the rubric." + " If a row does not apply to this specific assignment, select \"N/A\"") _validation_schema = { "type": "array", @@ -192,7 +193,7 @@ class GradeReviewForm(ModelForm): def clean(self): """ This function is used to validate input data. - It ensure the JSON submitted for scores is valid and readable. + It ensures the JSON submitted for scores is valid and readable. :return: The cleaned input data :rtype: dict diff --git a/Main/models.py b/Main/models.py index 207bb02..57bf84e 100644 --- a/Main/models.py +++ b/Main/models.py @@ -1,5 +1,5 @@ """ - This file defines models that will converted to tables in the database for the Main app + This file defines models that will be converted to tables in the database for the Main app """ from typing import Optional, Union @@ -12,7 +12,7 @@ from Users.models import User def val_uuid(src: Union[str, UUID]) -> Optional[UUID]: """ - This function takes a UUID in either a string or UUID format and ensures it's valid + This function takes a UUID in either a string or UUID format and ensures its valid :param src: The UUID to validate :type src: str @@ -39,7 +39,7 @@ class BaseModel(models.Model): """ This internal class specifies settings for the model - :cvar abstract: This is a special attribute that tells django not to save this model to the database, and only use it for inheritance + :cvar abstract: This is a special attribute that tells django not to save this model to the database """ abstract = True @@ -87,10 +87,13 @@ class Review(BaseModel): student = models.ForeignKey(User, on_delete=models.CASCADE, related_name="student") reviewer = models.ForeignKey(User, on_delete=models.CASCADE, related_name="reviewer", null=True) - schoology_id = models.CharField(max_length=10, null=True, help_text="The ID of the schoology assignment that this review pertains to") + schoology_id = models.CharField(max_length=10, null=True, + help_text="The ID of the schoology assignment that this review pertains to") status = models.CharField(choices=Status.choices, default=Status.OPEN, max_length=1) - rubric = models.ForeignKey("Instructor.Rubric", on_delete=models.CASCADE, related_name="source_rubric", help_text="The rubric the reviewer will use to grade your code") - additional_comments = models.TextField(blank=True, null=True, help_text="Any additional comments you have on the code") + rubric = models.ForeignKey("Instructor.Rubric", on_delete=models.CASCADE, related_name="source_rubric", + help_text="The rubric the reviewer will use to grade your code") + additional_comments = models.TextField(blank=True, null=True, + help_text="Any additional comments you have on the code") date_created = models.DateTimeField(auto_now_add=True) date_completed = models.DateTimeField(blank=True, null=True) @@ -105,7 +108,7 @@ class Review(BaseModel): def __str__(self): """ - This function defines how the model will be casted to a string + This function defines how the model will be cast to a string :returns: The student the Review is from :rtype: str diff --git a/Main/templates/base.html b/Main/templates/base.html index df1ba8e..a7f6a12 100644 --- a/Main/templates/base.html +++ b/Main/templates/base.html @@ -16,8 +16,10 @@ {% load static %} + + @@ -78,10 +80,12 @@
{% if messages %} {% for message in messages %} -