From 8e2ba173ec177cb19bb5583da0024feeb31e7ccf Mon Sep 17 00:00:00 2001 From: Luke Tuite Date: Thu, 4 Feb 2021 10:25:22 -0500 Subject: [PATCH 01/15] Developing submit collection to be validated page --- ingest/templates/ingest/base.html | 3 ++ .../submit_request_collection_list.html | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 ingest/templates/ingest/submit_request_collection_list.html diff --git a/ingest/templates/ingest/base.html b/ingest/templates/ingest/base.html index 527654f..6907b79 100644 --- a/ingest/templates/ingest/base.html +++ b/ingest/templates/ingest/base.html @@ -60,6 +60,9 @@ +
+ + + + + + + + + + + + + + + + + +{% for collection in collections %} + + + + + + + + + + + + + + + +{% endfor %} + +
NameDescriptionOrganization LabLab NameProject Funder IDProject FunderBIL UuidData PathLockedSubmission StatusValidation Status
{{ loop.index }}{{collection.name}}{{collection.description}}{{collection.organization_name}}{{collection.lab_name}}{{collection.project_funder_id}}{{collection.project_funder}}{{collection.bil_uuid}}{{collection.data_path}}{{collection.locked}}{{collection.submission_status}}{{collection.validation_status}}
+

