diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -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 diff --git a/accounts/forms.py b/accounts/forms.py index d006ee4..a6ed970 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -324,6 +324,14 @@ class ProfileUpdateForm(UserChangeForm): 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: model = User 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): def clean_email(self): email = self.cleaned_data["email"] diff --git a/accounts/urls.py b/accounts/urls.py index fd0737d..16dbe5a 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -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//edit/", edit_student, name="student_edit"), path("students//delete/", delete_student, name="student_delete"), + path("edit_program//", 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"), diff --git a/accounts/views.py b/accounts/views.py index 47fbead..2da75c6 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -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 @@ -420,6 +420,10 @@ def edit_student(request, pk): if form.is_valid(): 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.")) return redirect("student_list") else: @@ -477,6 +481,34 @@ def delete_student(request, pk): messages.success(request, "Student has been deleted.") 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 + }, + ) + # ######################################################## diff --git a/config/settings.py b/config/settings.py index 9a7a82f..fe2c2d0 100644 --- a/config/settings.py +++ b/config/settings.py @@ -199,6 +199,7 @@ EMAIL_USE_TLS = config("EMAIL_USE_TLS", default=True, cast=bool) EMAIL_HOST_USER = config("EMAIL_HOST_USER") EMAIL_HOST_PASSWORD = config("EMAIL_HOST_PASSWORD") EMAIL_FROM_ADDRESS = config("EMAIL_FROM_ADDRESS") +EMAIL_USE_SSL = False # crispy config CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" diff --git a/templates/accounts/edit_program.html b/templates/accounts/edit_program.html new file mode 100644 index 0000000..e45d193 --- /dev/null +++ b/templates/accounts/edit_program.html @@ -0,0 +1,34 @@ +{% extends 'base.html' %} +{% block title %}{{ title }} | Learning management system{% endblock title %} +{% load crispy_forms_tags %} +{% load static %} + +{% block content %} + + + +

Student Program Update Form

+ +{% include 'snippets/messages.html' %} + +
{% csrf_token %} +
+
+
+

Program

+ +
+ {{ form.program|as_crispy_field }} +
+
+
+
+ +
+{% endblock content %} diff --git a/templates/accounts/edit_student.html b/templates/accounts/edit_student.html index 8a56495..25b7169 100644 --- a/templates/accounts/edit_student.html +++ b/templates/accounts/edit_student.html @@ -30,6 +30,7 @@ {{ form.gender|as_crispy_field }} {{ form.phone|as_crispy_field }} {{ form.address|as_crispy_field }} + {{ form.program|as_crispy_field }} diff --git a/templates/accounts/email/new_student_account_confirmation.html b/templates/accounts/email/new_student_account_confirmation.html index 9e35d9d..c04c6db 100755 --- a/templates/accounts/email/new_student_account_confirmation.html +++ b/templates/accounts/email/new_student_account_confirmation.html @@ -268,8 +268,8 @@

Login credentials for your DJ LMS account:
    -
  • ID: {user.username}
  • -
  • Your password: {password}
  • +
  • ID: {{ user.username }}
  • +
  • Your password: {{ password }}

To secure your account be sure to change your password.

diff --git a/templates/accounts/profile_single.html b/templates/accounts/profile_single.html index f3030b8..cc38a78 100644 --- a/templates/accounts/profile_single.html +++ b/templates/accounts/profile_single.html @@ -38,6 +38,10 @@ Edit Profile + {# had to name out of convention because it clashes with 'edit_[whatever]program', which directs to 'program/[id]/edit/ #} +{# #} +{# Change Program#} +{# #} {% endif %} {% if user.is_lecturer %} @@ -93,6 +97,7 @@

{% endif %}