Merge branch 'edit-program' of github.com:mnymkr/django-lms into mnymkr-edit-program

This commit is contained in:
Adil Mohak 2024-07-30 16:20:23 +03:00
commit 9d5ef21f5c
9 changed files with 109 additions and 3 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -324,6 +324,14 @@ class ProfileUpdateForm(UserChangeForm):
label="Address / city", label="Address / city",
) )
program = forms.ModelChoiceField(
queryset=Program.objects.all(),
widget=forms.Select(
attrs={"class": "browser-default custom-select form-control"}
),
label="Program",
)
class Meta: class Meta:
model = User model = User
fields = [ fields = [
@ -337,6 +345,21 @@ class ProfileUpdateForm(UserChangeForm):
] ]
class ProgramUpdateForm(UserChangeForm):
program = forms.ModelChoiceField(
queryset=Program.objects.all(),
widget=forms.Select(
attrs={"class": "browser-default custom-select form-control"}
),
label="Program",
)
class Meta:
model = Student
fields = [
"program"
]
class EmailValidationOnForgotPassword(PasswordResetForm): class EmailValidationOnForgotPassword(PasswordResetForm):
def clean_email(self): def clean_email(self):
email = self.cleaned_data["email"] email = self.cleaned_data["email"]

View File

@ -22,6 +22,7 @@ from .views import (
student_add_view, student_add_view,
edit_student, edit_student,
delete_student, delete_student,
edit_program,
ParentAdd, ParentAdd,
validate_username, validate_username,
register, register,
@ -47,6 +48,7 @@ urlpatterns = [
path("student/add/", student_add_view, name="add_student"), path("student/add/", student_add_view, name="add_student"),
path("student/<int:pk>/edit/", edit_student, name="student_edit"), path("student/<int:pk>/edit/", edit_student, name="student_edit"),
path("students/<int:pk>/delete/", delete_student, name="student_delete"), path("students/<int:pk>/delete/", delete_student, name="student_delete"),
path("edit_program/<int:pk>/", edit_program, name="student_program_edit"),
path("parents/add/", ParentAdd.as_view(), name="add_parent"), path("parents/add/", ParentAdd.as_view(), name="add_parent"),
path("ajax/validate-username/", validate_username, name="validate_username"), path("ajax/validate-username/", validate_username, name="validate_username"),
path("register/", register, name="register"), path("register/", register, name="register"),

View File

@ -12,7 +12,7 @@ from core.models import Session, Semester
from course.models import Course from course.models import Course
from result.models import TakenCourse from result.models import TakenCourse
from .decorators import admin_required from .decorators import admin_required
from .forms import StaffAddForm, StudentAddForm, ProfileUpdateForm, ParentAddForm from .forms import StaffAddForm, StudentAddForm, ProfileUpdateForm, ParentAddForm, ProgramUpdateForm
from .models import User, Student, Parent from .models import User, Student, Parent
from .filters import LecturerFilter, StudentFilter from .filters import LecturerFilter, StudentFilter
@ -420,6 +420,10 @@ def edit_student(request, pk):
if form.is_valid(): if form.is_valid():
form.save() form.save()
student = Student.objects.get(student_id=instance.id)
student.program = form.cleaned_data["program"]
student.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:
@ -477,6 +481,34 @@ def delete_student(request, pk):
messages.success(request, "Student has been deleted.") messages.success(request, "Student has been deleted.")
return redirect("student_list") return redirect("student_list")
# REDUNDANT
@login_required
@admin_required
def edit_program(request, pk):
instance = get_object_or_404(Student, student_id=pk)
user = get_object_or_404(User, pk=pk)
if request.method == "POST":
form = ProgramUpdateForm(request.POST, request.FILES, instance=instance)
full_name = user.get_full_name
if form.is_valid():
form.save()
messages.success(request, message=full_name + " has been updated.")
url = "/accounts/profile/" + user.id.__str__() + "/detail/" # Botched job, must optimize
return redirect(to=url)
else:
messages.error(request, "Please correct the error(s) below.")
else:
form = ProgramUpdateForm(instance=instance)
return render(
request,
"accounts/edit_program.html",
context={
"title": "Edit-program",
"form": form
},
)
# ######################################################## # ########################################################

View File

@ -199,6 +199,7 @@ EMAIL_USE_TLS = config("EMAIL_USE_TLS", default=True, cast=bool)
EMAIL_HOST_USER = config("EMAIL_HOST_USER") EMAIL_HOST_USER = config("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = config("EMAIL_HOST_PASSWORD") EMAIL_HOST_PASSWORD = config("EMAIL_HOST_PASSWORD")
EMAIL_FROM_ADDRESS = config("EMAIL_FROM_ADDRESS") EMAIL_FROM_ADDRESS = config("EMAIL_FROM_ADDRESS")
EMAIL_USE_SSL = False
# crispy config # crispy config
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"

View File

@ -0,0 +1,34 @@
{% extends 'base.html' %}
{% block title %}{{ title }} | Learning management system{% endblock title %}
{% load crispy_forms_tags %}
{% load static %}
{% block content %}
<nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">Home</a></li>
<li class="breadcrumb-item"><a href="{% url 'student_list' %}">Students</a></li>
<li class="breadcrumb-item active" aria-current="page">Update</li>
</ol>
</nav>
<h4 class="fw-bold mb-3"><i class="fas fa-cog me-2"></i>Student Program Update Form</h4>
{% include 'snippets/messages.html' %}
<form action="" method="POST" enctype="multipart/form-data">{% csrf_token %}
<div class="row mb-3">
<div class="col-md-6">
<div class="card">
<p class="form-title">Program</p>
<div class="card-body">
{{ form.program|as_crispy_field }}
</div>
</div>
</div>
</div>
<input class="btn btn-primary" type="submit" value="Save">
</form>
{% endblock content %}

View File

@ -30,6 +30,7 @@
{{ form.gender|as_crispy_field }} {{ form.gender|as_crispy_field }}
{{ form.phone|as_crispy_field }} {{ form.phone|as_crispy_field }}
{{ form.address|as_crispy_field }} {{ form.address|as_crispy_field }}
{{ form.program|as_crispy_field }}
</div> </div>
</div> </div>
</div> </div>

View File

@ -268,8 +268,8 @@
</p> </p>
<h5>Login credentials for your DJ LMS account:</h5> <h5>Login credentials for your DJ LMS account:</h5>
<ul> <ul>
<li>ID: {user.username}</li> <li>ID: {{ user.username }}</li>
<li>Your password: {password}</li> <li>Your password: {{ password }}</li>
</ul> </ul>
<p>To secure your account be sure to change your password.</p> <p>To secure your account be sure to change your password.</p>
<p> <p>

View File

@ -38,6 +38,10 @@
<a class="edit-btn" href="{% url 'student_edit' pk=user.id %}"> <a class="edit-btn" href="{% url 'student_edit' pk=user.id %}">
<i class="fas fa-user-edit"></i><span class="mobile-hide">Edit Profile</span> <i class="fas fa-user-edit"></i><span class="mobile-hide">Edit Profile</span>
</a> </a>
{# had to name out of convention because it clashes with 'edit_[whatever]program', which directs to 'program/[id]/edit/ #}
{# <a class="edit-btn" href="{% url 'student_program_edit' user.id %}">#}
{# <i class="fas fa-user-edit"></i><span class="mobile-hide">Change Program</span>#}
{# </a>#}
{% endif %} {% endif %}
{% if user.is_lecturer %} {% if user.is_lecturer %}
<a class="edit-btn" href="{% url 'staff_edit' pk=user.id %}"> <a class="edit-btn" href="{% url 'staff_edit' pk=user.id %}">
@ -93,6 +97,7 @@
<div class="dashboard-description"> <div class="dashboard-description">
<p><strong>School: </strong>Hawas Preparatory School</p> <p><strong>School: </strong>Hawas Preparatory School</p>
<p><strong>Level: </strong>{{ level.level }}</p> <p><strong>Level: </strong>{{ level.level }}</p>
<p><strong>Program: </strong>{{ student.program }}</p>
</div> </div>
{% endif %} {% endif %}