- - Submit Validation Request - - diff --git a/ingest/urls.py b/ingest/urls.py index f19ea17..7d749d4 100644 --- a/ingest/urls.py +++ b/ingest/urls.py @@ -36,5 +36,6 @@ re_path(r'^collection_create/$', views.collection_create, name='collection_create'), re_path(r'^collection_list/$', views.CollectionList.as_view(), name='collection_list'), re_path(r'^submit_validate_collection_list/$', views.SubmitValidateCollectionList.as_view(), name='submit_validate_collection_list'), - re_path(r'^submit_request_collection_list/$', views.SubmitRequestCollectionList.as_view(), name ='submit_request_collection_list') + re_path(r'^submit_request_collection_list/$', views.SubmitRequestCollectionList.as_view(), name ='submit_request_collection_list'), + re_path(r'^collection_send/$', views.collection_send, name = 'collection_send') ] diff --git a/ingest/views.py b/ingest/views.py index f43beac..d72fcad 100644 --- a/ingest/views.py +++ b/ingest/views.py @@ -39,7 +39,7 @@ from .tables import CollectionRequestTable import uuid import datetime - +import json def logout(request): messages.success(request, "You've successfully logged out") @@ -263,15 +263,16 @@ class ImageMetadataDelete(LoginRequiredMixin, DeleteView): @login_required def collection_send(request): - checked_ids = [] + content = request.get_json() + items = [] + for item in content: + if (item['submit_for_validation']) == True: + items.append['bilUuid'] + bilUuid = item['bilUuid'] if request.method == "POST": - for i in rows: - if submit_for_validation == True: - checked_id = request.collection_id - checked_id.append(checked_id) subject = '[BIL Validations] New Validation Request' sender = 'ltuite96@psc.edu' - message = F'The following collections have been requested of validaton {checked_id}' + message = F'The following collections have been requested to be validated {items}' recipient = 'ltuite96@psc.edu' send_mail( @@ -280,8 +281,9 @@ def collection_send(request): sender, recipient ) - return print('message was sent i hope') - + print(message) + return json.dumps({"url": url_for('ingest:index')}) + #success_url = reverse_lazy('ingest:collection_list') @login_required def collection_create(request): @@ -417,6 +419,7 @@ def get_filterset_kwargs(self, filterset_class): if kwargs["data"] is None: kwargs["data"] = {"submit_status": "NOT_SUBMITTED"} return kwargs + success_url = reverse_lazy('ingest:collection_list') #def send_email_request(request): # checked_ids = [] # if request.method == "POST": From e38e4f79868513f6d73d4b5473fed2aae1b94205 Mon Sep 17 00:00:00 2001 From: Luke Tuite Date: Tue, 23 Feb 2021 15:35:34 -0500 Subject: [PATCH 04/15] changes to javascript function --- ingest/static/ingest/sendemail.js | 2 ++ ingest/views.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ingest/static/ingest/sendemail.js b/ingest/static/ingest/sendemail.js index 49cd75f..bcc6a2c 100644 --- a/ingest/static/ingest/sendemail.js +++ b/ingest/static/ingest/sendemail.js @@ -1,5 +1,6 @@ function collection_send() { const rowform = document.getElementById("rowform"); + const allrows = rowform.elements[row]; const all_names = rowform.elements["name"] const all_descriptions = rowform.elements["description"] const all_organization_labs = rowform.elements["organization_lab"] @@ -15,6 +16,7 @@ function collection_send() { for(let i = 0; i < all_names.length; i++) { const rowdata = { + rowid: all_rows[i].value, name: all_names[i].value, description: all_descriptions[i].value, organization_lab: all_organization_labs[i].value, diff --git a/ingest/views.py b/ingest/views.py index 3db5c5c..22b7ace 100644 --- a/ingest/views.py +++ b/ingest/views.py @@ -12,6 +12,8 @@ from django.http import Http404 from django.core.exceptions import ObjectDoesNotExist from django.core.mail import send_mail +from django.http import HttpResponse +from django.http import JsonResponse from django_filters.views import FilterView from django_tables2.views import SingleTableMixin @@ -283,7 +285,7 @@ def collection_send(request): recipient ) print(message) - return json.dumps({"url": url_for('ingest:index')}) + return JsonResponse({'ingest:index'}) #success_url = reverse_lazy('ingest:collection_list') @login_required From 8665ea186f4f025131233828fd41d25fd7b7952d Mon Sep 17 00:00:00 2001 From: Luke Tuite Date: Tue, 23 Feb 2021 17:15:43 -0500 Subject: [PATCH 05/15] Still need to add Juan's suggestions --- ingest/static/ingest/sendemail.js | 7 +++++-- ingest/views.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ingest/static/ingest/sendemail.js b/ingest/static/ingest/sendemail.js index bcc6a2c..b92c4fc 100644 --- a/ingest/static/ingest/sendemail.js +++ b/ingest/static/ingest/sendemail.js @@ -1,6 +1,8 @@ function collection_send() { - const rowform = document.getElementById("rowform"); - const allrows = rowform.elements[row]; + debugger; + const rowform = document.getElementById("rowform") + const all_submit_for_validations = document.getElementById("submit_for_validation") + const all_rows = rowform.elements["row"] const all_names = rowform.elements["name"] const all_descriptions = rowform.elements["description"] const all_organization_labs = rowform.elements["organization_lab"] @@ -17,6 +19,7 @@ function collection_send() { { const rowdata = { rowid: all_rows[i].value, + submit_for_validation: all_submit_for_validations[i].value, name: all_names[i].value, description: all_descriptions[i].value, organization_lab: all_organization_labs[i].value, diff --git a/ingest/views.py b/ingest/views.py index 22b7ace..02f8861 100644 --- a/ingest/views.py +++ b/ingest/views.py @@ -285,7 +285,7 @@ def collection_send(request): recipient ) print(message) - return JsonResponse({'ingest:index'}) + return HttpResponse(status=200) #success_url = reverse_lazy('ingest:collection_list') @login_required From 25b2c3e39049efd6d2f62cc5b265a9f3a2931377 Mon Sep 17 00:00:00 2001 From: Liz Pantalone Date: Thu, 4 Mar 2021 10:28:23 -0500 Subject: [PATCH 06/15] commenting out a line --- ingest/tables.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ingest/tables.py b/ingest/tables.py index a9f6c62..b73bd87 100644 --- a/ingest/tables.py +++ b/ingest/tables.py @@ -130,7 +130,8 @@ class CollectionRequestTable(tables.Table): 'ingest:collection_detail', verbose_name="", args=[A('pk')], - text=format_html('')) + # commenting out below line because i think it is interfering with template on ingest/template/submit_collection + #text=format_html('')) #text=format_html(''), #attrs={'a': {'class': "btn btn-info", 'role': "button"}}) description = tables.Column() From d4030cfd8c39085cbad569c0ff56a9186beb427d Mon Sep 17 00:00:00 2001 From: Liz Pantalone Date: Thu, 4 Mar 2021 10:38:05 -0500 Subject: [PATCH 07/15] cleaning up submit_request_collection_list.html ingest template --- .../ingest/submit_request_collection_list.html | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/ingest/templates/ingest/submit_request_collection_list.html b/ingest/templates/ingest/submit_request_collection_list.html index 815d8e0..b956f88 100644 --- a/ingest/templates/ingest/submit_request_collection_list.html +++ b/ingest/templates/ingest/submit_request_collection_list.html @@ -8,15 +8,6 @@

