added changing student's program functionality
This commit is contained in:
parent
e58a20d212
commit
7996248f79
@ -337,6 +337,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):
|
||||
def clean_email(self):
|
||||
email = self.cleaned_data["email"]
|
||||
|
||||
@ -22,6 +22,7 @@ from .views import (
|
||||
student_add_view,
|
||||
edit_student,
|
||||
delete_student,
|
||||
edit_program,
|
||||
ParentAdd,
|
||||
validate_username,
|
||||
register,
|
||||
@ -47,6 +48,7 @@ urlpatterns = [
|
||||
path("student/add/", student_add_view, name="add_student"),
|
||||
path("student/<int:pk>/edit/", edit_student, name="student_edit"),
|
||||
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("ajax/validate-username/", validate_username, name="validate_username"),
|
||||
path("register/", register, name="register"),
|
||||
|
||||
@ -12,7 +12,7 @@ from core.models import Session, Semester
|
||||
from course.models import Course
|
||||
from result.models import TakenCourse
|
||||
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 .filters import LecturerFilter, StudentFilter
|
||||
|
||||
@ -477,6 +477,33 @@ def delete_student(request, pk):
|
||||
messages.success(request, "Student has been deleted.")
|
||||
return redirect("student_list")
|
||||
|
||||
@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
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
# ########################################################
|
||||
|
||||
|
||||
34
templates/accounts/edit_program.html
Normal file
34
templates/accounts/edit_program.html
Normal 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 %}
|
||||
@ -38,6 +38,11 @@
|
||||
<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>
|
||||
</a>
|
||||
<div class="p-2"></div>
|
||||
{# 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 %}
|
||||
{% if user.is_lecturer %}
|
||||
<a class="edit-btn" href="{% url 'staff_edit' pk=user.id %}">
|
||||
@ -93,6 +98,7 @@
|
||||
<div class="dashboard-description">
|
||||
<p><strong>School: </strong>Hawas Preparatory School</p>
|
||||
<p><strong>Level: </strong>{{ level.level }}</p>
|
||||
<p><strong>Program: </strong>{{ student.program }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user