From ee7ffddd77329a08e0597c096de5cf2bb215b754 Mon Sep 17 00:00:00 2001 From: Paige Williams Date: Thu, 30 Oct 2025 15:16:20 -0700 Subject: [PATCH 01/15] use bootstrap modal to display info content --- TEKDB/TEKDB/static/admin/js/admin_index.js | 39 +++++++++------------- TEKDB/TEKDB/templates/admin/index.html | 21 ++++++++++-- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/TEKDB/TEKDB/static/admin/js/admin_index.js b/TEKDB/TEKDB/static/admin/js/admin_index.js index 6b2ee42f..07d21c87 100644 --- a/TEKDB/TEKDB/static/admin/js/admin_index.js +++ b/TEKDB/TEKDB/static/admin/js/admin_index.js @@ -44,64 +44,55 @@ $(function() { }); $('button#export-info').click(function(e) { - window.alert( - "Export Database Tool:\n\n" + - + $('#modalTitle').text("Export Database Tool"); + $('#modalBody').html( "The Export Database Tool is designed to support saving the current " + "state of your Traditional Knowledge Database. This is best " + - "used in conjunction with the 'Import Database' tool below. \n\n" + + "used in conjunction with the 'Import Database' tool below.

" + "To use the Export Database tool is simple: just press 'Export to " + ".zip' button and all of your data and media files will be collected " + - "into a single zipfile and downloaded to your current computer." + - "\n\n" + + "into a single zipfile and downloaded to your current computer.

" + "This is VERY DANGEROUS! While keeping regular backups " + "of your database is crucial to preventing data loss from future " + "incidents, the exported file will contain ALL of your data in an " + "unencrypted format. These exported files " + "must be kept in a secure place and only shared via secure channels: " + - "NOT BY EMAIL.\n\n" + + "NOT BY EMAIL.

" + "Please work with IT professionals to design " + "a safe and secure practice for regular backups, which may or may " + "not involve this tool." ); - }) + }); $('button#import-info').click(function(e) { - window.alert( - "Import Database Tool:\n\n" + - - "The Import Database Tool is designed to support restoring your " + - "Traditional Knowledge Database back to a prior state. This is best " + - "used in conjunction with the 'Export Database' tool above. \n\n" + - - "To use the Import Database tool is simple: select a properly formatted " + - "zip file to upload and then click 'Import'. All of your data will " + - "be reverted back to the state it was when that zipfile was created." + - "\n\n" + + $('#modalTitle').text("Import Database Tool"); + $('#modalBody').html( + "The Import Database Tool is designed to support restoring your Traditional Knowledge Database back to a prior state. This is best used in conjunction with the 'Export Database' tool above.

" + + + "To use the Import Database tool is simple: select a properly formatted zip file to upload and then click 'Import'. All of your data will be reverted back to the state it was when that zipfile was created.

" + "This is VERY DANGEROUS! For this to work, all of the data currently " + "in your database, including your users, your records, and your page " + "contents will be removed, and then replaced. Also, any files " + "associated with your media records (images, audio, video, PDFs, " + "etc...) will be overwritten by any files of the same name included " + - "in the zipped up backup file that you import.\n\n" + + "in the zipped up backup file that you import.

" + "If you wish to use this, it is recommended that you work with IT " + "professionals prior to undertaking this task. While IT cannot create " + "one of these import files for a prior state, they can help you " + "securely preserve any new zipped export files, and should be able " + "to create a system backup of your database to restore in the event " + - "of complications while using this tool. \n\n" + + "of complications while using this tool.

" + "Note that a zipped backup file is easily created for your current " + "state with the 'Export to .zip' button above, but cannot be " + "created by hand. If you have not created any of these files, you " + - "should not use this tool." - ); - }) + "should not use this tool."); + }); diff --git a/TEKDB/TEKDB/templates/admin/index.html b/TEKDB/TEKDB/templates/admin/index.html index 1ac0b221..f10142d8 100644 --- a/TEKDB/TEKDB/templates/admin/index.html +++ b/TEKDB/TEKDB/templates/admin/index.html @@ -25,7 +25,7 @@ {% if user.is_superuser %}
-

{% translate 'Export database' %}

+

{% translate 'Export database' %}

Export to .zip @@ -34,7 +34,7 @@

{% translate 'Export database' %}

+

{% translate 'Import database' %}

{% csrf_token %} @@ -74,5 +74,22 @@

{% translate 'My actions' %}

{% endif %}
+ + {% endblock %} \ No newline at end of file From f07af908b8c0325c11b261561cf899bc8364a15e Mon Sep 17 00:00:00 2001 From: Paige Williams Date: Fri, 31 Oct 2025 14:56:10 -0700 Subject: [PATCH 02/15] use bootstrap modal for import/export info and process --- TEKDB/TEKDB/static/admin/js/admin_index.js | 212 ++++++++++++--------- TEKDB/TEKDB/templates/admin/index.html | 10 +- 2 files changed, 131 insertions(+), 91 deletions(-) diff --git a/TEKDB/TEKDB/static/admin/js/admin_index.js b/TEKDB/TEKDB/static/admin/js/admin_index.js index 07d21c87..85ccf849 100644 --- a/TEKDB/TEKDB/static/admin/js/admin_index.js +++ b/TEKDB/TEKDB/static/admin/js/admin_index.js @@ -1,99 +1,139 @@ -$(function() { - $('button#import-button').click(function(e) { - e.preventDefault(); - if ( - window.confirm( - "This process will remove all data and files from your current " + - "database and replace it with data from the provided zip file. " + - "\n\n" + - "This process CANNOT be undone. \n\n" + - "It is recommended that you use the button above to export " + - "your current database status so that you may restore to your " + - "present state, AND that you COORDINATE WITH IT professionals " + - "prior to attempting this. \n\n" + - "You will need to log in again using administrator credentials " + - "as defined by the new data: your current account will cease to " + - "exist.\n\n" + - "Are you sure you understand and are prepared to take this risk?" - ) - ) { - form = $('#import-database-form'); - $.ajax({ - url: '/import_database/', - data: new FormData(form[0]), - type: "POST", - processData: false, - contentType: false, - success: function(data, status) { - if (data.hasOwnProperty('status_code') && data.hasOwnProperty('status_message')) { - if (data.status_code == 200) { - window.alert(data.status_message + "\n\nYou may now be logged out."); - window.location.reload(); - } else { - window.alert("Error Code: " + data.status_code + "\n\n" + data.status_message); - } - } else { - window.alert("Unexpected error occurred: " + status); - } - }, - error: function(xhr, desc, err) { - window.alert("Unexpected error occurred: " + err); - } - }) - } - }); +const importText = ` + This process will remove all data and files from your current + database and replace it with data from the provided zip file. +

+ This process CANNOT be undone.

+ It is recommended that you use the 'Export to .zip' button above to export + your current database status so that you may restore to your + present state, AND that you COORDINATE WITH IT professionals + prior to attempting this.

+ You will need to log in again using administrator credentials + as defined by the new data: your current account will cease to + exist.

+ Are you sure you understand and are prepared to take this risk? +` +const importInfoText = `The Import Database Tool is designed to support restoring your Traditional Knowledge Database back to a prior state. This is best used in conjunction with the 'Export Database' tool above.

+ To use the Import Database tool is simple: select a properly formatted zip file to upload and then click 'Import'. All of your data will be reverted back to the state it was when that zipfile was created.

+ This is VERY DANGEROUS! For this to work, all of the data currently + in your database, including your users, your records, and your page + contents will be removed, and then replaced. Also, any files + associated with your media records (images, audio, video, PDFs, + etc...) will be overwritten by any files of the same name included + in the zipped up backup file that you import.

+ If you wish to use this, it is recommended that you work with IT + professionals prior to undertaking this task. While IT cannot create + one of these import files for a prior state, they can help you + securely preserve any new zipped export files, and should be able + to create a system backup of your database to restore in the event + of complications while using this tool.

+ Note that a zipped backup file is easily created for your current + state with the 'Export to .zip' button above, but cannot be + created by hand. If you have not created any of these files, you + should not use this tool.` - $('button#export-info').click(function(e) { - $('#modalTitle').text("Export Database Tool"); - $('#modalBody').html( - "The Export Database Tool is designed to support saving the current " + - "state of your Traditional Knowledge Database. This is best " + - "used in conjunction with the 'Import Database' tool below.

" + +const exportInfoText = `The Export Database Tool is designed to support saving the current + state of your Traditional Knowledge Database. This is best + used in conjunction with the 'Import Database' tool below.

- "To use the Export Database tool is simple: just press 'Export to " + - ".zip' button and all of your data and media files will be collected " + - "into a single zipfile and downloaded to your current computer.

" + + To use the Export Database tool is simple: just press 'Export to + .zip' button and all of your data and media files will be collected + into a single zipfile and downloaded to your current computer.

- "This is VERY DANGEROUS! While keeping regular backups " + - "of your database is crucial to preventing data loss from future " + - "incidents, the exported file will contain ALL of your data in an " + - "unencrypted format. These exported files " + - "must be kept in a secure place and only shared via secure channels: " + - "NOT BY EMAIL.

" + + This is VERY DANGEROUS! While keeping regular backups + of your database is crucial to preventing data loss from future + incidents, the exported file will contain ALL of your data in an + unencrypted format. These exported files + must be kept in a secure place and only shared via secure channels: + NOT BY EMAIL.

- "Please work with IT professionals to design " + - "a safe and secure practice for regular backups, which may or may " + - "not involve this tool." - ); - }); + Please work with IT professionals to design + a safe and secure practice for regular backups, which may or may + not involve this tool.` + +$(function () { + const unexpectedError = (statusCode, statusMessage) => { + return `

Unexpected error occurred: ${statusCode}

${statusMessage}

`; + }; + + const showNextStepsSection = () => { + $("#modalNextSteps").removeClass("hidden"); + } - $('button#import-info').click(function(e) { - $('#modalTitle').text("Import Database Tool"); - $('#modalBody').html( - "The Import Database Tool is designed to support restoring your Traditional Knowledge Database back to a prior state. This is best used in conjunction with the 'Export Database' tool above.

" + - - "To use the Import Database tool is simple: select a properly formatted zip file to upload and then click 'Import'. All of your data will be reverted back to the state it was when that zipfile was created.

" + + const showModalFooter = () => { + $(".modal-footer").show(); + } - "This is VERY DANGEROUS! For this to work, all of the data currently " + - "in your database, including your users, your records, and your page " + - "contents will be removed, and then replaced. Also, any files " + - "associated with your media records (images, audio, video, PDFs, " + - "etc...) will be overwritten by any files of the same name included " + - "in the zipped up backup file that you import.

" + + const hideModalFooter = () => { + $(".modal-footer").hide(); + } - "If you wish to use this, it is recommended that you work with IT " + - "professionals prior to undertaking this task. While IT cannot create " + - "one of these import files for a prior state, they can help you " + - "securely preserve any new zipped export files, and should be able " + - "to create a system backup of your database to restore in the event " + - "of complications while using this tool.

" + + $("button#import-button").click(function (e) { + e.preventDefault(); + showModalFooter(); + + $("#modalTitle").text("Export Database Tool"); + $("#modalBody").html(importText); - "Note that a zipped backup file is easily created for your current " + - "state with the 'Export to .zip' button above, but cannot be " + - "created by hand. If you have not created any of these files, you " + - "should not use this tool."); + $("#continueImport").click(function () { + form = $("#import-database-form"); + $.ajax({ + url: "/import_database/", + data: new FormData(form[0]), + type: "POST", + processData: false, + contentType: false, + success: function (data, status) { + if ( + data.hasOwnProperty("status_code") && + data.hasOwnProperty("status_message") + ) { + showNextStepsSection() + + if (data.status_code == 200) { + $("#modalNextSteps").html( + `

Import successful. You may now be logged out.

` + ); + + window.location.reload(); + } else { + $("#modalNextSteps").html( + `

Import failed with error code ${data.status_code}.

${data.status_message}

` + ); + } + } else { + $("#modalNextSteps").html( + unexpectedError(xhr.status, xhr.statusText) + ); + } + }, + error: function (xhr, desc, err) { + $("#modalNextSteps").html( + unexpectedError(xhr.status, xhr.statusText) + ); + }, + }); }); + $; + }); + $("button#import-info").click(function (e) { + hideModalFooter(); + $("#modalTitle").text("Import Database Tool"); + $("#modalBody").html(exportInfoText); + }); + $("button#export-info").click(function (e) { + hideModalFooter(); + $("#modalTitle").text("Export Database Tool"); + $("#modalBody").html(exportInfoText); + }); + + // Clear modal content on close + $('#exportImportModal').on('hidden.bs.modal', function () { + $("#modalTitle").text(""); + $("#modalBody").html(""); + $("#modalNextSteps").html(""); + $("#modalNextSteps").addClass("hidden"); +}); }); diff --git a/TEKDB/TEKDB/templates/admin/index.html b/TEKDB/TEKDB/templates/admin/index.html index f10142d8..7d933e1b 100644 --- a/TEKDB/TEKDB/templates/admin/index.html +++ b/TEKDB/TEKDB/templates/admin/index.html @@ -38,7 +38,7 @@

{% translate 'Import database' %} + @@ -84,10 +84,10 @@

- {% comment %} {% endcomment %} + + From 51d82f06e40ba673935ac759eccecde9c745a24a Mon Sep 17 00:00:00 2001 From: Paige Williams Date: Fri, 31 Oct 2025 15:10:46 -0700 Subject: [PATCH 03/15] gitignore vscode settings --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index e5e0451e..c5ba5117 100644 --- a/.gitignore +++ b/.gitignore @@ -96,3 +96,6 @@ ENV/ # Rope project settings .ropeproject + +#vscode settings +.vscode/ \ No newline at end of file From fde86e8652f7aad6952d0f04228ab5bd8a5c878e Mon Sep 17 00:00:00 2001 From: Paige Williams Date: Fri, 31 Oct 2025 16:25:35 -0700 Subject: [PATCH 04/15] continue integrating import flow with modal --- TEKDB/TEKDB/static/admin/js/admin_index.js | 61 +++++++++++++++------- TEKDB/TEKDB/templates/admin/index.html | 16 +++--- 2 files changed, 51 insertions(+), 26 deletions(-) diff --git a/TEKDB/TEKDB/static/admin/js/admin_index.js b/TEKDB/TEKDB/static/admin/js/admin_index.js index 85ccf849..667ebfe4 100644 --- a/TEKDB/TEKDB/static/admin/js/admin_index.js +++ b/TEKDB/TEKDB/static/admin/js/admin_index.js @@ -11,7 +11,7 @@ const importText = ` as defined by the new data: your current account will cease to exist.

Are you sure you understand and are prepared to take this risk? -` +`; const importInfoText = `The Import Database Tool is designed to support restoring your Traditional Knowledge Database back to a prior state. This is best used in conjunction with the 'Export Database' tool above.

To use the Import Database tool is simple: select a properly formatted zip file to upload and then click 'Import'. All of your data will be reverted back to the state it was when that zipfile was created.

This is VERY DANGEROUS! For this to work, all of the data currently @@ -29,7 +29,7 @@ const importInfoText = `The Import Database Tool is designed to support restorin Note that a zipped backup file is easily created for your current state with the 'Export to .zip' button above, but cannot be created by hand. If you have not created any of these files, you - should not use this tool.` + should not use this tool.`; const exportInfoText = `The Export Database Tool is designed to support saving the current state of your Traditional Knowledge Database. This is best @@ -48,7 +48,7 @@ const exportInfoText = `The Export Database Tool is designed to support saving t Please work with IT professionals to design a safe and secure practice for regular backups, which may or may - not involve this tool.` + not involve this tool.`; $(function () { const unexpectedError = (statusCode, statusMessage) => { @@ -57,24 +57,30 @@ $(function () { const showNextStepsSection = () => { $("#modalNextSteps").removeClass("hidden"); - } + }; const showModalFooter = () => { $(".modal-footer").show(); - } + }; const hideModalFooter = () => { $(".modal-footer").hide(); - } + }; $("button#import-button").click(function (e) { e.preventDefault(); showModalFooter(); - - $("#modalTitle").text("Export Database Tool"); + + $("#modalTitle").text("Import Database"); $("#modalBody").html(importText); $("#continueImport").click(function () { + // prevent closing the modal after verifying import + $("#exportImportModal").modal({ + backdrop: "static", + keyboard: false, + }); + form = $("#import-database-form"); $.ajax({ url: "/import_database/", @@ -82,34 +88,52 @@ $(function () { type: "POST", processData: false, contentType: false, - success: function (data, status) { + success: function (data) { if ( data.hasOwnProperty("status_code") && data.hasOwnProperty("status_message") ) { - showNextStepsSection() - + showNextStepsSection(); + if (data.status_code == 200) { + $("#exportImportModal").modal({ + backdrop: "static", + keyboard: false, + }); $("#modalNextSteps").html( `

Import successful. You may now be logged out.

` ); - - window.location.reload(); + $("#continueImport").html("Log out"); + $("#continueImport").click(function () { + window.location.reload(); + }); } else { $("#modalNextSteps").html( `

Import failed with error code ${data.status_code}.

${data.status_message}

` ); + $("#continueImport").html("Close"); + $("#continueImport").click(function () { + $("#exportImportModal").modal("hide"); + }); } } else { $("#modalNextSteps").html( unexpectedError(xhr.status, xhr.statusText) ); + $("#continueImport").html("Close"); + $("#continueImport").click(function () { + $("#exportImportModal").modal("hide"); + }); } }, - error: function (xhr, desc, err) { + error: function (xhr) { $("#modalNextSteps").html( unexpectedError(xhr.status, xhr.statusText) ); + $("#continueImport").html("Close"); + $("#continueImport").click(function () { + $("#exportImportModal").modal("hide"); + }); }, }); }); @@ -128,12 +152,13 @@ $(function () { $("#modalBody").html(exportInfoText); }); - // Clear modal content on close - $('#exportImportModal').on('hidden.bs.modal', function () { + // Clear modal content on close; reset to default state + $("#exportImportModal").on("hidden.bs.modal", function () { $("#modalTitle").text(""); $("#modalBody").html(""); $("#modalNextSteps").html(""); $("#modalNextSteps").addClass("hidden"); -}); - + $("#continueImport").html("Continue"); + $("#continueImport").off("click"); + }); }); diff --git a/TEKDB/TEKDB/templates/admin/index.html b/TEKDB/TEKDB/templates/admin/index.html index 7d933e1b..77655154 100644 --- a/TEKDB/TEKDB/templates/admin/index.html +++ b/TEKDB/TEKDB/templates/admin/index.html @@ -75,14 +75,14 @@

{% translate 'My actions' %}

{% endif %} -