Submit Request to Publicize Collection

-
@@ -52,7 +43,7 @@

Submit Request to Publicize Collection

{% endfor %} - +
{{collection.validation_status}}

From d0b0a54fe393fdff96c5d2cc89e9da1cb4bd621e Mon Sep 17 00:00:00 2001 From: Liz Pantalone Date: Thu, 4 Mar 2021 10:42:32 -0500 Subject: [PATCH 08/15] updating sendemail.js file with Juan's code --- ingest/static/ingest/sendemail.js | 57 +++++++++---------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/ingest/static/ingest/sendemail.js b/ingest/static/ingest/sendemail.js index b92c4fc..d3e12be 100644 --- a/ingest/static/ingest/sendemail.js +++ b/ingest/static/ingest/sendemail.js @@ -1,41 +1,18 @@ function collection_send() { - debugger; - const rowform = document.getElementById("rowform") - const all_submit_for_validations = document.getElementById("submit_for_validation") - const all_rows = rowform.elements["row"] - const all_names = rowform.elements["name"] - const all_descriptions = rowform.elements["description"] - const all_organization_labs = rowform.elements["organization_lab"] - const all_lab_names = rowform.elements["lab_name"] - const all_project_funder_ids = rowform.elements["project_funder_id"] - const all_project_funders = rowform.elements["project_funder"] - const all_bil_uuids = rowform.elements["bil_uuid"] - const all_data_path = rowform.elements["data_path"] - const all_locked = rowform.elements["locked"] - const all_submission_statuses = rowform.elements["submission_status"] - const all_validation_statuses = rowform.elements["validation_status"] - let output_rows = [] - for(let i = 0; i < all_names.length; i++) - { - const rowdata = { - rowid: all_rows[i].value, - submit_for_validation: all_submit_for_validations[i].value, - name: all_names[i].value, - description: all_descriptions[i].value, - organization_lab: all_organization_labs[i].value, - lab_name: all_lab_names[i].value, - project_funder_id: all_project_funder_ids[i].value, - project_funder: all_project_funders[i].value, - bil_uuid: all_bil_uuids[i].value, - data_path: all_data_path[i].value, - locked: all_locked[i].value, - submission_status: all_submission_statuses[i].value, - validation_status: all_validation_statuses[i].value, - }; - output_rows.push(rowdata); - } - console.log(output_rows); - fetch('${window.origin}/collection_send', { + let output_rows = [] + $('tbody>tr').each(function(i, e){ + let $e = $(e); + // $e is the tr element + let row_is_checked = $e.find('#collection_is_checked').is(':checked'); + // row_is_checked is a boolean of whether that row is checked or not + let bil_uuid = $e.find('#bil') + if(row_is_checked) + output_rows.push({ + 'billUuid': bil_uuid + } + ) + }); + fetch(window.origin + '/collection_send', { method: "POST", credentials: "include", body: JSON.stringify(output_rows), @@ -52,11 +29,9 @@ function collection_send() { response.json().then(function(data) { console.log(data); window.location.replace(data['url']); - }); + }); }) .catch(function(error) { console.log("Fetch error: " + error); - }); -} - +} \ No newline at end of file From 578509933de1e7df7f86b76117f759c2665664d2 Mon Sep 17 00:00:00 2001 From: Liz Pantalone Date: Thu, 4 Mar 2021 10:54:34 -0500 Subject: [PATCH 09/15] fixed syntax error line 134 ingest/tables.py --- ingest/tables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ingest/tables.py b/ingest/tables.py index b73bd87..6114626 100644 --- a/ingest/tables.py +++ b/ingest/tables.py @@ -131,7 +131,7 @@ class CollectionRequestTable(tables.Table): verbose_name="", args=[A('pk')], # commenting out below line because i think it is interfering with template on ingest/template/submit_collection - #text=format_html('')) + text=format_html('')) #text=format_html(''), #attrs={'a': {'class': "btn btn-info", 'role': "button"}}) description = tables.Column() From 7d793282a46a6c13b879607f4ff6de784b81fba8 Mon Sep 17 00:00:00 2001 From: Liz Pantalone Date: Thu, 4 Mar 2021 10:57:06 -0500 Subject: [PATCH 10/15] remove true conditional within the collection_send function of ingest/views.py --- ingest/views.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ingest/views.py b/ingest/views.py index 02f8861..5e75059 100644 --- a/ingest/views.py +++ b/ingest/views.py @@ -269,9 +269,8 @@ def collection_send(request): content = request.get_json() items = [] for item in content: - if (item['submit_for_validation']) == True: - items.append['bilUuid'] - bilUuid = item['bilUuid'] + items.append['bilUuid'] + bilUuid = item['bilUuid'] if request.method == "POST": subject = '[BIL Validations] New Validation Request' sender = 'ltuite96@psc.edu' From 9fc48a6a7202515b7ff9210b2ff3707eef1c3573 Mon Sep 17 00:00:00 2001 From: Luke Tuite Date: Thu, 4 Mar 2021 11:45:08 -0500 Subject: [PATCH 11/15] Added csrf token --- ingest/static/ingest/sendemail.js | 6 ++-- .../submit_request_collection_list.html | 4 +-- ingest/views.py | 36 ++++++++++--------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/ingest/static/ingest/sendemail.js b/ingest/static/ingest/sendemail.js index d3e12be..3b95259 100644 --- a/ingest/static/ingest/sendemail.js +++ b/ingest/static/ingest/sendemail.js @@ -1,4 +1,5 @@ function collection_send() { + const csrftoken = Cookies.get('csrftoken'); let output_rows = [] $('tbody>tr').each(function(i, e){ let $e = $(e); @@ -12,12 +13,13 @@ function collection_send() { } ) }); - fetch(window.origin + '/collection_send', { + fetch(`${window.origin}/ingest/collection_send/`, { method: "POST", credentials: "include", body: JSON.stringify(output_rows), cache: "no-cache", headers: new Headers({ + "X-CSRFToken": "csrftoken", "content-type": "application/json" }) }) @@ -34,4 +36,4 @@ function collection_send() { .catch(function(error) { console.log("Fetch error: " + error); }); -} \ No newline at end of file +} diff --git a/ingest/templates/ingest/submit_request_collection_list.html b/ingest/templates/ingest/submit_request_collection_list.html index b956f88..5e45e87 100644 --- a/ingest/templates/ingest/submit_request_collection_list.html +++ b/ingest/templates/ingest/submit_request_collection_list.html @@ -1,14 +1,14 @@ + {% extends 'ingest/wide.html' %} {% load bootstrap4 %} - {% block wide %} -

