improve trainee management
This commit is contained in:
@@ -23,20 +23,21 @@
|
|||||||
<th>Grade</th><th>Email</th><th>Supervisor</th><th>Edit</th>
|
<th>Grade</th><th>Email</th><th>Supervisor</th><th>Edit</th>
|
||||||
<th class="trainee-bulk-edit">Bulk Edit<br/>
|
<th class="trainee-bulk-edit">Bulk Edit<br/>
|
||||||
<span _="on click log 'test' then log 'hello' then repeat for i in <input/>
|
<span _="on click log 'test' then log 'hello' then repeat for i in <input/>
|
||||||
set i.checked to not i.checked
|
-- set i.checked to not i.checked
|
||||||
|
toggle [@checked] on i
|
||||||
">Toggle All</span>
|
">Toggle All</span>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
{% for trainee in trainees %}
|
{% for trainee in trainees %}
|
||||||
<tr class="trainee">
|
<tr class="trainee" _="on click log 'test' then log the next <input/> then toggle [@checked] on <input/> in me">
|
||||||
<td>{{trainee.user.first_name}} {{trainee.user.last_name}}</td>
|
<td>{{trainee.user.first_name}} {{trainee.user.last_name}}</td>
|
||||||
<td
|
<td
|
||||||
{% if not trainee.grade %}
|
{% if not trainee.grade %}
|
||||||
class="no-grade"
|
class="no-grade"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
>{{trainee.grade}}{% if not trainee.grade %}
|
>{{trainee.grade}}{% if not trainee.grade %}
|
||||||
<a href="{% url 'account_profile_update' trainee.user.username %}" class="add-grade">add</a>
|
<a href="{% url 'account_profile_update' trainee.user.username %}?redirect={{request.path}}" class="add-grade">add</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>{{trainee.user.email}}</td>
|
<td>{{trainee.user.email}}</td>
|
||||||
@@ -45,7 +46,7 @@
|
|||||||
class="no-supervisor"
|
class="no-supervisor"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
>{{trainee.supervisor}}{% if not trainee.supervisor %}
|
>{{trainee.supervisor}}{% if not trainee.supervisor %}
|
||||||
<a href="{% url 'account_profile_update' trainee.user.username %}" class="add-supervisor">add</a>
|
<a href="{% url 'account_profile_update' trainee.user.username %}?redirect={{request.path}}" class="add-supervisor">add</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td><a href="{% url 'account_update' trainee.user.username %}">User</a>/<a href="{% url 'account_profile_update' trainee.user.username %}">Profile</a>
|
<td><a href="{% url 'account_update' trainee.user.username %}">User</a>/<a href="{% url 'account_profile_update' trainee.user.username %}">Profile</a>
|
||||||
@@ -54,7 +55,7 @@
|
|||||||
></i></span>
|
></i></span>
|
||||||
</td>
|
</td>
|
||||||
<td class="trainee-bulk-edit">
|
<td class="trainee-bulk-edit">
|
||||||
<input type="checkbox" name="trainee" value="{{trainee.user.pk}}">
|
<input type="checkbox" name="selection" value="{{trainee.user.pk}}">
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
@@ -67,11 +68,41 @@
|
|||||||
|
|
||||||
<button class="btn btn-sm"
|
<button class="btn btn-sm"
|
||||||
_="on click toggle .show on .remove-trainee"
|
_="on click toggle .show on .remove-trainee"
|
||||||
>Remove trainees</button>
|
>Remove trainee status</button>
|
||||||
<button class="btn btn-sm"
|
<button class="btn btn-sm"
|
||||||
_="on click toggle .show on .trainee-bulk-edit"
|
_="on click toggle .show on .trainee-bulk-edit"
|
||||||
>Bulk edit trainees</button>
|
>Bulk edit trainees</button>
|
||||||
|
|
||||||
|
<div id="bulk-edit" class="trainee-bulk-edit">
|
||||||
|
<h3>Bulk edit options</h3>
|
||||||
|
These actions will act on all the selected trainees. Refresh the page to cancel / clear.
|
||||||
|
<div id="htmx-info"></div>
|
||||||
|
<div id="htmx-options"></div>
|
||||||
|
<button id="bulk-delete-supervisors-button"
|
||||||
|
title="Deletes the supervisors of all selected users"
|
||||||
|
hx-post="{% url 'generic:users_bulk_delete_supervisors' %}"
|
||||||
|
hx-include="[name='selection']"
|
||||||
|
hx-confirm="This will delete supervisors from all selected users, are you sure you wish to continue?"
|
||||||
|
hx-target="#htmx-info"
|
||||||
|
_='on click put "" into #htmx-options'
|
||||||
|
>Delete supervisors</button>
|
||||||
|
<button id="bulk-edit-grade-button"
|
||||||
|
hx-post="{% url 'generic:users_bulk_edit' %}"
|
||||||
|
hx-include="[name='selection']"
|
||||||
|
hx-target="#htmx-options"
|
||||||
|
title="Changes the selected users grade."
|
||||||
|
|
||||||
|
>Edit grade</button>
|
||||||
|
<button id="bulk-deactivate-user-button"
|
||||||
|
hx-post="{% url 'generic:users_bulk_edit' %}"
|
||||||
|
hx-include="[name='selection']"
|
||||||
|
hx-target="#htmx-options"
|
||||||
|
hx-confirm="This will deactivate all selected users, are you sure you wish to continue?"
|
||||||
|
title="Deactivates the selected users"
|
||||||
|
|
||||||
|
>Deactivate</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.add-supervisor, .add-grade {
|
.add-supervisor, .add-grade {
|
||||||
font-size: small;
|
font-size: small;
|
||||||
@@ -85,8 +116,12 @@
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#bulk-edit {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.show {
|
.show {
|
||||||
display: inline;
|
display: inline !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
td {
|
td {
|
||||||
|
|||||||
+17
-1
@@ -2853,6 +2853,17 @@ def users_bulk_edit(request):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
# TODO: work out how to actually use hyperscript
|
# TODO: work out how to actually use hyperscript
|
||||||
|
html = (
|
||||||
|
html
|
||||||
|
+
|
||||||
|
f"""<button class='change-grade-button' id='add-grade--remove'
|
||||||
|
hx-post="{reverse('generic:users_bulk_edit')}"
|
||||||
|
hx-include="[name='selection']"
|
||||||
|
hx-confirm="This will remove grades of all selected users, are you sure you wish to continue?"
|
||||||
|
hx-target="#htmx-info"
|
||||||
|
_='on click put "" into #htmx-options'
|
||||||
|
>Remove</button>"""
|
||||||
|
)
|
||||||
html = (
|
html = (
|
||||||
html
|
html
|
||||||
+ "<button class='cancel-button' _='on click for el in .change-grade-button remove el end then remove me'>Cancel</button>"
|
+ "<button class='cancel-button' _='on click for el in .change-grade-button remove el end then remove me'>Cancel</button>"
|
||||||
@@ -2861,9 +2872,14 @@ def users_bulk_edit(request):
|
|||||||
case r if r.startswith("add-grade"):
|
case r if r.startswith("add-grade"):
|
||||||
user_models = get_user_selection_from_request(request)
|
user_models = get_user_selection_from_request(request)
|
||||||
|
|
||||||
|
grade = r.split("--")[-1]
|
||||||
|
|
||||||
|
if grade == "remove":
|
||||||
|
grade = None
|
||||||
|
|
||||||
# u: User
|
# u: User
|
||||||
for u in user_models:
|
for u in user_models:
|
||||||
u.userprofile.grade_id = r.split("--")[-1]
|
u.userprofile.grade_id = grade
|
||||||
u.save()
|
u.save()
|
||||||
html = "Grades updated"
|
html = "Grades updated"
|
||||||
case "bulk-add-group-button":
|
case "bulk-add-group-button":
|
||||||
|
|||||||
+4
-1
@@ -7,7 +7,7 @@ from atlas.models import CaseCollection, CidReportAnswer
|
|||||||
from generic.decorators import user_is_cid_user_manager
|
from generic.decorators import user_is_cid_user_manager
|
||||||
from generic.filters import UserUserFilter
|
from generic.filters import UserUserFilter
|
||||||
from generic.tables import UserUserTable
|
from generic.tables import UserUserTable
|
||||||
from generic.views import CidManagerRequiredMixin, get_question_and_content_type
|
from generic.views import CidManagerRequiredMixin, RedirectMixin, get_question_and_content_type
|
||||||
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
|
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
|
||||||
from django.shortcuts import render, get_object_or_404, redirect
|
from django.shortcuts import render, get_object_or_404, redirect
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
@@ -657,6 +657,9 @@ class UpdateUserProfileView(UpdateView):
|
|||||||
|
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
if "redirect" in self.request.GET:
|
||||||
|
return self.request.GET["redirect"]
|
||||||
|
|
||||||
if self.request.user.is_superuser or self.request.user.groups.filter(name="cid_user_manager").exists():
|
if self.request.user.is_superuser or self.request.user.groups.filter(name="cid_user_manager").exists():
|
||||||
view_name = "account_profile"
|
view_name = "account_profile"
|
||||||
# No need for reverse_lazy here, because it's called inside the method
|
# No need for reverse_lazy here, because it's called inside the method
|
||||||
|
|||||||
Reference in New Issue
Block a user