From 1e3a80239fe1e35f4f4d19bf2babb458814d9146 Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Mon, 13 Apr 2015 09:45:30 -0600 Subject: [PATCH 1/8] delete sample template --- .../base_metadata_template.py | 29 ++++++++++++++----- .../study_handlers/description_handlers.py | 28 ++++++++++++++++++ qiita_pet/templates/study_description.html | 25 +++++++++++++++- .../study_information_tab.html | 2 ++ 4 files changed, 76 insertions(+), 8 deletions(-) diff --git a/qiita_db/metadata_template/base_metadata_template.py b/qiita_db/metadata_template/base_metadata_template.py index 2a105a1f2..7c1715a53 100644 --- a/qiita_db/metadata_template/base_metadata_template.py +++ b/qiita_db/metadata_template/base_metadata_template.py @@ -761,21 +761,36 @@ def delete(cls, id_): conn_handler = SQLConnectionHandler() # Delete the sample template filepaths - conn_handler.execute( - "DELETE FROM qiita.sample_template_filepath WHERE " - "study_id = %s", (id_, )) + queue = "delete_sample_template_%d" % id_ + conn_handler.create_queue(queue) - conn_handler.execute( - "DROP TABLE qiita.{0}".format(table_name)) - conn_handler.execute( + conn_handler.add_to_queue( + queue, + "DELETE FROM qiita.sample_template_filepath WHERE study_id = %s", + (id_, )) + + conn_handler.add_to_queue( + queue, + "DROP TABLE IF EXISTS qiita.{0}".format(table_name)) + + conn_handler.add_to_queue( + queue, + "DROP TABLE IF EXISTS qiita.{0}".format(table_name)) + + conn_handler.add_to_queue( + queue, "DELETE FROM qiita.{0} where {1} = %s".format(cls._table, cls._id_column), (id_,)) - conn_handler.execute( + + conn_handler.add_to_queue( + queue, "DELETE FROM qiita.{0} where {1} = %s".format(cls._column_table, cls._id_column), (id_,)) + conn_handler.execute_queue(queue) + @classmethod def exists(cls, obj_id): r"""Checks if already exists a MetadataTemplate for the provided object diff --git a/qiita_pet/handlers/study_handlers/description_handlers.py b/qiita_pet/handlers/study_handlers/description_handlers.py index 7ff8bc182..f220c162a 100644 --- a/qiita_pet/handlers/study_handlers/description_handlers.py +++ b/qiita_pet/handlers/study_handlers/description_handlers.py @@ -640,6 +640,33 @@ def display_template(self, study, user, msg, msg_level, full_access, sub_tab=sub_tab, prep_tab=prep_tab) + def delete_sample_template(self, study, user, callback): + """Delete sample template + + Parameters + ---------- + study : Study + The current study object + user : User + The current user object + callback : function + The callback function to call with the results once the processing + is done + """ + sample_template_id = int(self.get_argument('sample_template_id')) + + try: + SampleTemplate.delete(sample_template_id) + msg = ("Sample template %d has been deleted from study: " + "%s" % (sample_template_id, study.title)) + msg_level = "success" + except Exception as e: + msg = "Couldn't remove %d raw data: %s" % (sample_template_id, + str(e)) + msg_level = "danger" + + callback((msg, msg_level, 'study_information_tab', None, None)) + def delete_raw_data(self, study, user, callback): """Delete the selected raw data @@ -781,6 +808,7 @@ def post(self, study_id): request_approval=self.request_approval, make_sandbox=self.make_sandbox, update_investigation_type=self.update_investigation_type, + delete_sample_template=self.delete_sample_template, delete_raw_data=self.delete_raw_data, delete_prep_template=self.delete_prep_template, delete_preprocessed_data=self.delete_preprocessed_data, diff --git a/qiita_pet/templates/study_description.html b/qiita_pet/templates/study_description.html index d1a88d773..7267feb7c 100644 --- a/qiita_pet/templates/study_description.html +++ b/qiita_pet/templates/study_description.html @@ -184,6 +184,24 @@ form.submit(); } +function delete_sample_template(sample_template_id) { + if (confirm('Are you sure you want to delete sample template ID: ' + sample_template_id + '?')) { + var form = $("
") + .attr("action", window.location.href) + .attr("method", "post") + .append($("") + .attr("type", "hidden") + .attr("name", "sample_template_id") + .attr("value", sample_template_id)) + .append($("") + .attr("type", "hidden") + .attr("name", "action") + .attr("value", "delete_sample_template")); + $("body").append(form); + form.submit(); + } +} + function delete_raw_data(raw_data_filetype, raw_data_id) { if (confirm('Are you sure you want to delete raw data: ' + raw_data_filetype + ' (ID: ' + raw_data_id + ')?')) { var form = $("") @@ -537,7 +555,12 @@

{{study_alias}}