update trainee / supervisor management
This commit is contained in:
+1
-1
@@ -684,7 +684,7 @@ class TraineeForm(Form):
|
|||||||
last_name = CharField(max_length=255, required=True)
|
last_name = CharField(max_length=255, required=True)
|
||||||
grade = ModelChoiceField(UserGrades.objects.all(), required=False)
|
grade = ModelChoiceField(UserGrades.objects.all(), required=False)
|
||||||
supervisor = ModelChoiceField(
|
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
|
) # Needs to be a user/object ref
|
||||||
|
|
||||||
#class Meta:
|
#class Meta:
|
||||||
|
|||||||
+1
-1
@@ -1643,7 +1643,7 @@ class Supervisor(models.Model):
|
|||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
null=True,
|
null=True,
|
||||||
blank=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 = models.ForeignKey(
|
||||||
"Site",
|
"Site",
|
||||||
|
|||||||
+8
-2
@@ -1,3 +1,4 @@
|
|||||||
|
from django.urls import reverse
|
||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django_tables2.utils import A
|
from django_tables2.utils import A
|
||||||
|
|
||||||
@@ -312,8 +313,9 @@ class SupervisorTable(tables.Table):
|
|||||||
verbose_name="Name",
|
verbose_name="Name",
|
||||||
)
|
)
|
||||||
|
|
||||||
edit = tables.LinkColumn(
|
# We don't use a link column as we want to add a redirect parameter
|
||||||
"generic:supervisor_edit", text="Edit", args=[A("pk")], orderable=False
|
edit = tables.Column(
|
||||||
|
accessor="pk", orderable=False
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -322,3 +324,7 @@ class SupervisorTable(tables.Table):
|
|||||||
|
|
||||||
sequence = ("name", "email")
|
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 %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>Edit Supervisor / {{object.cid}}</h2>
|
<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 %}
|
{% if errors %}
|
||||||
<div class="alert alert-info" role="alert">{{errors}}</a></div>
|
<div class="alert alert-info" role="alert">{{errors}}</a></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
+8
-7
@@ -112,6 +112,13 @@ import plotly.express as px
|
|||||||
from django.db.models import Prefetch
|
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):
|
class AuthorRequiredMixin(object):
|
||||||
def get_object(self, *args, **kwargs):
|
def get_object(self, *args, **kwargs):
|
||||||
obj = super().get_object(*args, **kwargs)
|
obj = super().get_object(*args, **kwargs)
|
||||||
@@ -3480,7 +3487,7 @@ class SupervisorDelete(CidManagerRequiredMixin, DeleteView):
|
|||||||
success_url = reverse_lazy("generic:supervisor")
|
success_url = reverse_lazy("generic:supervisor")
|
||||||
|
|
||||||
|
|
||||||
class SupervisorUpdate(CidManagerRequiredMixin, UpdateView):
|
class SupervisorUpdate(RedirectMixin, CidManagerRequiredMixin, UpdateView):
|
||||||
model = Supervisor
|
model = Supervisor
|
||||||
form_class = SupervisorForm
|
form_class = SupervisorForm
|
||||||
# success_url = reverse_lazy("generic:supervisor_detail", kwargs={'pk': self.pk})
|
# success_url = reverse_lazy("generic:supervisor_detail", kwargs={'pk': self.pk})
|
||||||
@@ -3630,12 +3637,6 @@ class ExamGroupsUpdateBase(
|
|||||||
kwargs.update({"user": self.request.user})
|
kwargs.update({"user": self.request.user})
|
||||||
return kwargs
|
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):
|
class UpdateQuestionMixin(RedirectMixin, RevisionMixin, UpdateView):
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
|
|||||||
+15
-1
@@ -1,5 +1,5 @@
|
|||||||
import secrets
|
import secrets
|
||||||
from typing import Optional
|
from typing import Any, Optional
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from django_tables2 import SingleTableMixin
|
from django_tables2 import SingleTableMixin
|
||||||
@@ -77,6 +77,8 @@ from django.template import RequestContext
|
|||||||
|
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
|
from dal import autocomplete
|
||||||
|
|
||||||
def feedback_checker(user):
|
def feedback_checker(user):
|
||||||
return user.groups.filter(name="feedback_checker").exists()
|
return user.groups.filter(name="feedback_checker").exists()
|
||||||
|
|
||||||
@@ -655,6 +657,18 @@ class UpdateUserProfileView(UpdateView):
|
|||||||
self.fields = ["grade", "registration_number", "site"]
|
self.fields = ["grade", "registration_number", "site"]
|
||||||
return super().dispatch(request, *args, **kwargs)
|
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):
|
def get_success_url(self):
|
||||||
if "redirect" in self.request.GET:
|
if "redirect" in self.request.GET:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
{% load auth_extras %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<p>
|
<p>
|
||||||
<div class="anatomy">
|
<div class="anatomy">
|
||||||
@@ -53,7 +53,8 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div>
|
<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>
|
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>
|
<p>Manage <a href="{% url 'generic:examination_view' %}">Examinations</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user