From d09e7fe84e5b3f1ddbde909e7c9478c249592fa3 Mon Sep 17 00:00:00 2001 From: bwc9876 Date: Tue, 26 Oct 2021 14:08:37 -0400 Subject: [PATCH] Added docstrings for Users --- Users/admin.py | 5 ++++ Users/apps.py | 4 +++ Users/models.py | 37 ++++++++++++++++++++++++++-- Users/templates/login.html | 5 ++++ Users/templates/logout_complete.html | 3 +++ Users/urls.py | 9 +++++-- Users/views.py | 15 ++++++++--- 7 files changed, 70 insertions(+), 8 deletions(-) diff --git a/Users/admin.py b/Users/admin.py index 7bc23f0..bbf35ff 100644 --- a/Users/admin.py +++ b/Users/admin.py @@ -1,7 +1,12 @@ +""" + This file defines how our models interact with Django's admin interface +""" + from django.conf import settings from django.contrib import admin from . import models +# We'll be using our own system for Users in production, so we only run this in debug if settings.DEBUG: admin.site.register(models.User) diff --git a/Users/apps.py b/Users/apps.py index d430cc0..0774f95 100644 --- a/Users/apps.py +++ b/Users/apps.py @@ -1,3 +1,7 @@ +""" + This file provides configuration data to Django about this app +""" + from django.apps import AppConfig diff --git a/Users/models.py b/Users/models.py index b0bf0b2..68d3f37 100644 --- a/Users/models.py +++ b/Users/models.py @@ -1,3 +1,7 @@ +""" + This file defines models that will converted to tables in the database for the Users app +""" + from uuid import uuid4 from django.contrib.auth.models import AbstractUser @@ -5,7 +9,19 @@ from django.db import models class User(AbstractUser): + """ + This model represents a User in the database + + :cvar id: A Unique Identifier for the user + :cvar session: The session the student is in (AM or PM) + :cvar is_reviewer: Whether the student can review code + """ + class Session(models.TextChoices): + """ + This internal class is used to store the types of sessions there are + """ + AM = 'AM', "AM Session" PM = 'PM', "PM Session" @@ -14,10 +30,27 @@ class User(AbstractUser): is_reviewer = models.BooleanField(default=False) @staticmethod - def session_from_str(session_code): + def session_from_str(session_code: str) -> str: + """ + This function takes a session code (AM or PM) and returns the label for it ("AM Session" or "PM Session") + + :param session_code: The key for the session in the Session enum + :type session_code: str + :returns: The label for the session + :rtype: str + """ + return User.Session.labels[User.Session.values.index(session_code)] - def __str__(self): + def __str__(self) -> str: + """ + This function define how this object will be casted to string. + If the user has a first and last name, we use those, otherwise, we just use the username + + :returns: A string representation of this object + :rtype: str + """ + if self.first_name == "" or self.last_name == "": return self.username else: diff --git a/Users/templates/login.html b/Users/templates/login.html index 4f47f47..6c82ed7 100644 --- a/Users/templates/login.html +++ b/Users/templates/login.html @@ -1,5 +1,10 @@ {% extends "form_base.html" %} +{% comment %} + This page allows the user to login. + It overrides some blocks to make the login screen look more like a login screen than a form +{% endcomment %} + {% block nav %}{% endblock %} {% block pageHeader %}Login{% endblock %} diff --git a/Users/templates/logout_complete.html b/Users/templates/logout_complete.html index beb748a..c8093ac 100644 --- a/Users/templates/logout_complete.html +++ b/Users/templates/logout_complete.html @@ -1,5 +1,8 @@ {% extends "base.html" %} +{% comment %} + This page is displayed when the user has logged out +{% endcomment %} {% block nav %}{% endblock %} diff --git a/Users/urls.py b/Users/urls.py index 3948287..0381a8d 100644 --- a/Users/urls.py +++ b/Users/urls.py @@ -1,10 +1,15 @@ +""" + This file defines how a URL will map to a view in the Users app +""" + from django.contrib.auth import views as auth_views from django.urls import path from . import views urlpatterns = [ - path('login', auth_views.LoginView.as_view(template_name="login.html", extra_context={'hide_back': True}), name="login"), + path('login', auth_views.LoginView.as_view(template_name="login.html", extra_context={'hide_back': True}), + name="login"), path('logout', auth_views.LogoutView.as_view(), name="logout"), - path('logout-done', views.logout_done, name="logout-done") + path('logout-done', views.LogoutDoneView.as_view(), name="logout-done") ] diff --git a/Users/views.py b/Users/views.py index 5607a7e..0913315 100644 --- a/Users/views.py +++ b/Users/views.py @@ -1,6 +1,13 @@ -from django.http import HttpResponse -from django.shortcuts import render +""" + This file defines the backend code that runs when the user goes to a page +""" +from django.views.generic import TemplateView -def logout_done(request) -> HttpResponse: - return render(request, "logout_complete.html") + +class LogoutDoneView(TemplateView): + """ + This view is shown when the user has been logged out + """ + + template_name = "logout_complete.html" -- knotmirror 0.0.1