More improvements to user management

This commit is contained in:
Ross
2022-11-21 12:43:46 +00:00
parent be3f420c68
commit 0b90308394
21 changed files with 321 additions and 44 deletions
+14 -4
View File
@@ -5,7 +5,7 @@
{% block content %}
{% if created_users %}
<div class="alert alert-success">
The follow users have been created: {{created_users}}
The following users have been created: {{created_users}}
</div>
{% endif %}
@@ -26,13 +26,16 @@
<table>
<tr><th>First name</th><th>Last name</th><th>Email</th><th>Grade</th><th>Supervisor</th><th>Supervisor email</th></tr>
<tr><td>name 1</td><td>last name 1</td><td>email 1</td><td>grade 1</td><td>supervisor 1</td><td>Supervisor email 1</td></tr>
<tr><td>name 1</td><td>last name 1</td><td>email1@email.com</td><td>grade 1</td><td>supervisor 1</td><td>Supervisor@email.com</td></tr>
<tr><td>name 2</td><td>last name 2</td><td>email2@email.com</td><td>grade 2</td><td>supervisor 2</td><td>Supervisor2@email.com</td></tr>
</table>
On your spreadsheet then "copy" the data (not including header), come to this page, put focus on the &lt;textarea> box and "paste" the text in. In some instance (large data sets) this might take a couple of seconds.
Once there simply click the button and check the users that will be created below.
</p>
<p>Please note users created this way bypass some of the validations so check details such as email addresses are correct</p>
<textarea id="csv" placeholder="Paste users content here" style="width: 300px; height: 100px;"></textarea><br/>
<input type="button" value="Load Data" onclick="createTable()" >
@@ -70,12 +73,13 @@
// Loop over the rows
var elements = ["first_name", "last_name", "grade", "email", "supervisor_name", "supervisor_email"];
var elements = ["first_name", "last_name", "email", "grade", "supervisor_name", "supervisor_email"];
var users = [];
$("#users-list").empty();
$("#users-list").append(`The following users will be created. "undefined" fields will be left blank. Emails will be used as usernames.`);
$("#users-list").append(`The following users will be created. "undefined" fields will be left blank. Emails will be used as usernames. Supervisors will be created automatically if required.`);
var emails = [];
for (i=0; i<excelRow.length - 1; i++) {
//users[i] = {};
user = {};
@@ -96,10 +100,16 @@
}
myTbody.appendChild(myRow);
users.push(user)
emails.push(user.email)
$("#users-list").append(`<li>Name: ${user.first_name} ${user.last_name}<br/>Email: ${user.email}<br/>Grade: ${user.grade}<br/>Supervisor: ${user.supervisor_name}<br/>Supervisor email: ${user.supervisor_email}</li>`)
}
myTable.appendChild(myTbody);
$.post("{% url 'accounts_check_users' %}", { csrfmiddlewaretoken: "{{ csrf_token }}",
user_list: JSON.stringify(emails) }, function(data) {
console.log("Existing users", data)
})
$("#users-list").append(`${users.length} users to create.`)
$("#user-list-json").val(JSON.stringify(users));
-4
View File
@@ -16,10 +16,6 @@
<div>
Grade: {{ user.userprofile.grade }}
</div>
<div style="border:1px dashed red">
Supervisor: {{ user.userprofile.supervisor_name }}<br/>
Supervisor Email: {{ user.userprofile.supervisor_email }}<br/>
</div>
<div>
Supervisor: {{ user.userprofile.supervisor }}<br/>
</div>
+2 -2
View File
@@ -16,8 +16,8 @@
{% for list_user in object_list %}
<li><span class="username">Username: <a href="{% url 'account_profile' list_user.username %}">{{ list_user.username }}</a></span>
<span class="name">Name: {{list_user.first_name}} {{list_user.last_name}}</span>
{% if list_user.userprofile.grade %}<span class="grade">Grade: {{list_user.userprofile.grade}}</span>{% endif %} Supervisor: {{list_user.userprofile.supervisor_name}} [{{list_user.userprofile.supervisor_email}}]
<br/> Registration number: {{list_user.registration_number}}
{% if list_user.userprofile.grade %}<span class="grade">Grade: {{list_user.userprofile.grade}}</span>{% endif %} Supervisor: {{list_user.userprofile.supervisor}}
<br/> Registration number: {{list_user.userprofile.registration_number}}
<button class="small-url-button"><a href="{% url 'account_update' list_user.username %}">Edit user</a></button>
<button class="small-url-button"><a href="{% url 'account_profile_update' list_user.username %}">Edit profile</a></button>
+1
View File
@@ -2,6 +2,7 @@
{% block content %}
<h2>Editing user: {{object.username}}</h2>
This form allows you to edit the users name and email address. More details (such as grade / supervisor / etc...) can be changed <a href="{% url 'account_profile_update' object.username %}">here</a>
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Update">
+10
View File
@@ -0,0 +1,10 @@
{% extends 'generic/base.html' %}
{% block content %}
<h2>Editing user: {{object.username}}</h2>
This form allows you to edit additional user details. Name and emails can be edited <a href="{% url 'account_update' object.username %}">here</a>
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Update">
</form>
{% endblock %}