-
Notifications
You must be signed in to change notification settings - Fork 79
Delete study #1068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete study #1068
Changes from all commits
00b317e
62ccfcc
fca7aaa
910b7cb
45e267d
1f96f2e
aa171c6
09e3cf3
23d133e
a6bb7ab
e958282
ac20386
2d4c258
803299f
53b5b93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,6 +107,7 @@ | |
| from .util import (check_required_columns, check_table_cols, convert_to_id, | ||
| get_environmental_packages, get_table_cols, infer_status) | ||
| from .sql_connection import SQLConnectionHandler | ||
| from .util import exists_table | ||
|
|
||
|
|
||
| class Study(QiitaObject): | ||
|
|
@@ -347,6 +348,68 @@ def create(cls, owner, title, efo, info, investigation=None): | |
|
|
||
| return cls(study_id) | ||
|
|
||
| @classmethod | ||
| def delete(cls, id_): | ||
| r"""Deletes the study from the database | ||
|
|
||
| Parameters | ||
| ---------- | ||
| id_ : integer | ||
| The object identifier | ||
|
|
||
| Raises | ||
| ------ | ||
| QiitaDBError | ||
| If the sample_(id_) table exists means a sample template exists | ||
| """ | ||
| cls._check_subclass() | ||
|
|
||
| # checking that the id_ exists | ||
| cls(id_) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to confirm, what you are asking is for me to solve
#1078 within this PR and use
that function?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, but you are only instantiating the object to check if the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| conn_handler = SQLConnectionHandler() | ||
| if exists_table('sample_%d' % id_, conn_handler): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A question about the future. Is a user going to be able to add raw data, preprocessed data or processed data (otu tables) w/o a sample template? If so, we should check if the study has something else...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way it works right now is that you need a raw data to have a preprocessed data, a preprocessed data to have a processed data, which I think is fine and give us the possibility of "play" with the options. For example, when we allow to upload a process data we can link it to the same default raw data for faster searches. |
||
| raise QiitaDBError('Study "%s" cannot be erased because it has a ' | ||
| 'sample template' % cls(id_).title) | ||
|
|
||
| queue = "delete_study_%d" % id_ | ||
| conn_handler.create_queue(queue) | ||
|
|
||
| conn_handler.add_to_queue( | ||
| queue, | ||
| "DELETE FROM qiita.study_sample_columns WHERE study_id = %s", | ||
| (id_, )) | ||
|
|
||
| conn_handler.add_to_queue( | ||
| queue, | ||
| "DELETE FROM qiita.study_experimental_factor WHERE study_id = %s", | ||
| (id_, )) | ||
|
|
||
| conn_handler.add_to_queue( | ||
| queue, | ||
| "DELETE FROM qiita.study_pmid WHERE study_id = %s", (id_, )) | ||
|
|
||
| conn_handler.add_to_queue( | ||
| queue, | ||
| "DELETE FROM qiita.study_environmental_package WHERE study_id = " | ||
| "%s", (id_, )) | ||
|
|
||
| conn_handler.add_to_queue( | ||
| queue, | ||
| "DELETE FROM qiita.study_users WHERE study_id = %s", (id_, )) | ||
|
|
||
| conn_handler.add_to_queue( | ||
| queue, | ||
| "DELETE FROM qiita.investigation_study WHERE study_id = " | ||
| "%s", (id_, )) | ||
|
|
||
| conn_handler.add_to_queue( | ||
| queue, | ||
| "DELETE FROM qiita.study WHERE study_id = %s", (id_, )) | ||
|
|
||
| conn_handler.execute_queue(queue) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm surprised that this is actually working. It should fail since you are not removing the row from the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added #1079
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding the issue. However you still should remove those rows here, otherwise the DB is going to be in an inconsistent state. |
||
|
|
||
|
|
||
| # --- Attributes --- | ||
| @property | ||
| def title(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,6 +184,36 @@ | |
| form.submit(); | ||
| } | ||
|
|
||
| function validate_delete_study_text() { | ||
| if ($("#study-alias").val() == "{{study_alias}}") { | ||
| $('#delete-study-button').prop('disabled', false); | ||
| } else { | ||
| $('#delete-study-button').prop('disabled', true); | ||
| } | ||
| } | ||
|
|
||
| function delete_study() { | ||
| if ($("#study-alias").val() != "{{study_alias}}") { | ||
| alert("The added name doesn't match the study alias"); | ||
| return false; | ||
| } | ||
| if (confirm('Are you sure you want to delete "{{study_title}}"?')) { | ||
| var form = $("<form>") | ||
| .attr("action", window.location.href) | ||
| .attr("method", "post") | ||
| .append($("<input>") | ||
| .attr("type", "hidden") | ||
| .attr("name", "study_id") | ||
| .attr("value", {{study.id}})) | ||
| .append($("<input>") | ||
| .attr("type", "hidden") | ||
| .attr("name", "action") | ||
| .attr("value", "delete_study")); | ||
| $("body").append(form); | ||
| form.submit(); | ||
| } | ||
| } | ||
|
|
||
| function delete_sample_template() { | ||
| sample_template_id = {{study.sample_template}}; | ||
| if (confirm('Are you sure you want to delete sample template ID: ' + sample_template_id + '?')) { | ||
|
|
@@ -548,6 +578,7 @@ <h2><i>{{study_alias}}</i></h2> | |
| <a class="btn btn-default glyphicon glyphicon-edit" href="/study/edit/{{study.id}}" title="Edit the study information" style="margin:5px; word-spacing: -10px;"> Edit</a> | ||
| {% end %} | ||
| <a href="/study/upload/{{study.id}}" class="btn btn-default glyphicon glyphicon-upload" title="Upload study files" style="margin:5px; word-spacing: -10px;"> Upload</a> | ||
| <a class="btn btn-danger glyphicon glyphicon-trash" style="display: inline-block;" data-toggle="modal" data-target="#delete-study"> Delete-study</a> | ||
| </td> | ||
| </tr> | ||
| </table> | ||
|
|
@@ -580,4 +611,24 @@ <h2><i>{{study_alias}}</i></h2> | |
| {% end %} | ||
| </div> | ||
|
|
||
|
|
||
| <div class="modal fade delete-study" tabindex="-1" role="dialog" id="delete-study"> | ||
| <div class="modal-dialog modal-sm"> | ||
| <div class="modal-content"> | ||
| <div class="modal-header"> | ||
| <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> | ||
| <h3>Deleting:<br/></h3><h4>{{study_title}}</h4> | ||
| </div> | ||
| <div class="modal-body"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And if you follow the comment above, this should be moved to the "modal-footer" section.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested your 2 suggestions and I do not like them. |
||
| You will only be able to delete a study that has no data associated with it. | ||
| </div> | ||
| <div class="modal-footer"> | ||
| To continue you need to write the alias name of the study: | ||
| <input type="text" name="study-alias" id="study-alias" onkeyup="validate_delete_study_text();"> | ||
| <button class="btn btn-danger glyphicon glyphicon-trash" onclick="delete_study();" id="delete-study-button" disabled></button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| {% end %} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check if the study with id 'id_' exists.
Off topic: This is another reason why I think
deleteshould be an instance method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1078. For the time being, I added a instantiation of
Study(id_)to validate this case and a test just to be sure.