Skip to content

Commit

Permalink
Merge pull request #70 from squirrelo/addstudy
Browse files Browse the repository at this point in the history
Study and StudyPerson object
  • Loading branch information
antgonza committed Jun 12, 2014
2 parents 3d16e6a + 4d74534 commit f80166b
Show file tree
Hide file tree
Showing 9 changed files with 1,035 additions and 90 deletions.
6 changes: 3 additions & 3 deletions qiita_db/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def status(self):
"{0}_id = %s)".format(self._table),
(self._id, ))[0]

def _status_setter_checks(self):
def _status_setter_checks(self, conn_handler):
r"""Perform any extra checks that needed to be done before setting the
object status on the database. Should be overwritten by the subclasses
"""
Expand All @@ -218,10 +218,10 @@ def status(self, status):
self._check_subclass()

# Perform any extra checks needed before we update the status in the DB
self._status_setter_checks()
conn_handler = SQLConnectionHandler()
self._status_setter_checks(conn_handler)

# Update the status of the object
conn_handler = SQLConnectionHandler()
conn_handler.execute(
"UPDATE qiita.{0} SET {0}_status_id = "
"(SELECT {0}_status_id FROM qiita.{0}_status WHERE status = %s) "
Expand Down
11 changes: 8 additions & 3 deletions qiita_db/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ class QiitaDBConnectionError(QiitaDBError):
pass


class QiitaDBColumnError(QiitaDBError):
"""Exception when missing table information or excess information passed"""
pass


class QiitaDBDuplicateError(QiitaDBError):
"""Exception when duplicating something in the database"""
pass


class QiitaDBColumnError(QiitaDBError):
"""Exception when database column info missing or incorrect"""
class QiitaDBStatusError(QiitaDBError):
"""Exception when editing is done with an unallowed status"""
pass


Expand All @@ -45,4 +50,4 @@ class QiitaDBUnknownIDError(QiitaDBError):
def __init__(self, missing_id, table):
super(QiitaDBUnknownIDError, self).__init__()
self.args = ("The object with ID '%s' does not exists in table '%s"
% (missing_id, table))
% (missing_id, table),)
14 changes: 14 additions & 0 deletions qiita_db/metadata_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ class MetadataTemplate(QiitaStatusObject):
# instantiate this base class
_table_prefix = None
_column_table = None
_id_column = None

def _check_id(self, id_, conn_handler=None):
# PLACEHOLDER SO TESTS PASS. Jose will rewrite for metadata pr
r""""""
self._check_subclass()
conn_handler = (conn_handler if conn_handler is not None
else SQLConnectionHandler())
return conn_handler.execute_fetchone(
"SELECT EXISTS(SELECT * FROM qiita.{0} WHERE "
"{1}=%s)".format(self._table, self._id_column),
(id_, ))[0]

@classmethod
def _get_table_name(cls, study_id):
Expand Down Expand Up @@ -262,8 +274,10 @@ def has_single_category_values(self, category):

class SampleTemplate(MetadataTemplate):
""""""
_table = "required_sample_info"
_table_prefix = "sample_"
_column_table = "study_sample_columns"
_id_column = "study_id"


class PrepTemplate(MetadataTemplate):
Expand Down

0 comments on commit f80166b

Please sign in to comment.