Skip to content

DataTables load using AJAX, Search by metadata on studies page #1006

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

Merged
merged 29 commits into from
Apr 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
616300f
add get_info to Studies object
squirrelo Mar 19, 2015
d595016
expand tests
squirrelo Mar 19, 2015
90313f7
use get_info in listing handler
squirrelo Mar 19, 2015
fb5eef3
condense view studies pages
squirrelo Mar 19, 2015
1ffd4bc
clean up naming, add form elements
squirrelo Mar 19, 2015
16257c4
load study tables through ajax
squirrelo Mar 19, 2015
9ccc098
add message for zero results
squirrelo Mar 19, 2015
abeb46f
add search and retrieve to page
squirrelo Mar 20, 2015
259bec2
fix bug in joins
squirrelo Mar 20, 2015
b8472a8
add full ajax search support
squirrelo Mar 20, 2015
cf6ca77
add error handling to datatables
squirrelo Mar 20, 2015
cd4f66e
alter/add tests for handlers to reflect changes
squirrelo Mar 20, 2015
ce4d334
fix tests
squirrelo Mar 20, 2015
58b28cd
implement Jess' suggestions
squirrelo Mar 21, 2015
1872555
Merge branch 'master' of https://github.com/biocore/qiita into cart
squirrelo Mar 22, 2015
4b7ffcf
remove unneeded format loop, format datatables better
squirrelo Mar 24, 2015
515f0f6
update tests
squirrelo Mar 24, 2015
21b17d6
Merge branch 'master' of https://github.com/biocore/qiita into cart
squirrelo Mar 24, 2015
04f87f4
specific ordering for PMIDs for testing
squirrelo Mar 24, 2015
ee4c9e2
flake8
squirrelo Mar 24, 2015
ef16d18
address issues
squirrelo Mar 26, 2015
fbe7c74
address comments
squirrelo Mar 26, 2015
e0f22d0
merge upstream/master
squirrelo Mar 27, 2015
0df6666
fix merge issues
squirrelo Mar 27, 2015
5085c35
more enhancements
squirrelo Mar 27, 2015
ea69fe8
address comments
squirrelo Mar 28, 2015
3a12f87
update tests
squirrelo Mar 28, 2015
25ae8f2
update schema and html files
squirrelo Mar 29, 2015
e01e224
fix search disabled and clearing table search
squirrelo Apr 1, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions qiita_db/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@
from __future__ import division
from future.utils import viewitems
from copy import deepcopy
from itertools import chain
import warnings

from qiita_core.exceptions import IncompetentQiitaDeveloperError
from .base import QiitaObject
from .exceptions import (QiitaDBStatusError, QiitaDBColumnError, QiitaDBError)
from .util import (check_required_columns, check_table_cols, convert_to_id,
get_environmental_packages, infer_status)
get_environmental_packages, get_table_cols, infer_status)
from .sql_connection import SQLConnectionHandler


Expand Down Expand Up @@ -142,7 +144,12 @@ class Study(QiitaObject):
"""
_table = "study"
# The following columns are considered not part of the study info
_non_info = {"email", "study_title"}
_non_info = frozenset(["email", "study_title"])
# The following tables are considered part of info
_info_cols = frozenset(chain(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of this information will change at runtime, right? If so, I think this could be cached in qiita_pet.__init__ and done once

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! nevermind, it is at the static scope of the object. it is done once

get_table_cols('study'), get_table_cols('study_status'),
get_table_cols('timeseries_type'), get_table_cols('portal_type'),
get_table_cols('study_pmid')))

def _lock_non_sandbox(self, conn_handler):
"""Raises QiitaDBStatusError if study is non-sandboxed"""
Expand Down Expand Up @@ -198,6 +205,45 @@ def get_by_status(cls, status):

return studies

@classmethod
def get_info(cls, study_ids=None, info_cols=None):
"""Returns study data for a set of study_ids

Parameters
----------
study_ids : list of ints, optional
Studies to get information for. Defauls to all studies
info_cols: list of str, optional
Information columns to retrieve. Defaults to all study data

Returns
-------
list of DictCursor
Table-like structure of metadata, one study per row. Can be
accessed as a list of dictionaries, keyed on column name.
"""
if info_cols is None:
info_cols = cls._info_cols
elif not cls._info_cols.issuperset(info_cols):
warnings.warn("Non-info columns passed: %s" % ", ".join(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a warning or an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A warning, as suggested by @adamrp.

set(info_cols) - cls._info_cols))

search_cols = ",".join(sorted(cls._info_cols.intersection(info_cols)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might raise a warning if the user requests information columns that are not in cls._info_cols, since right now it silently ignores them, which could lead to bugs if/when there are typos or misspellings


sql = """SELECT {0} FROM (
qiita.study
JOIN qiita.timeseries_type USING (timeseries_type_id)
JOIN qiita.portal_type USING (portal_type_id)
LEFT JOIN (SELECT study_id, array_agg(pmid ORDER BY pmid) as
pmid FROM qiita.study_pmid GROUP BY study_id) sp USING (study_id)
)""".format(search_cols)
if study_ids is not None:
sql = "{0} WHERE study_id in ({1})".format(
sql, ','.join(str(s) for s in study_ids))

conn_handler = SQLConnectionHandler()
return conn_handler.execute_fetchall(sql)

@classmethod
def exists(cls, study_title):
"""Check if a study exists based on study_title, which is unique
Expand Down
6 changes: 6 additions & 0 deletions qiita_db/support_files/patches/20.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- March 19, 2015
-- Rename columns to be more descriptive and allow easier joins
ALTER TABLE qiita.processed_data_status RENAME COLUMN description TO processed_data_status_description;
ALTER TABLE qiita.portal_type RENAME COLUMN description TO portal_description;
ALTER TABLE qiita.investigation RENAME COLUMN description TO investigation_description;
ALTER TABLE qiita.investigation RENAME COLUMN name TO investigation_name;
2 changes: 1 addition & 1 deletion qiita_db/support_files/populate_test_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ INSERT INTO qiita.study_users (study_id, email) VALUES (1, 'shared@foo.bar');
INSERT INTO qiita.study_pmid (study_id, pmid) VALUES (1, '123456'), (1, '7891011');

