diff --git a/accounts/admin.py b/accounts/admin.py index 8c94543..e7f44f6 100644 --- a/accounts/admin.py +++ b/accounts/admin.py @@ -1,6 +1,4 @@ from django.contrib import admin -from django.contrib.auth.models import Group - from .models import User, Student, Parent @@ -32,15 +30,6 @@ class Meta: verbose_name_plural = "Users" -# class ScoreAdmin(admin.ModelAdmin): -# list_display = [ -# 'student', 'course', 'assignment', 'mid_exam', 'quiz', -# 'attendance', 'final_exam', 'total', 'grade', 'comment' -# ] - - admin.site.register(User, UserAdmin) admin.site.register(Student) admin.site.register(Parent) - -# admin.site.unregister(Group) diff --git a/accounts/api/views.py b/accounts/api/views.py index 4bc8365..067d96b 100644 --- a/accounts/api/views.py +++ b/accounts/api/views.py @@ -9,11 +9,11 @@ class UserListAPIView(generics.ListAPIView): serializer_class = UserSerializer def get_queryset(self): - qs = get_user_model().objects.all() - q = self.request.GET.get("q") - if q is not None: - qs = qs.filter(username__iexact=q) - return qs + queryset = get_user_model().objects.all() + query = self.request.GET.get("q") + if query is not None: + queryset = queryset.filter(username__iexact=q) + return queryset class UserDetailView(generics.RetrieveAPIView): diff --git a/accounts/forms.py b/accounts/forms.py index da3b546..c54b18a 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -4,14 +4,9 @@ UserCreationForm, UserChangeForm, ) - -# from django.contrib.auth.models import User from django.contrib.auth.forms import PasswordResetForm - from course.models import Program - -# from .models import User, Student, LEVEL -from .models import * +from .models import User, Student, Parent, RELATION_SHIP, LEVEL class StaffAddForm(UserCreationForm): diff --git a/accounts/models.py b/accounts/models.py index 9fc0724..a0875ef 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -39,9 +39,9 @@ ) -class UserManager(UserManager): +class CustomUserManager(UserManager): def search(self, query=None): - qs = self.get_queryset() + queryset = self.get_queryset() if query is not None: or_lookup = ( Q(username__icontains=query) @@ -49,10 +49,10 @@ def search(self, query=None): | Q(last_name__icontains=query) | Q(email__icontains=query) ) - qs = qs.filter( + queryset = queryset.filter( or_lookup ).distinct() # distinct() is often necessary with Q lookups - return qs + return queryset class User(AbstractUser): @@ -69,7 +69,7 @@ class User(AbstractUser): username_validator = ASCIIUsernameValidator() - objects = UserManager() + objects = CustomUserManager() @property def get_full_name(self): @@ -84,13 +84,15 @@ def __str__(self): @property def get_user_role(self): if self.is_superuser: - return "Admin" + role = "Admin" elif self.is_student: - return "Student" + role = "Student" elif self.is_lecturer: - return "Lecturer" + role = "Lecturer" elif self.is_parent: - return "Parent" + role = "Parent" + + return role def get_picture(self): try: @@ -162,7 +164,8 @@ class Parent(models.Model): phone = models.CharField(max_length=60, blank=True, null=True) email = models.EmailField(blank=True, null=True) - # What is the relationship between the student and the parent (i.e. father, mother, brother, sister) + # What is the relationship between the student and + # the parent (i.e. father, mother, brother, sister) relation_ship = models.TextField(choices=RELATION_SHIP, blank=True) def __str__(self): diff --git a/accounts/urls.py b/accounts/urls.py index 20bd1cd..a387ae0 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -1,12 +1,13 @@ from django.urls import path, include -from django.contrib.auth.views import ( - PasswordResetView, - PasswordResetDoneView, - PasswordResetConfirmView, - PasswordResetCompleteView, - LoginView, - LogoutView, -) + +# from django.contrib.auth.views import ( +# PasswordResetView, +# PasswordResetDoneView, +# PasswordResetConfirmView, +# PasswordResetCompleteView, +# LoginView, +# LogoutView, +# ) from .views import ( profile, profile_single, @@ -25,7 +26,8 @@ validate_username, register, ) -from .forms import EmailValidationOnForgotPassword + +# from .forms import EmailValidationOnForgotPassword urlpatterns = [ diff --git a/accounts/views.py b/accounts/views.py index 89d29f3..ae07ef9 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -1,20 +1,16 @@ -from django.http.response import HttpResponse, JsonResponse +from django.http.response import JsonResponse from django.shortcuts import render, redirect, get_object_or_404 -from django.http import Http404 from django.contrib import messages from django.contrib.auth.decorators import login_required from django.contrib.auth import update_session_auth_hash from django.views.generic import CreateView, ListView -from django.core.paginator import Paginator from django.db.models import Q from django.utils.decorators import method_decorator from django.contrib.auth.forms import ( - UserCreationForm, - UserChangeForm, PasswordChangeForm, ) -from .decorators import lecturer_required, student_required, admin_required +from .decorators import admin_required from course.models import Course from result.models import TakenCourse from app.models import Session, Semester