From 2ea778143ea065f29c27de4c7e628bea4b7c8a29 Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Wed, 15 Jun 2022 23:54:44 +0100 Subject: [PATCH] Finished admin console --- ref-test/app/admin/static/js/script.js | 30 +++------- .../admin/templates/admin/auth/account.html | 4 +- .../app/admin/templates/admin/auth/login.html | 4 +- .../admin/templates/admin/auth/register.html | 4 +- .../app/admin/templates/admin/auth/reset.html | 2 +- .../templates/admin/auth/update-password.html | 2 +- .../templates/admin/components/navbar.html | 29 +++++----- .../components/secondary-navs/tests.html | 10 ++-- ref-test/app/admin/templates/admin/index.html | 20 +++---- .../admin/templates/admin/result-detail.html | 6 +- .../app/admin/templates/admin/results.html | 4 +- .../{delete-user.html => delete_user.html} | 8 +-- .../admin/templates/admin/settings/index.html | 22 +++---- .../templates/admin/settings/questions.html | 20 +++---- .../{update-user.html => update_user.html} | 14 ++--- ...d-questions.html => upload_questions.html} | 0 .../admin/templates/admin/settings/users.html | 20 +++---- ref-test/app/admin/templates/admin/test.html | 46 ++++++++------- ref-test/app/admin/templates/admin/tests.html | 10 ++-- ref-test/app/admin/views.py | 57 ++++++++++--------- ref-test/app/api/views.py | 12 ++-- ref-test/app/forms/admin.py | 9 +-- ref-test/app/models/dataset.py | 2 +- ref-test/app/models/entry.py | 2 +- ref-test/app/models/test.py | 24 ++++---- ref-test/app/models/user.py | 9 ++- ref-test/app/quiz/static/js/quiz.js | 6 +- ref-test/app/quiz/static/js/script.js | 4 +- ref-test/app/tools/auth.py | 6 +- ref-test/app/tools/data.py | 3 +- ref-test/app/tools/forms.py | 6 +- ref-test/app/views.py | 2 +- ref-test/main.py | 7 ++- 33 files changed, 198 insertions(+), 206 deletions(-) rename ref-test/app/admin/templates/admin/settings/{delete-user.html => delete_user.html} (88%) rename ref-test/app/admin/templates/admin/settings/{update-user.html => update_user.html} (84%) rename ref-test/app/admin/templates/admin/settings/{upload-questions.html => upload_questions.html} (100%) diff --git a/ref-test/app/admin/static/js/script.js b/ref-test/app/admin/static/js/script.js index a0aab2b..f6206a0 100644 --- a/ref-test/app/admin/static/js/script.js +++ b/ref-test/app/admin/static/js/script.js @@ -70,14 +70,14 @@ $('form[name=form-upload-questions]').submit(function(event) { // Edit and Delete Test Button Handlers $('.test-action').click(function(event) { - let _id = $(this).data('_id'); + let id = $(this).data('id'); let action = $(this).data('action'); - if (action == 'delete') { + if (action == 'delete' || action == 'start' || action == 'end') { $.ajax({ - url: `/admin/tests/delete/`, + url: `/admin/tests/edit/`, type: 'POST', - data: JSON.stringify({'_id': _id}), + data: JSON.stringify({'id': id, 'action': action}), // TODO Change how CRUD operations work contentType: 'application/json', success: function(response) { window.location.href = '/admin/tests/'; @@ -87,21 +87,7 @@ $('.test-action').click(function(event) { }, }); } else if (action == 'edit') { - window.location.href = `/admin/test/${_id}/` - } else if (action == 'close'){ - $.ajax({ - url: `/admin/tests/close/`, - type: 'POST', - data: JSON.stringify({'_id': _id}), - contentType: 'application/json', - success: function(response) { - $(window).scrollTop(0); - window.location.reload(); - }, - error: function(response){ - error_response(response); - }, - }); + window.location.href = `/admin/test/${id}/` } event.preventDefault(); @@ -185,13 +171,13 @@ $('#dismiss-cookie-alert').click(function(event){ // Script for Result Actions $('.result-action-buttons').click(function(event){ - var _id = $(this).data('_id'); + var id = $(this).data('id'); if ($(this).data('result-action') == 'generate') { $.ajax({ url: '/admin/certificate/', type: 'POST', - data: JSON.stringify({'_id': _id}), + data: JSON.stringify({'id': id}), contentType: 'application/json', dataType: 'html', success: function(response) { @@ -207,7 +193,7 @@ $('.result-action-buttons').click(function(event){ $.ajax({ url: window.location.href, type: 'POST', - data: JSON.stringify({'_id': _id, 'action': action}), + data: JSON.stringify({'id': id, 'action': action}), contentType: 'application/json', success: function(response) { if (action == 'delete') { diff --git a/ref-test/app/admin/templates/admin/auth/account.html b/ref-test/app/admin/templates/admin/auth/account.html index 1043fc9..b653b0f 100644 --- a/ref-test/app/admin/templates/admin/auth/account.html +++ b/ref-test/app/admin/templates/admin/auth/account.html @@ -2,7 +2,7 @@ {% block content %}
-
+ {% include "admin/components/server-alerts.html" %}

Update Your Account

{{ form.hidden_tag() }} @@ -32,7 +32,7 @@
{% endblock %} \ No newline at end of file diff --git a/ref-test/app/admin/templates/admin/auth/register.html b/ref-test/app/admin/templates/admin/auth/register.html index c6fcb4e..b1d38b9 100644 --- a/ref-test/app/admin/templates/admin/auth/register.html +++ b/ref-test/app/admin/templates/admin/auth/register.html @@ -3,14 +3,14 @@ {% block navbar %} {% endblock %} {% block content %}
-
+ {% include "admin/components/server-alerts.html" %}

Register an Account

{{ form.hidden_tag() }} diff --git a/ref-test/app/admin/templates/admin/auth/reset.html b/ref-test/app/admin/templates/admin/auth/reset.html index 96f3978..ab75ba6 100644 --- a/ref-test/app/admin/templates/admin/auth/reset.html +++ b/ref-test/app/admin/templates/admin/auth/reset.html @@ -2,7 +2,7 @@ {% block content %}
- + {% include "admin/components/server-alerts.html" %}

Reset Password

{{ form.hidden_tag() }} diff --git a/ref-test/app/admin/templates/admin/auth/update-password.html b/ref-test/app/admin/templates/admin/auth/update-password.html index 7efc244..ce4e5b8 100644 --- a/ref-test/app/admin/templates/admin/auth/update-password.html +++ b/ref-test/app/admin/templates/admin/auth/update-password.html @@ -2,7 +2,7 @@ {% block content %}
- + {% include "admin/components/server-alerts.html" %}

Update Password

{{ form.hidden_tag() }} diff --git a/ref-test/app/admin/templates/admin/components/navbar.html b/ref-test/app/admin/templates/admin/components/navbar.html index 9f77ae1..7a980b6 100644 --- a/ref-test/app/admin/templates/admin/components/navbar.html +++ b/ref-test/app/admin/templates/admin/components/navbar.html @@ -1,6 +1,6 @@
@@ -69,7 +69,7 @@ {% for result in recent_results %} - {{ result.name.surname }}, {{ result.name.first_name }} + {{ result.name.surname }}, {{ result.name.first_name }} {{ result.submission_time.strftime('%d %b %Y %H:%M') }} @@ -82,7 +82,7 @@
- View Results + View Results {% else %}
There are currently no exam results to preview. @@ -114,22 +114,22 @@ {% for test in upcoming_tests %} - {{ '—'.join([test.test_code[:4], test.test_code[4:8], test.test_code[8:]]) }} + {{ test.get_code() }} - {{ test.expiry_date.strftime('%d %b %Y') }} + {{ test.end_date.strftime('%d %b %Y') }} {% endfor %}
- View Exams + View Exams {% else %}
There are currently no upcoming exams.
- Create Exam + Create Exam {% endif %}
diff --git a/ref-test/app/admin/templates/admin/result-detail.html b/ref-test/app/admin/templates/admin/result-detail.html index c1f548f..156fb92 100644 --- a/ref-test/app/admin/templates/admin/result-detail.html +++ b/ref-test/app/admin/templates/admin/result-detail.html @@ -164,19 +164,19 @@ {% endif %}
{% if entry.status == 'late' %} - + Allow Late Entry {% endif %} - + Delete Result diff --git a/ref-test/app/admin/templates/admin/results.html b/ref-test/app/admin/templates/admin/results.html index 5c1c862..98f9077 100644 --- a/ref-test/app/admin/templates/admin/results.html +++ b/ref-test/app/admin/templates/admin/results.html @@ -69,9 +69,9 @@ diff --git a/ref-test/app/admin/templates/admin/settings/delete-user.html b/ref-test/app/admin/templates/admin/settings/delete_user.html similarity index 88% rename from ref-test/app/admin/templates/admin/settings/delete-user.html rename to ref-test/app/admin/templates/admin/settings/delete_user.html index ca766c7..cda9077 100644 --- a/ref-test/app/admin/templates/admin/settings/delete-user.html +++ b/ref-test/app/admin/templates/admin/settings/delete_user.html @@ -2,11 +2,11 @@ {% block content %} - Manage Datasets + Manage Datasets {% else %}
There are currently no question datasets uploaded.
- Upload Dataset + Upload Dataset {% endif %}
diff --git a/ref-test/app/admin/templates/admin/settings/questions.html b/ref-test/app/admin/templates/admin/settings/questions.html index 87ca8ee..9c2ea08 100644 --- a/ref-test/app/admin/templates/admin/settings/questions.html +++ b/ref-test/app/admin/templates/admin/settings/questions.html @@ -9,9 +9,6 @@ - - - File Name Uploaded @@ -31,7 +28,7 @@ {% for element in data %} - {% if element.filename == default %} + {% if element.default %}
@@ -40,16 +37,13 @@ {% endif %} - {{ element.filename }} + {{ element.date.strftime('%d %b %Y %H:%M') }} - {{ element.timestamp.strftime('%d %b %Y') }} + {{ element.creator.get_username() }} - {{ element.author }} - - - {{ element.use }} + {{ element.tests|length }} -
+
{% include "admin/components/server-alerts.html" %} -

Update User ‘{{ user.username }}’

+

Update User ‘{{ user.get_username() }}’

{{ form.hidden_tag() }}
- {{ form.email(class_="form-control", placeholder="Email Address", value = user.email) }} + {{ form.email(class_="form-control", placeholder="Email Address", value = user.get_email()) }} {{ form.email.label }}
@@ -23,17 +23,17 @@ {{ form.notify.label }}
- Please confirm your password before committing any changes to a user account. + Please confirm your current password before committing any changes to a user account.
- {{ form.user_password(class_="form-control", placeholder="Your Password", value = user.email) }} - {{ form.user_password.label }} + {{ form.confirm_password(class_="form-control", placeholder="Your Password", value = user.email) }} + {{ form.confirm_password.label }}
{% include "admin/components/client-alerts.html" %}
- + diff --git a/ref-test/app/admin/templates/admin/settings/upload-questions.html b/ref-test/app/admin/templates/admin/settings/upload_questions.html similarity index 100% rename from ref-test/app/admin/templates/admin/settings/upload-questions.html rename to ref-test/app/admin/templates/admin/settings/upload_questions.html diff --git a/ref-test/app/admin/templates/admin/settings/users.html b/ref-test/app/admin/templates/admin/settings/users.html index e770d71..976f775 100644 --- a/ref-test/app/admin/templates/admin/settings/users.html +++ b/ref-test/app/admin/templates/admin/settings/users.html @@ -23,7 +23,7 @@ {% for user in users %} - {% if user._id == get_id_from_cookie() %} + {% if user == current_user %}
@@ -32,18 +32,18 @@ {% endif %} - {{ user.username }} + {{ user.get_username() }} - {{ user.email }} + {{ user.get_email() }} diff --git a/ref-test/app/admin/templates/admin/test.html b/ref-test/app/admin/templates/admin/test.html index 8c1b2d3..72eaf5e 100644 --- a/ref-test/app/admin/templates/admin/test.html +++ b/ref-test/app/admin/templates/admin/test.html @@ -12,38 +12,33 @@
Exam Code

- {{ '—'.join([test.test_code[:4], test.test_code[4:8], test.test_code[8:]]) }} + {{ test.get_code() }}

  • Dataset
    - {{ test.dataset }} + {{ test.dataset.date.strftime('%Y%m%d%H%M%S') }}
  • Created By
    - {{ test.creator }} -
  • -
  • -
    -
    Date Created
    -
    - {{ test.date_created.strftime('%d %b %Y') }} + {{ test.creator.get_username() }}
  • +
  • Start Date
    - {{ test.start_date.strftime('%d %b %Y') }} + {{ test.start_date.strftime('%d %b %Y %H:%M') }}
  • Expiry Date
    - {{ test.expiry_date.strftime('%d %b %Y') }} + {{ test.end_date.strftime('%d %b %Y %H:%M') }}
  • @@ -62,7 +57,7 @@ {% endif %}
  • {% endif %} - {% if 'time_adjustments' in test and test.time_adjustments|length > 0 %} + {% if test.adjustments %}