-- Insert an investigation
INSERT INTO qiita.investigation (name, description, contact_person_id) VALUES
INSERT INTO qiita.investigation (investigation_name, investigation_description, contact_person_id) VALUES
('TestInvestigation', 'An investigation for testing purposes', 3);

-- Insert investigation_study (link study 1 with investigation 1)
Expand Down
14 changes: 7 additions & 7 deletions qiita_db/support_files/qiita-db.dbs
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@
<table name="investigation" >
<comment>Overarching investigation information.An investigation comprises one or more individual studies.</comment>
<column name="investigation_id" type="bigserial" jt="-5" mandatory="y" />
<column name="name" type="varchar" jt="12" mandatory="y" />
<column name="description" type="varchar" jt="12" mandatory="y" >
<column name="investigation_name" type="varchar" jt="12" mandatory="y" />
<column name="investigation_description" type="varchar" jt="12" mandatory="y" >
<comment><![CDATA[Describes the overarching goal of the investigation]]></comment>
</column>
<column name="contact_person_id" type="bigint" jt="-5" />
Expand Down Expand Up @@ -682,7 +682,7 @@
<comment>What portals are available to show a study in</comment>
<column name="portal_type_id" type="bigserial" jt="-5" mandatory="y" />
<column name="portal" type="varchar" jt="12" mandatory="y" />
<column name="description" type="varchar" jt="12" mandatory="y" />
<column name="portal_description" type="varchar" jt="12" mandatory="y" />
<index name="pk_portal_type" unique="PRIMARY_KEY" >
<column name="portal_type_id" />
</index>
Expand Down Expand Up @@ -1000,7 +1000,7 @@
<table name="processed_data_status" >
<column name="processed_data_status_id" type="bigserial" jt="-5" mandatory="y" />
<column name="processed_data_status" type="varchar" jt="12" mandatory="y" />
<column name="description" type="varchar" jt="12" mandatory="y" />
<column name="processed_data_status_description" type="varchar" jt="12" mandatory="y" />
<index name="pk_study_status" unique="PRIMARY_KEY" >
<column name="processed_data_status_id" />
</index>
Expand Down Expand Up @@ -1565,7 +1565,6 @@ Controlled Vocabulary]]></comment>
<connector name="PostgreSQL" database="PostgreSQL" driver_class="org.postgresql.Driver" driver_jar="postgresql-9.2-1003.jdbc3.jar" host="localhost" port="5432" instance="qiita_test" user="mcdonadt" schema_mapping="" />
<layout id="Layout669806" name="qiita" show_relation_columns="y" >
<entity schema="qiita" name="controlled_vocab_values" color="d0def5" x="45" y="1545" />
<entity schema="qiita" name="investigation" color="c0d4f3" x="2100" y="255" />
<entity schema="qiita" name="investigation_study" color="c0d4f3" x="2100" y="405" />
<entity schema="qiita" name="job_results_filepath" color="c0d4f3" x="405" y="855" />
<entity schema="qiita" name="analysis_job" color="d0def5" x="285" y="930" />
Expand Down Expand Up @@ -1635,10 +1634,11 @@ Controlled Vocabulary]]></comment>
<entity schema="qiita" name="analysis" color="d0def5" x="225" y="720" />
<entity schema="qiita" name="study_experimental_factor" color="c0d4f3" x="2100" y="495" />
<entity schema="qiita" name="study_pmid" color="c0d4f3" x="2145" y="600" />
<entity schema="qiita" name="portal_type" color="c0d4f3" x="1995" y="660" />
<entity schema="qiita" name="study" color="d0def5" x="1815" y="60" />
<entity schema="qiita" name="processed_data" color="d0def5" x="1275" y="960" />
<entity schema="qiita" name="processed_data_status" color="c0d4f3" x="1530" y="1050" />
<entity schema="qiita" name="investigation" color="c0d4f3" x="2100" y="255" />
<entity schema="qiita" name="processed_data_status" color="c0d4f3" x="1500" y="1050" />
<entity schema="qiita" name="portal_type" color="c0d4f3" x="1995" y="660" />
<group name="Group_analyses" color="c4e0f9" >
<comment>analysis tables</comment>
<entity schema="qiita" name="analysis" />
Expand Down
Loading