update trainee / supervisor management

This commit is contained in:
Ross
2024-09-09 12:41:27 +01:00
parent b8ee207061
commit 41a4aa1a4c
7 changed files with 39 additions and 16 deletions
+1 -1
View File
@@ -684,7 +684,7 @@ class TraineeForm(Form):
last_name = CharField(max_length=255, required=True)
grade = ModelChoiceField(UserGrades.objects.all(), required=False)
supervisor = ModelChoiceField(
Supervisor.objects.all(), required=False, widget=autocomplete.ModelSelect2(url='generic:supervisor-autocomplete')
Supervisor.objects.all().order_by("name"), required=False, widget=autocomplete.ModelSelect2(url='generic:supervisor-autocomplete')
) # Needs to be a user/object ref
#class Meta:
+1 -1
View File
@@ -1643,7 +1643,7 @@ class Supervisor(models.Model):
on_delete=models.CASCADE,
null=True,
blank=True,
help_text="If the supervisor has an account on the test system that can be associated here",
help_text="If the supervisor has an account on the test system it can be associated here",
)
site = models.ForeignKey(
"Site",
+9 -3
View File
@@ -1,3 +1,4 @@
from django.urls import reverse
import django_tables2 as tables
from django_tables2.utils import A
@@ -312,8 +313,9 @@ class SupervisorTable(tables.Table):
verbose_name="Name",
)
edit = tables.LinkColumn(
"generic:supervisor_edit", text="Edit", args=[A("pk")], orderable=False
# We don't use a link column as we want to add a redirect parameter
edit = tables.Column(
accessor="pk", orderable=False
)
class Meta:
@@ -321,4 +323,8 @@ class SupervisorTable(tables.Table):
template_name = "django_tables2/bootstrap4.html"
sequence = ("name", "email")
exclude = ("id",)
exclude = ("id",)
def render_edit(self, value, record):
url = f"{reverse("generic:supervisor_edit", args=[record.pk])}?redirect={self.request.path}"
return format_html("<a href='{}'>Edit</a>", url)
@@ -18,7 +18,8 @@
{% endblock %}
{% block content %}
<h2>Edit Supervisor / {{object.cid}}</h2>
Use this form to create / edit a supervisor
<p>Use this form to create / edit a supervisor</p>
<p>Trainees can be assigned to a supervisor by editing the trainee and selecting the supervisor from the drop down list.</p>
{% if errors %}
<div class="alert alert-info" role="alert">{{errors}}</a></div>
{% endif %}
+8 -7
View File
@@ -112,6 +112,13 @@ import plotly.express as px
from django.db.models import Prefetch
class RedirectMixin():
def get_success_url(self) -> str:
if "redirect" in self.request.GET:
return self.request.GET["redirect"]
return super().get_success_url()
class AuthorRequiredMixin(object):
def get_object(self, *args, **kwargs):
obj = super().get_object(*args, **kwargs)
@@ -3480,7 +3487,7 @@ class SupervisorDelete(CidManagerRequiredMixin, DeleteView):
success_url = reverse_lazy("generic:supervisor")
class SupervisorUpdate(CidManagerRequiredMixin, UpdateView):
class SupervisorUpdate(RedirectMixin, CidManagerRequiredMixin, UpdateView):
model = Supervisor
form_class = SupervisorForm
# success_url = reverse_lazy("generic:supervisor_detail", kwargs={'pk': self.pk})
@@ -3630,12 +3637,6 @@ class ExamGroupsUpdateBase(
kwargs.update({"user": self.request.user})
return kwargs
class RedirectMixin():
def get_success_url(self) -> str:
if "redirect" in self.request.GET:
return self.request.GET["redirect"]
return super().get_success_url()
class UpdateQuestionMixin(RedirectMixin, RevisionMixin, UpdateView):
def get_form_kwargs(self):
+15 -1
View File
@@ -1,5 +1,5 @@
import secrets
from typing import Optional
from typing import Any, Optional
from django.conf import settings
from django_tables2 import SingleTableMixin
@@ -77,6 +77,8 @@ from django.template import RequestContext
from django.db.models import Q
from dal import autocomplete
def feedback_checker(user):
return user.groups.filter(name="feedback_checker").exists()
@@ -655,6 +657,18 @@ class UpdateUserProfileView(UpdateView):
self.fields = ["grade", "registration_number", "site"]
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs: reverse_lazy) -> dict[str, Any]:
context = super().get_context_data(**kwargs)
form = context["form"]
if "supervisor" in form.fields:
#form.fields["supervisor"].queryset = Supervisor.objects.all()
form.fields["supervisor"] = forms.ModelChoiceField(
Supervisor.objects.all().order_by("name"), required=False, widget=autocomplete.ModelSelect2(url='generic:supervisor-autocomplete')
)
return context
def get_success_url(self):
if "redirect" in self.request.GET:
+3 -2
View File
@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% load auth_extras %}
{% block content %}
<p>
<div class="anatomy">
@@ -53,7 +53,8 @@
{% endif %}
<div>
{% if request.user.is_staff %}
{% if request.user|has_group:"cid_user_manager" %}
Manage <a href="{% url 'trainees' %}">trainees</a><br/>
Manage users <a href="{% url 'accounts_list'%}">here</a> and candidates <a href="{% url 'generic:manage_cids'%}">here</a>
<p>Manage <a href="{% url 'generic:examination_view' %}">Examinations</a>