Fix profile page returning 404
This commit is contained in:
parent
bb0b5f05f6
commit
4a29e29683
139
SMS/settings.py
139
SMS/settings.py
@ -24,7 +24,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|||||||
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = 'o!ld8nrt4vc*h1zoey*wj48x*q0#ss12h=+zh)kk^6b3aygg=!'
|
SECRET_KEY = "o!ld8nrt4vc*h1zoey*wj48x*q0#ss12h=+zh)kk^6b3aygg=!"
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
@ -32,65 +32,62 @@ DEBUG = True
|
|||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = []
|
||||||
|
|
||||||
# change the default user models to our custom model
|
# change the default user models to our custom model
|
||||||
AUTH_USER_MODEL = 'accounts.User'
|
AUTH_USER_MODEL = "accounts.User"
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
DJANGO_APPS = [
|
DJANGO_APPS = [
|
||||||
'django.contrib.admin',
|
"django.contrib.admin",
|
||||||
'django.contrib.auth',
|
"django.contrib.auth",
|
||||||
'django.contrib.contenttypes',
|
"django.contrib.contenttypes",
|
||||||
'django.contrib.sessions',
|
"django.contrib.sessions",
|
||||||
'django.contrib.messages',
|
"django.contrib.messages",
|
||||||
'django.contrib.staticfiles',
|
"django.contrib.staticfiles",
|
||||||
'django_cleanup',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Thired party apps
|
# Thired party apps
|
||||||
THIRED_PARTY_APPS = [
|
THIRED_PARTY_APPS = [
|
||||||
'crispy_forms',
|
"crispy_forms",
|
||||||
'rest_framework',
|
"rest_framework",
|
||||||
'channels',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Custom apps
|
# Custom apps
|
||||||
PROJECT_APPS = [
|
PROJECT_APPS = [
|
||||||
'app.apps.AppConfig',
|
"app.apps.AppConfig",
|
||||||
'accounts.apps.AccountsConfig',
|
"accounts.apps.AccountsConfig",
|
||||||
'course.apps.CourseConfig',
|
"course.apps.CourseConfig",
|
||||||
'result.apps.ResultConfig',
|
"result.apps.ResultConfig",
|
||||||
'search.apps.SearchConfig',
|
"search.apps.SearchConfig",
|
||||||
'quiz.apps.QuizConfig',
|
"quiz.apps.QuizConfig",
|
||||||
'payments.apps.PaymentsConfig',
|
"payments.apps.PaymentsConfig",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Combine all apps
|
# Combine all apps
|
||||||
INSTALLED_APPS = DJANGO_APPS + THIRED_PARTY_APPS + PROJECT_APPS
|
INSTALLED_APPS = DJANGO_APPS + THIRED_PARTY_APPS + PROJECT_APPS
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
"django.middleware.security.SecurityMiddleware",
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||||
'django.middleware.common.CommonMiddleware',
|
"django.middleware.common.CommonMiddleware",
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
"django.middleware.csrf.CsrfViewMiddleware",
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
"django.contrib.messages.middleware.MessageMiddleware",
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'SMS.urls'
|
ROOT_URLCONF = "SMS.urls"
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||||
'DIRS': [os.path.join(BASE_DIR, 'templates')],
|
"DIRS": [os.path.join(BASE_DIR, "templates")],
|
||||||
'APP_DIRS': True,
|
"APP_DIRS": True,
|
||||||
'OPTIONS': {
|
"OPTIONS": {
|
||||||
'context_processors': [
|
"context_processors": [
|
||||||
'django.template.context_processors.debug',
|
"django.template.context_processors.debug",
|
||||||
'django.template.context_processors.request',
|
"django.template.context_processors.request",
|
||||||
'django.contrib.auth.context_processors.auth',
|
"django.contrib.auth.context_processors.auth",
|
||||||
'django.contrib.messages.context_processors.messages',
|
"django.contrib.messages.context_processors.messages",
|
||||||
|
|
||||||
# 'django.template.context_processors.i18n',
|
# 'django.template.context_processors.i18n',
|
||||||
# 'django.template.context_processors.media',
|
# 'django.template.context_processors.media',
|
||||||
# 'django.template.context_processors.static',
|
# 'django.template.context_processors.static',
|
||||||
@ -100,7 +97,7 @@ TEMPLATES = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
WSGI_APPLICATION = 'SMS.wsgi.application'
|
WSGI_APPLICATION = "SMS.wsgi.application"
|
||||||
|
|
||||||
ASGI_APPLICATION = "SMS.asgi.application"
|
ASGI_APPLICATION = "SMS.asgi.application"
|
||||||
|
|
||||||
@ -119,13 +116,13 @@ ASGI_APPLICATION = "SMS.asgi.application"
|
|||||||
# NOTE: Some model fields may not work on sqlite db,
|
# NOTE: Some model fields may not work on sqlite db,
|
||||||
# so consider using postgresql instead
|
# so consider using postgresql instead
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
"default": {
|
||||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
"ENGINE": "django.db.backends.postgresql_psycopg2",
|
||||||
'NAME': env('DB_NAME'),
|
"NAME": env("DB_NAME"),
|
||||||
'USER': env('DB_USER'),
|
"USER": env("DB_USER"),
|
||||||
'PASSWORD': env('DB_PASSWORD'),
|
"PASSWORD": env("DB_PASSWORD"),
|
||||||
'HOST': env('DB_HOST'),
|
"HOST": env("DB_HOST"),
|
||||||
'PORT': env('DB_PORT'),
|
"PORT": env("DB_PORT"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,16 +134,16 @@ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -154,9 +151,9 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = "en-us"
|
||||||
|
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = "UTC"
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
@ -168,42 +165,44 @@ USE_TZ = True
|
|||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/2.2/howto/static-files/
|
# https://docs.djangoproject.com/en/2.2/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = "/static/"
|
||||||
STATICFILES_DIRS = [
|
STATICFILES_DIRS = [
|
||||||
os.path.join(BASE_DIR, "static"),
|
os.path.join(BASE_DIR, "static"),
|
||||||
]
|
]
|
||||||
STATIC_ROOT = posixpath.join(*(BASE_DIR.split(os.path.sep) + ['staticfiles']))
|
STATIC_ROOT = posixpath.join(*(BASE_DIR.split(os.path.sep) + ["staticfiles"]))
|
||||||
|
|
||||||
MEDIA_URL = '/media/'
|
MEDIA_URL = "/media/"
|
||||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
|
||||||
|
|
||||||
# -----------------------------------
|
# -----------------------------------
|
||||||
# E-mail configuration
|
# E-mail configuration
|
||||||
|
|
||||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
|
||||||
EMAIL_HOST = 'smtp.gmail.com' # Here i'm using gmail as the email host, but you can change it
|
EMAIL_HOST = (
|
||||||
|
"smtp.gmail.com" # Here i'm using gmail as the email host, but you can change it
|
||||||
|
)
|
||||||
EMAIL_PORT = 587
|
EMAIL_PORT = 587
|
||||||
EMAIL_USE_TLS = True
|
EMAIL_USE_TLS = True
|
||||||
EMAIL_HOST_USER = env('USER_EMAIL')
|
EMAIL_HOST_USER = env("USER_EMAIL")
|
||||||
EMAIL_HOST_PASSWORD = env('USER_PASSWORD')
|
EMAIL_HOST_PASSWORD = env("USER_PASSWORD")
|
||||||
|
|
||||||
# crispy config
|
# crispy config
|
||||||
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
CRISPY_TEMPLATE_PACK = "bootstrap4"
|
||||||
|
|
||||||
LOGIN_REDIRECT_URL = '/'
|
LOGIN_REDIRECT_URL = "/"
|
||||||
LOGOUT_REDIRECT_URL = '/'
|
LOGOUT_REDIRECT_URL = "/"
|
||||||
|
|
||||||
# DRF setup
|
# DRF setup
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_PERMISSION_CLASSES': [
|
"DEFAULT_PERMISSION_CLASSES": [
|
||||||
'rest_framework.permissions.IsAuthenticated',
|
"rest_framework.permissions.IsAuthenticated",
|
||||||
|
],
|
||||||
|
"DEFAULT_AUTHENTICATION_CLASSES": [
|
||||||
|
"rest_framework.authentication.SessionAuthentication",
|
||||||
|
"rest_framework.authentication.BasicAuthentication",
|
||||||
],
|
],
|
||||||
'DEFAULT_AUTHENTICATION_CLASSES': [
|
|
||||||
'rest_framework.authentication.SessionAuthentication',
|
|
||||||
'rest_framework.authentication.BasicAuthentication'
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Strip payment config
|
# Strip payment config
|
||||||
STRIPE_SECRET_KEY = env('STRIPE_SECRET_KEY')
|
STRIPE_SECRET_KEY = env("STRIPE_SECRET_KEY")
|
||||||
STRIPE_PUBLISHABLE_KEY = env('STRIPE_PUBLISHABLE_KEY')
|
STRIPE_PUBLISHABLE_KEY = env("STRIPE_PUBLISHABLE_KEY")
|
||||||
|
|||||||
@ -8,7 +8,11 @@ from django.views.generic import CreateView, ListView
|
|||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.contrib.auth.forms import UserCreationForm, UserChangeForm, PasswordChangeForm
|
from django.contrib.auth.forms import (
|
||||||
|
UserCreationForm,
|
||||||
|
UserChangeForm,
|
||||||
|
PasswordChangeForm,
|
||||||
|
)
|
||||||
|
|
||||||
from .decorators import lecturer_required, student_required, admin_required
|
from .decorators import lecturer_required, student_required, admin_required
|
||||||
from course.models import Course
|
from course.models import Course
|
||||||
@ -20,68 +24,77 @@ from .models import User, Student, Parent
|
|||||||
|
|
||||||
def validate_username(request):
|
def validate_username(request):
|
||||||
username = request.GET.get("username", None)
|
username = request.GET.get("username", None)
|
||||||
data = {
|
data = {"is_taken": User.objects.filter(username__iexact=username).exists()}
|
||||||
"is_taken": User.objects.filter(username__iexact = username).exists()
|
|
||||||
}
|
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
||||||
|
|
||||||
def register(request):
|
def register(request):
|
||||||
if request.method == 'POST':
|
if request.method == "POST":
|
||||||
form = StudentAddForm(request.POST)
|
form = StudentAddForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
messages.success(request, f'Account created successfuly.')
|
messages.success(request, f"Account created successfuly.")
|
||||||
else:
|
else:
|
||||||
messages.error(request, f'Somthing is not correct, please fill all fields correctly.')
|
messages.error(
|
||||||
|
request, f"Somthing is not correct, please fill all fields correctly."
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
form = StudentAddForm(request.POST)
|
form = StudentAddForm(request.POST)
|
||||||
return render(request, "registration/register.html", {'form': form})
|
return render(request, "registration/register.html", {"form": form})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def profile(request):
|
def profile(request):
|
||||||
"""Show profile of any user that fire out the request"""
|
"""Show profile of any user that fire out the request"""
|
||||||
try:
|
current_session = Session.objects.filter(is_current_session=True).first()
|
||||||
current_session = get_object_or_404(Session, is_current_session=True)
|
current_semester = Semester.objects.filter(
|
||||||
current_semester = get_object_or_404(Semester, is_current_semester=True, session=current_session)
|
is_current_semester=True, session=current_session
|
||||||
|
).first()
|
||||||
except Semester.MultipleObjectsReturned and Semester.DoesNotExist and Session.DoesNotExist:
|
|
||||||
raise Http404
|
|
||||||
|
|
||||||
if request.user.is_lecturer:
|
if request.user.is_lecturer:
|
||||||
courses = Course.objects.filter(allocated_course__lecturer__pk=request.user.id).filter(
|
courses = Course.objects.filter(
|
||||||
semester=current_semester)
|
allocated_course__lecturer__pk=request.user.id
|
||||||
return render(request, 'accounts/profile.html', {
|
).filter(semester=current_semester)
|
||||||
'title': request.user.get_full_name,
|
return render(
|
||||||
|
request,
|
||||||
|
"accounts/profile.html",
|
||||||
|
{
|
||||||
|
"title": request.user.get_full_name,
|
||||||
"courses": courses,
|
"courses": courses,
|
||||||
'current_session': current_session,
|
"current_session": current_session,
|
||||||
'current_semester': current_semester,
|
"current_semester": current_semester,
|
||||||
})
|
},
|
||||||
|
)
|
||||||
elif request.user.is_student:
|
elif request.user.is_student:
|
||||||
level = Student.objects.get(student__pk=request.user.id)
|
level = Student.objects.get(student__pk=request.user.id)
|
||||||
try:
|
try:
|
||||||
parent = Parent.objects.get(student=level)
|
parent = Parent.objects.get(student=level)
|
||||||
except:
|
except:
|
||||||
parent = "no parent set"
|
parent = "no parent set"
|
||||||
courses = TakenCourse.objects.filter(student__student__id=request.user.id, course__level=level.level)
|
courses = TakenCourse.objects.filter(
|
||||||
|
student__student__id=request.user.id, course__level=level.level
|
||||||
|
)
|
||||||
context = {
|
context = {
|
||||||
'title': request.user.get_full_name,
|
"title": request.user.get_full_name,
|
||||||
'parent': parent,
|
"parent": parent,
|
||||||
'courses': courses,
|
"courses": courses,
|
||||||
'level': level,
|
"level": level,
|
||||||
'current_session': current_session,
|
"current_session": current_session,
|
||||||
'current_semester': current_semester,
|
"current_semester": current_semester,
|
||||||
}
|
}
|
||||||
return render(request, 'accounts/profile.html', context)
|
return render(request, "accounts/profile.html", context)
|
||||||
else:
|
else:
|
||||||
staff = User.objects.filter(is_lecturer=True)
|
staff = User.objects.filter(is_lecturer=True)
|
||||||
return render(request, 'accounts/profile.html', {
|
return render(
|
||||||
'title': request.user.get_full_name,
|
request,
|
||||||
|
"accounts/profile.html",
|
||||||
|
{
|
||||||
|
"title": request.user.get_full_name,
|
||||||
"staff": staff,
|
"staff": staff,
|
||||||
'current_session': current_session,
|
"current_session": current_session,
|
||||||
'current_semester': current_semester,
|
"current_semester": current_semester,
|
||||||
})
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@ -91,48 +104,57 @@ def profile_single(request, id):
|
|||||||
if request.user.id == id:
|
if request.user.id == id:
|
||||||
return redirect("/profile/")
|
return redirect("/profile/")
|
||||||
|
|
||||||
current_session = get_object_or_404(Session, is_current_session=True)
|
current_session = Session.objects.filter(is_current_session=True).first()
|
||||||
current_semester = get_object_or_404(Semester, is_current_semester=True, session=current_session)
|
current_semester = Semester.objects.filter(
|
||||||
|
is_current_semester=True, session=current_session
|
||||||
|
).first()
|
||||||
|
|
||||||
user = User.objects.get(pk=id)
|
user = User.objects.get(pk=id)
|
||||||
if user.is_lecturer:
|
if user.is_lecturer:
|
||||||
courses = Course.objects.filter(allocated_course__lecturer__pk=id).filter(semester=current_semester)
|
courses = Course.objects.filter(allocated_course__lecturer__pk=id).filter(
|
||||||
|
semester=current_semester
|
||||||
|
)
|
||||||
context = {
|
context = {
|
||||||
'title': user.get_full_name,
|
"title": user.get_full_name,
|
||||||
"user": user,
|
"user": user,
|
||||||
"user_type": "Lecturer",
|
"user_type": "Lecturer",
|
||||||
"courses": courses,
|
"courses": courses,
|
||||||
'current_session': current_session,
|
"current_session": current_session,
|
||||||
'current_semester': current_semester,
|
"current_semester": current_semester,
|
||||||
}
|
}
|
||||||
return render(request, 'accounts/profile_single.html', context)
|
return render(request, "accounts/profile_single.html", context)
|
||||||
elif user.is_student:
|
elif user.is_student:
|
||||||
student = Student.objects.get(student__pk=id)
|
student = Student.objects.get(student__pk=id)
|
||||||
courses = TakenCourse.objects.filter(student__student__id=id, course__level=student.level)
|
courses = TakenCourse.objects.filter(
|
||||||
|
student__student__id=id, course__level=student.level
|
||||||
|
)
|
||||||
context = {
|
context = {
|
||||||
'title': user.get_full_name,
|
"title": user.get_full_name,
|
||||||
'user': user,
|
"user": user,
|
||||||
"user_type": "student",
|
"user_type": "student",
|
||||||
'courses': courses,
|
"courses": courses,
|
||||||
'student': student,
|
"student": student,
|
||||||
'current_session': current_session,
|
"current_session": current_session,
|
||||||
'current_semester': current_semester,
|
"current_semester": current_semester,
|
||||||
}
|
}
|
||||||
return render(request, 'accounts/profile_single.html', context)
|
return render(request, "accounts/profile_single.html", context)
|
||||||
else:
|
else:
|
||||||
context = {
|
context = {
|
||||||
'title': user.get_full_name,
|
"title": user.get_full_name,
|
||||||
"user": user,
|
"user": user,
|
||||||
"user_type": "superuser",
|
"user_type": "superuser",
|
||||||
'current_session': current_session,
|
"current_session": current_session,
|
||||||
'current_semester': current_semester,
|
"current_semester": current_semester,
|
||||||
}
|
}
|
||||||
return render(request, 'accounts/profile_single.html', context)
|
return render(request, "accounts/profile_single.html", context)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@admin_required
|
@admin_required
|
||||||
def admin_panel(request):
|
def admin_panel(request):
|
||||||
return render(request, 'setting/admin_panel.html', {})
|
return render(request, "setting/admin_panel.html", {})
|
||||||
|
|
||||||
|
|
||||||
# ########################################################
|
# ########################################################
|
||||||
|
|
||||||
|
|
||||||
@ -141,85 +163,107 @@ def admin_panel(request):
|
|||||||
# ########################################################
|
# ########################################################
|
||||||
@login_required
|
@login_required
|
||||||
def profile_update(request):
|
def profile_update(request):
|
||||||
if request.method == 'POST':
|
if request.method == "POST":
|
||||||
form = ProfileUpdateForm(request.POST, request.FILES, instance=request.user)
|
form = ProfileUpdateForm(request.POST, request.FILES, instance=request.user)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
messages.success(request, 'Your profile has been updated successfully.')
|
messages.success(request, "Your profile has been updated successfully.")
|
||||||
return redirect('profile')
|
return redirect("profile")
|
||||||
else:
|
else:
|
||||||
messages.error(request, 'Please correct the error(s) below.')
|
messages.error(request, "Please correct the error(s) below.")
|
||||||
else:
|
else:
|
||||||
form = ProfileUpdateForm(instance=request.user)
|
form = ProfileUpdateForm(instance=request.user)
|
||||||
return render(request, 'setting/profile_info_change.html', {
|
return render(
|
||||||
'title': 'Setting | DjangoSMS',
|
request,
|
||||||
'form': form,
|
"setting/profile_info_change.html",
|
||||||
})
|
{
|
||||||
|
"title": "Setting | DjangoSMS",
|
||||||
|
"form": form,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def change_password(request):
|
def change_password(request):
|
||||||
if request.method == 'POST':
|
if request.method == "POST":
|
||||||
form = PasswordChangeForm(request.user, request.POST)
|
form = PasswordChangeForm(request.user, request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
user = form.save()
|
user = form.save()
|
||||||
update_session_auth_hash(request, user)
|
update_session_auth_hash(request, user)
|
||||||
messages.success(request, 'Your password was successfully updated!')
|
messages.success(request, "Your password was successfully updated!")
|
||||||
return redirect('profile')
|
return redirect("profile")
|
||||||
else:
|
else:
|
||||||
messages.error(request, 'Please correct the error(s) below. ')
|
messages.error(request, "Please correct the error(s) below. ")
|
||||||
else:
|
else:
|
||||||
form = PasswordChangeForm(request.user)
|
form = PasswordChangeForm(request.user)
|
||||||
return render(request, 'setting/password_change.html', {
|
return render(
|
||||||
'form': form,
|
request,
|
||||||
})
|
"setting/password_change.html",
|
||||||
|
{
|
||||||
|
"form": form,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# ########################################################
|
# ########################################################
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@admin_required
|
@admin_required
|
||||||
def staff_add_view(request):
|
def staff_add_view(request):
|
||||||
if request.method == 'POST':
|
if request.method == "POST":
|
||||||
form = StaffAddForm(request.POST)
|
form = StaffAddForm(request.POST)
|
||||||
first_name = request.POST.get('first_name')
|
first_name = request.POST.get("first_name")
|
||||||
last_name = request.POST.get('last_name')
|
last_name = request.POST.get("last_name")
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
messages.success(request, "Account for lecturer " + first_name + ' ' + last_name + " has been created.")
|
messages.success(
|
||||||
|
request,
|
||||||
|
"Account for lecturer "
|
||||||
|
+ first_name
|
||||||
|
+ " "
|
||||||
|
+ last_name
|
||||||
|
+ " has been created.",
|
||||||
|
)
|
||||||
return redirect("lecturer_list")
|
return redirect("lecturer_list")
|
||||||
else:
|
else:
|
||||||
form = StaffAddForm()
|
form = StaffAddForm()
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'title': 'Lecturer Add | DjangoSMS',
|
"title": "Lecturer Add | DjangoSMS",
|
||||||
'form': form,
|
"form": form,
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, 'accounts/add_staff.html', context)
|
return render(request, "accounts/add_staff.html", context)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@admin_required
|
@admin_required
|
||||||
def edit_staff(request, pk):
|
def edit_staff(request, pk):
|
||||||
instance = get_object_or_404(User, is_lecturer=True, pk=pk)
|
instance = get_object_or_404(User, is_lecturer=True, pk=pk)
|
||||||
if request.method == 'POST':
|
if request.method == "POST":
|
||||||
form = ProfileUpdateForm(request.POST, request.FILES, instance=instance)
|
form = ProfileUpdateForm(request.POST, request.FILES, instance=instance)
|
||||||
full_name = instance.get_full_name
|
full_name = instance.get_full_name
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
|
|
||||||
messages.success(request, 'Lecturer ' + full_name + ' has been updated.')
|
messages.success(request, "Lecturer " + full_name + " has been updated.")
|
||||||
return redirect('lecturer_list')
|
return redirect("lecturer_list")
|
||||||
else:
|
else:
|
||||||
messages.error(request, 'Please correct the error below.')
|
messages.error(request, "Please correct the error below.")
|
||||||
else:
|
else:
|
||||||
form = ProfileUpdateForm(instance=instance)
|
form = ProfileUpdateForm(instance=instance)
|
||||||
return render(request, 'accounts/edit_lecturer.html', {
|
return render(
|
||||||
'title': 'Edit Lecturer | DjangoSMS',
|
request,
|
||||||
'form': form,
|
"accounts/edit_lecturer.html",
|
||||||
})
|
{
|
||||||
|
"title": "Edit Lecturer | DjangoSMS",
|
||||||
|
"form": form,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@method_decorator([login_required, admin_required], name='dispatch')
|
@method_decorator([login_required, admin_required], name="dispatch")
|
||||||
class LecturerListView(ListView):
|
class LecturerListView(ListView):
|
||||||
queryset = User.objects.filter(is_lecturer=True)
|
queryset = User.objects.filter(is_lecturer=True)
|
||||||
template_name = "accounts/lecturer_list.html"
|
template_name = "accounts/lecturer_list.html"
|
||||||
@ -227,7 +271,7 @@ class LecturerListView(ListView):
|
|||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['title'] = "Lecturers | DjangoSMS"
|
context["title"] = "Lecturers | DjangoSMS"
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
@ -238,14 +282,17 @@ class LecturerListView(ListView):
|
|||||||
# staff.delete()
|
# staff.delete()
|
||||||
# return redirect('lecturer_list')
|
# return redirect('lecturer_list')
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@admin_required
|
@admin_required
|
||||||
def delete_staff(request, pk):
|
def delete_staff(request, pk):
|
||||||
lecturer = get_object_or_404(User, pk=pk)
|
lecturer = get_object_or_404(User, pk=pk)
|
||||||
full_name = lecturer.get_full_name
|
full_name = lecturer.get_full_name
|
||||||
lecturer.delete()
|
lecturer.delete()
|
||||||
messages.success(request, 'Lecturer ' + full_name + ' has been deleted.')
|
messages.success(request, "Lecturer " + full_name + " has been deleted.")
|
||||||
return redirect('lecturer_list')
|
return redirect("lecturer_list")
|
||||||
|
|
||||||
|
|
||||||
# ########################################################
|
# ########################################################
|
||||||
|
|
||||||
|
|
||||||
@ -255,23 +302,27 @@ def delete_staff(request, pk):
|
|||||||
@login_required
|
@login_required
|
||||||
@admin_required
|
@admin_required
|
||||||
def student_add_view(request):
|
def student_add_view(request):
|
||||||
if request.method == 'POST':
|
if request.method == "POST":
|
||||||
form = StudentAddForm(request.POST)
|
form = StudentAddForm(request.POST)
|
||||||
first_name = request.POST.get('first_name')
|
first_name = request.POST.get("first_name")
|
||||||
last_name = request.POST.get('last_name')
|
last_name = request.POST.get("last_name")
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
messages.success(request, 'Account for ' + first_name + ' ' + last_name + ' has been created.')
|
messages.success(
|
||||||
return redirect('student_list')
|
request,
|
||||||
|
"Account for " + first_name + " " + last_name + " has been created.",
|
||||||
|
)
|
||||||
|
return redirect("student_list")
|
||||||
else:
|
else:
|
||||||
messages.error(request, 'Correct the error(s) below.')
|
messages.error(request, "Correct the error(s) below.")
|
||||||
else:
|
else:
|
||||||
form = StudentAddForm()
|
form = StudentAddForm()
|
||||||
|
|
||||||
return render(request, 'accounts/add_student.html', {
|
return render(
|
||||||
'title': "Add Student | DjangoSMS",
|
request,
|
||||||
'form': form
|
"accounts/add_student.html",
|
||||||
})
|
{"title": "Add Student | DjangoSMS", "form": form},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@ -279,39 +330,43 @@ def student_add_view(request):
|
|||||||
def edit_student(request, pk):
|
def edit_student(request, pk):
|
||||||
# instance = User.objects.get(pk=pk)
|
# instance = User.objects.get(pk=pk)
|
||||||
instance = get_object_or_404(User, is_student=True, pk=pk)
|
instance = get_object_or_404(User, is_student=True, pk=pk)
|
||||||
if request.method == 'POST':
|
if request.method == "POST":
|
||||||
form = ProfileUpdateForm(request.POST, request.FILES, instance=instance)
|
form = ProfileUpdateForm(request.POST, request.FILES, instance=instance)
|
||||||
full_name = instance.get_full_name
|
full_name = instance.get_full_name
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
|
|
||||||
messages.success(request, ('Student ' + full_name + ' has been updated.'))
|
messages.success(request, ("Student " + full_name + " has been updated."))
|
||||||
return redirect('student_list')
|
return redirect("student_list")
|
||||||
else:
|
else:
|
||||||
messages.error(request, 'Please correct the error below.')
|
messages.error(request, "Please correct the error below.")
|
||||||
else:
|
else:
|
||||||
form = ProfileUpdateForm(instance=instance)
|
form = ProfileUpdateForm(instance=instance)
|
||||||
return render(request, 'accounts/edit_student.html', {
|
return render(
|
||||||
'title': 'Edit-profile | DjangoSMS',
|
request,
|
||||||
'form': form,
|
"accounts/edit_student.html",
|
||||||
})
|
{
|
||||||
|
"title": "Edit-profile | DjangoSMS",
|
||||||
|
"form": form,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@method_decorator([login_required, admin_required], name='dispatch')
|
@method_decorator([login_required, admin_required], name="dispatch")
|
||||||
class StudentListView(ListView):
|
class StudentListView(ListView):
|
||||||
template_name = "accounts/student_list.html"
|
template_name = "accounts/student_list.html"
|
||||||
paginate_by = 10 # if pagination is desired
|
paginate_by = 10 # if pagination is desired
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
queryset = Student.objects.all()
|
queryset = Student.objects.all()
|
||||||
query = self.request.GET.get('student_id')
|
query = self.request.GET.get("student_id")
|
||||||
if query is not None:
|
if query is not None:
|
||||||
queryset = queryset.filter(Q(department=query))
|
queryset = queryset.filter(Q(department=query))
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['title'] = "Students | DjangoSMS"
|
context["title"] = "Students | DjangoSMS"
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
@ -321,15 +376,17 @@ def delete_student(request, pk):
|
|||||||
student = get_object_or_404(Student, pk=pk)
|
student = get_object_or_404(Student, pk=pk)
|
||||||
# full_name = student.user.get_full_name
|
# full_name = student.user.get_full_name
|
||||||
student.delete()
|
student.delete()
|
||||||
messages.success(request, 'Student has been deleted.')
|
messages.success(request, "Student has been deleted.")
|
||||||
return redirect('student_list')
|
return redirect("student_list")
|
||||||
|
|
||||||
|
|
||||||
# ########################################################
|
# ########################################################
|
||||||
|
|
||||||
|
|
||||||
class ParentAdd(CreateView):
|
class ParentAdd(CreateView):
|
||||||
model = Parent
|
model = Parent
|
||||||
form_class = ParentAddForm
|
form_class = ParentAddForm
|
||||||
template_name = 'accounts/parent_form.html'
|
template_name = "accounts/parent_form.html"
|
||||||
|
|
||||||
|
|
||||||
# def parent_add(request):
|
# def parent_add(request):
|
||||||
|
|||||||
@ -21,3 +21,7 @@ djangorestframework==3.14.0 # https://github.com/encode/django-rest-framework
|
|||||||
django-cors-headers==3.13.0 # https://github.com/adamchainz/django-cors-headers
|
django-cors-headers==3.13.0 # https://github.com/adamchainz/django-cors-headers
|
||||||
# DRF-spectacular for api documentation
|
# DRF-spectacular for api documentation
|
||||||
drf-spectacular==0.25.1 # https://github.com/tfranzel/drf-spectacular
|
drf-spectacular==0.25.1 # https://github.com/tfranzel/drf-spectacular
|
||||||
|
|
||||||
|
reportlab==4.0.4
|
||||||
|
stripe==5.5.0
|
||||||
|
gopay==2.0.1
|
||||||
|
|||||||
@ -102,7 +102,9 @@
|
|||||||
<p class="title-info"><i class="fa fa-calendar-day"></i> Important Dates</p>
|
<p class="title-info"><i class="fa fa-calendar-day"></i> Important Dates</p>
|
||||||
<div class="dashboard-description">
|
<div class="dashboard-description">
|
||||||
<p><strong>Last login:</strong> {{ user.last_login }}</p>
|
<p><strong>Last login:</strong> {{ user.last_login }}</p>
|
||||||
|
{% if current_semester and current_session %}
|
||||||
<p><strong>Academic Year:</strong> {{ current_semester }} Semester {{ current_session }}</p>
|
<p><strong>Academic Year:</strong> {{ current_semester }} Semester {{ current_session }}</p>
|
||||||
|
{% endif %}
|
||||||
<p><strong>Registered Date:</strong> {{ user.date_joined|date }}</p>
|
<p><strong>Registered Date:</strong> {{ user.date_joined|date }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -95,7 +95,9 @@
|
|||||||
<p class="title-info"><i class="fa fa-calendar-day"></i>Important Dates</p>
|
<p class="title-info"><i class="fa fa-calendar-day"></i>Important Dates</p>
|
||||||
<div class="dashboard-description">
|
<div class="dashboard-description">
|
||||||
<p><strong>Last login:</strong> {{ user.last_login }}</p>
|
<p><strong>Last login:</strong> {{ user.last_login }}</p>
|
||||||
|
{% if current_semester and current_session %}
|
||||||
<p><strong>Academic Year:</strong> {{ current_semester }} Semester {{ current_session }}</p>
|
<p><strong>Academic Year:</strong> {{ current_semester }} Semester {{ current_session }}</p>
|
||||||
|
{% endif %}
|
||||||
<p><strong>Registered Date:</strong> {{ user.date_joined|date }}</p>
|
<p><strong>Registered Date:</strong> {{ user.date_joined|date }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user