Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
More pylint conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
adilmohak committed Dec 26, 2023
1 parent 43290a9 commit ef88e20
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 47 deletions.
11 changes: 0 additions & 11 deletions accounts/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from django.contrib import admin
from django.contrib.auth.models import Group

from .models import User, Student, Parent


Expand Down Expand Up @@ -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)
10 changes: 5 additions & 5 deletions accounts/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 1 addition & 6 deletions accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
23 changes: 13 additions & 10 deletions accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@
)


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)
| Q(first_name__icontains=query)
| 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):
Expand All @@ -69,7 +69,7 @@ class User(AbstractUser):

username_validator = ASCIIUsernameValidator()

objects = UserManager()
objects = CustomUserManager()

@property
def get_full_name(self):
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
20 changes: 11 additions & 9 deletions accounts/urls.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -25,7 +26,8 @@
validate_username,
register,
)
from .forms import EmailValidationOnForgotPassword

# from .forms import EmailValidationOnForgotPassword


urlpatterns = [
Expand Down
8 changes: 2 additions & 6 deletions accounts/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ef88e20

Please sign in to comment.