diff --git a/extension/toar_controlled_vocabulary-0.1/toar_controlled_vocabulary--0.1.sql b/extension/toar_controlled_vocabulary-0.1/toar_controlled_vocabulary--0.1.sql index 7c955595996d35a2828c2b3d069b0a9b259128ee..22515c65163f3a095a024bd668f018d861692cd0 100644 --- a/extension/toar_controlled_vocabulary-0.1/toar_controlled_vocabulary--0.1.sql +++ b/extension/toar_controlled_vocabulary-0.1/toar_controlled_vocabulary--0.1.sql @@ -47,6 +47,26 @@ INSERT INTO RS_vocabulary (enum_val, enum_str, enum_display_str) VALUES (1, 'inactive', 'inactive'), (2, 'unknown', 'unknown'); + +-- Annotation +-- ========== + +-- Kind of Annotation + +CREATE TABLE IF NOT EXISTS AK_vocabulary ( + enum_val INT NOT NULL, + enum_str character varying(128) NOT NULL, + enum_display_str character varying(128) NOT NULL, + PRIMARY KEY(enum_val, enum_str), + CONSTRAINT ak_enum_val_unique UNIQUE (enum_val) +); + +INSERT INTO AK_vocabulary (enum_val, enum_str, enum_display_str) VALUES + (0, 'User', 'user comment'), + (1, 'Provider', 'provider comment'); + + + -- Contacts -- ======== diff --git a/toardb/generic/models.py b/toardb/generic/models.py index ad6af6b31157305fc1981556dba295a99663ef66..6222dffbdee9456015cb2430f6bbb07103bea4c7 100644 --- a/toardb/generic/models.py +++ b/toardb/generic/models.py @@ -5,6 +5,8 @@ from toardb.base import Base # controlled vocabulary +## Roles + # Role Status RS_enum_table = Table("rs_vocabulary", Base.metadata, @@ -58,3 +60,20 @@ CL_enum = ( Enumdict(6, 'Flagging', 'data value flagging') ) +## Annotations + +# Kind of Annotations +AK_enum_table = Table("ak_vocabulary", + Base.metadata, + Column("enum_val", Integer, primary_key=True), + Column("enum_str", String), + Column("enum_display_str", String) + ) +# The following code is just a workaround (see stationmeta/models.py): +from collections import namedtuple +Enumdict=namedtuple("Dict",["value","string","display_str"]) +AK_enum = ( + Enumdict(0, 'User', 'user comment'), + Enumdict(1, 'Provider', 'provider comment') + ) + diff --git a/toardb/stationmeta/models_annotation.py b/toardb/stationmeta/models_annotation.py index 2a7fb421586c04d0e2a3b6e40f0ff4f21666bba4..45bb9f355b13fb12b14509d9ad37aa4c793e8205 100644 --- a/toardb/stationmeta/models_annotation.py +++ b/toardb/stationmeta/models_annotation.py @@ -4,7 +4,7 @@ class StationmetaAnnotation (Base) ================================== """ from sqlalchemy import Column, DateTime, Float, ForeignKey, Integer, String, \ - Text, Boolean, CheckConstraint, Table, Sequence + Text, Boolean, CheckConstraint, Table, Sequence, text from sqlalchemy.orm import relationship from toardb.auth_user.models import AuthUser from toardb.base import Base @@ -26,7 +26,7 @@ class StationmetaAnnotation(Base): +================+==========================+===========+==========+========================================================+ | id | integer | | not null | nextval('stationmeta_annotations_id_seq'::regclass) | +----------------+--------------------------+-----------+----------+--------------------------------------------------------+ - | kind | integer | | not null | | + | kind | integer | | not null | 0 | +----------------+--------------------------+-----------+----------+--------------------------------------------------------+ | text | text | | not null | | +----------------+--------------------------+-----------+----------+--------------------------------------------------------+ @@ -43,6 +43,7 @@ class StationmetaAnnotation(Base): "stationmeta_annotations_kind_check" CHECK (kind >= 0) Foreign-key constraints: "stationmeta_annotations_contributor_id_a5009820_fk_auth_user_id" FOREIGN KEY (contributor_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED + "stationmeta_annotations_kind_fk_ak_vocabulary_enum_val" FOREIGN KEY (kind) REFERENCES ak_vocabulary(enum_val) """ __tablename__ = 'stationmeta_annotations' __table_args__ = ( @@ -50,7 +51,7 @@ class StationmetaAnnotation(Base): ) id = Column(Integer, STATIONMETA_ANNOTATIONS_ID_SEQ, primary_key=True, server_default=STATIONMETA_ANNOTATIONS_ID_SEQ.next_value()) - kind = Column(Integer, nullable=False) + kind = Column(ForeignKey('ak_vocabulary.enum_val'), nullable=False, server_default=text("0'::integer")) text = Column(Text, nullable=False) date_added = Column(DateTime(True), nullable=False) approved = Column(Boolean, nullable=False)