Submit Request to Publicize Collection

+{% csrf_token %} diff --git a/ingest/views.py b/ingest/views.py index 5e75059..a904912 100644 --- a/ingest/views.py +++ b/ingest/views.py @@ -267,24 +267,26 @@ class ImageMetadataDelete(LoginRequiredMixin, DeleteView): @login_required def collection_send(request): content = request.get_json() + print(content) items = [] - for item in content: - items.append['bilUuid'] - bilUuid = item['bilUuid'] - if request.method == "POST": - subject = '[BIL Validations] New Validation Request' - sender = 'ltuite96@psc.edu' - message = F'The following collections have been requested to be validated {items}' - recipient = 'ltuite96@psc.edu' - - send_mail( - subject, - message, - sender, - recipient - ) - print(message) - return HttpResponse(status=200) + #for item in content: + # items.append['bilUuid'] + # bilUuid = item['bilUuid'] + #if request.method == "POST": + # subject = '[BIL Validations] New Validation Request' + # sender = 'ltuite96@psc.edu' + # message = F'The following collections have been requested to be validated {items}' + # recipient = 'ltuite96@psc.edu' + + # send_mail( + # subject, + # message, + # sender, + # recipient + # ) + # print(message) + return redirect('index') + #return HttpResponse(status=200) #success_url = reverse_lazy('ingest:collection_list') @login_required From 2c17989ae6184b869f1bfbf96c02ca9a4c6d78e7 Mon Sep 17 00:00:00 2001 From: Luke Tuite Date: Fri, 5 Mar 2021 16:59:20 -0500 Subject: [PATCH 12/15] update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 68d0f90..dfbba65 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ __pycache__/ *.py[cod] *.swp *venv +/bil_site/settings.py site.cfg bil_sit/settings_secret.py ingest/settings_secret.py From ea5b9954c009edde335bd0057bc1862b0765c10a Mon Sep 17 00:00:00 2001 From: Luke Tuite Date: Fri, 5 Mar 2021 17:00:48 -0500 Subject: [PATCH 13/15] update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dfbba65..f222f10 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ __pycache__/ *.py[cod] *.swp *venv -/bil_site/settings.py +bil_site/settings.py site.cfg bil_sit/settings_secret.py ingest/settings_secret.py From d3068feb1c631fb4c3ae252333bddb4b9c8eff67 Mon Sep 17 00:00:00 2001 From: Luke Tuite Date: Fri, 5 Mar 2021 17:01:44 -0500 Subject: [PATCH 14/15] sendemail function now working --- ingest/static/ingest/sendemail.js | 6 +-- .../submit_request_collection_list.html | 2 +- ingest/views.py | 38 ++++++++++--------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/ingest/static/ingest/sendemail.js b/ingest/static/ingest/sendemail.js index 3b95259..9ba3fe5 100644 --- a/ingest/static/ingest/sendemail.js +++ b/ingest/static/ingest/sendemail.js @@ -6,10 +6,10 @@ function collection_send() { // $e is the tr element let row_is_checked = $e.find('#collection_is_checked').is(':checked'); // row_is_checked is a boolean of whether that row is checked or not - let bil_uuid = $e.find('#bil') + let bil_uuid = $e.find('#bilUuid') if(row_is_checked) output_rows.push({ - 'billUuid': bil_uuid + "bil_uuid": bil_uuid.text() } ) }); @@ -19,7 +19,7 @@ function collection_send() { body: JSON.stringify(output_rows), cache: "no-cache", headers: new Headers({ - "X-CSRFToken": "csrftoken", + "X-CSRFToken": csrftoken, "content-type": "application/json" }) }) diff --git a/ingest/templates/ingest/submit_request_collection_list.html b/ingest/templates/ingest/submit_request_collection_list.html index 5e45e87..3cb489a 100644 --- a/ingest/templates/ingest/submit_request_collection_list.html +++ b/ingest/templates/ingest/submit_request_collection_list.html @@ -43,9 +43,9 @@

