-
Couldn't load subscription status.
- Fork 79
database changes to fix 969 #2071
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -464,6 +464,42 @@ def delete(cls, id_): | |
|
|
||
| qdb.sql_connection.TRN.execute() | ||
|
|
||
| @classmethod | ||
| def get_tags(cls): | ||
| """Returns the available study tags | ||
|
|
||
| Returns | ||
| ------- | ||
| list of DictCursor | ||
| Table-like structure of metadata, one tag per row. Can be | ||
| accessed as a list of dictionaries, keyed on column name. | ||
| """ | ||
| with qdb.sql_connection.TRN: | ||
| sql = """SELECT study_tag_id, study_tag | ||
| FROM qiita.study_tags""" | ||
|
|
||
| qdb.sql_connection.TRN.add(sql) | ||
| return qdb.sql_connection.TRN.execute_fetchindex() | ||
|
|
||
| @classmethod | ||
| def insert_tags(cls, user, tags): | ||
| """Insert available study tags | ||
|
|
||
| Parameters | ||
| ---------- | ||
| user : qiita_db.user.User | ||
| The user adding the tags | ||
| tags : list of str | ||
| The list of tags to add | ||
| """ | ||
| with qdb.sql_connection.TRN: | ||
| sql = """INSERT INTO qiita.study_tags (email, study_tag) | ||
| VALUES (%s, %s)""" | ||
| sql_args = [[user.email, tag] for tag in tags] | ||
|
|
||
| qdb.sql_connection.TRN.add(sql, sql_args, many=True) | ||
| qdb.sql_connection.TRN.execute() | ||
|
|
||
|
|
||
| # --- Attributes --- | ||
| @property | ||
|
|
@@ -921,7 +957,52 @@ def ebi_submission_status(self, value): | |
|
|
||
| ebi_submission_status.__doc__.format(', '.join(_VALID_EBI_STATUS)) | ||
|
|
||
| # --- methods --- | ||
| @property | ||
| def tags(self): | ||
| """Returns the tags of the study | ||
|
|
||
| Returns | ||
| ------- | ||
| list of str | ||
| The study tags | ||
| """ | ||
| with qdb.sql_connection.TRN: | ||
| sql = """SELECT study_tag_id, study_tag | ||
| FROM qiita.study_tags | ||
| LEFT JOIN qiita.per_study_tags USING (study_tag_id) | ||
| WHERE study_id = {0}""".format(self._id) | ||
| qdb.sql_connection.TRN.add(sql) | ||
| return qdb.sql_connection.TRN.execute_fetchindex() | ||
|
|
||
| @tags.setter | ||
| def tags(self, tag_ids): | ||
|
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. This is not setting the tags correctly. If a tag has been removed from the list it doesn't get removed from the DB. Would it be more useful to add a couple of functions |
||
| """Sets the tags of the study | ||
|
|
||
| Parameters | ||
| ---------- | ||
| tag_ids : list of int | ||
|
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 we provide the list of tags rather than the list of tag ids? We have been removing the exposure of DB ids for these types of thins as much as we could, so I would like not to re-add some of them back 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. 👍 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 FYI: We (@josenavas and me) decided via offline chat that it was fine to leave as is because that way we can link the ids in the templates and the text can be escaped in the templates, which makes our live easier. |
||
| The tag ids of the study | ||
| """ | ||
| with qdb.sql_connection.TRN: | ||
| sql = """DELETE FROM qiita.per_study_tags WHERE study_id = %s""" | ||
| qdb.sql_connection.TRN.add(sql, [self._id]) | ||
|
|
||
| if tag_ids: | ||
| sql = """INSERT INTO qiita.per_study_tags | ||
| (study_tag_id, study_id) | ||
| SELECT %s, %s | ||
| WHERE | ||
| NOT EXISTS ( | ||
| SELECT study_tag_id, study_id | ||
| FROM qiita.per_study_tags | ||
| WHERE study_tag_id = %s AND study_id = %s | ||
| )""" | ||
| sql_args = [[tid, self._id, tid, self._id] for tid in tag_ids] | ||
| qdb.sql_connection.TRN.add(sql, sql_args, many=True) | ||
|
|
||
| qdb.sql_connection.TRN.execute() | ||
|
|
||
| # --- methods --- | ||
| def artifacts(self, dtype=None, artifact_type=None): | ||
| """Returns the list of artifacts associated with the study | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| -- Feb 3, 2017 | ||
| -- adding study tagging system | ||
|
|
||
| CREATE TABLE qiita.study_tags ( | ||
| study_tag_id bigserial NOT NULL, | ||
| email varchar NOT NULL, | ||
| study_tag varchar NOT NULL, | ||
|
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/should we guarantee unique tags? 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. yes, 1 line below: |
||
| CONSTRAINT pk_study_tag UNIQUE ( study_tag ), | ||
| CONSTRAINT pk_study_tag_id PRIMARY KEY ( study_tag_id ) | ||
| ) ; | ||
|
|
||
| CREATE INDEX idx_study_tag_id ON qiita.study_tags ( study_tag_id ) ; | ||
| ALTER TABLE qiita.study_tags ADD CONSTRAINT fk_study_tags FOREIGN KEY ( email ) REFERENCES qiita.qiita_user( email ); | ||
|
|
||
| CREATE TABLE qiita.per_study_tags ( | ||
| study_tag_id bigint NOT NULL, | ||
| study_id bigint NOT NULL, | ||
| CONSTRAINT pk_per_study_tags PRIMARY KEY ( study_tag_id, study_id ) | ||
| ) ; | ||
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.
Just return the "study_tag" (not the id)