Submit Request to Publicize Collection

{% endfor %} -
{{collection.validation_status}}
+
diff --git a/ingest/views.py b/ingest/views.py index a904912..1cbfead 100644 --- a/ingest/views.py +++ b/ingest/views.py @@ -6,6 +6,7 @@ from django.core.files.storage import FileSystemStorage from django.shortcuts import render, redirect from django.urls import reverse_lazy +from django.urls import reverse from django.views.generic import DetailView from django.views.generic.edit import UpdateView, DeleteView from django.core.cache import cache @@ -266,26 +267,27 @@ class ImageMetadataDelete(LoginRequiredMixin, DeleteView): @login_required def collection_send(request): - content = request.get_json() + content = json.loads(request.body) print(content) items = [] - #for item in content: - # items.append['bilUuid'] - # bilUuid = item['bilUuid'] - #if request.method == "POST": - # subject = '[BIL Validations] New Validation Request' - # sender = 'ltuite96@psc.edu' - # message = F'The following collections have been requested to be validated {items}' - # recipient = 'ltuite96@psc.edu' - - # send_mail( - # subject, - # message, - # sender, - # recipient - # ) - # print(message) - return redirect('index') + for item in content: + items.append(item['bil_uuid']) + + if request.method == "POST": + subject = '[BIL Validations] New Validation Request' + sender = 'ltuite96@psc.edu' + message = F'The following collections have been requested to be validated {items}' + recipient = ['ltuite96@psc.edu'] + + send_mail( + subject, + message, + sender, + recipient + ) + print(message) + #messages.success(request, 'Request succesfully sent') + return HttpResponse(json.dumps({'url': reverse('ingest:index')})) #return HttpResponse(status=200) #success_url = reverse_lazy('ingest:collection_list') From 3d5350a07587fc20fa7b0971f42254daaf2370b3 Mon Sep 17 00:00:00 2001 From: Luke Tuite Date: Mon, 15 Mar 2021 14:49:17 -0400 Subject: [PATCH 15/15] Submit Validation Request: styling done, email function updated (finished) --- bil_site/settings.py | 5 +++-- ingest/templates/ingest/submit_request_collection_list.html | 6 +++--- ingest/views.py | 6 ++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bil_site/settings.py b/bil_site/settings.py index eb876f1..fd06bb0 100644 --- a/bil_site/settings.py +++ b/bil_site/settings.py @@ -208,12 +208,13 @@ MESSAGE_TAGS = { messages.ERROR: 'danger' } + #Email Settings EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = '587' EMAIL_HOST_USER = 'ltuite96@psc.edu' -EMAIL_HOST_PASSWORD = '' +EMAIL_HOST_PASSWORD = 'qxcwnowpqqxwtsmc' EMAIL_USE_TLS = True EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' #EMAIL_USE_SSL = False -} \ No newline at end of file + diff --git a/ingest/templates/ingest/submit_request_collection_list.html b/ingest/templates/ingest/submit_request_collection_list.html index 3cb489a..e3a205e 100644 --- a/ingest/templates/ingest/submit_request_collection_list.html +++ b/ingest/templates/ingest/submit_request_collection_list.html @@ -6,12 +6,13 @@ {% load bootstrap4 %} {% block wide %}

Submit Request to Publicize Collection

- +

Select checkboxes for each collection to request validation and publication. This will submit a ticket to BIL support and be processed

{% csrf_token %} - +
+ @@ -28,7 +29,6 @@

Submit Request to Publicize Collection

{% for collection in collections %} - diff --git a/ingest/views.py b/ingest/views.py index 1cbfead..7c86d15 100644 --- a/ingest/views.py +++ b/ingest/views.py @@ -270,15 +270,16 @@ def collection_send(request): content = json.loads(request.body) print(content) items = [] + user_name = request.user for item in content: items.append(item['bil_uuid']) if request.method == "POST": subject = '[BIL Validations] New Validation Request' sender = 'ltuite96@psc.edu' - message = F'The following collections have been requested to be validated {items}' + message = F'The following collections have been requested to be validated {items} by {user_name}@psc.edu' recipient = ['ltuite96@psc.edu'] - + send_mail( subject, message, @@ -286,6 +287,7 @@ def collection_send(request): recipient ) print(message) + print(user_name) #messages.success(request, 'Request succesfully sent') return HttpResponse(json.dumps({'url': reverse('ingest:index')})) #return HttpResponse(status=200)
Name Description Organization Lab
{{ loop.index }} {{collection.name}} {{collection.description}}