Skip to content
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

Update annotation model to have JSON Metadata field #5745

Merged
merged 16 commits into from
Aug 31, 2018
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""add_metadata_column_to_annotation_model.py

Revision ID: 55e910a74826
Revises: 1a1d627ebd8e
Create Date: 2018-08-29 14:35:20.407743

"""

# revision identifiers, used by Alembic.
revision = '55e910a74826'
down_revision = '1a1d627ebd8e'

from alembic import op
import sqlalchemy as sa


def upgrade():
op.add_column('annotation', sa.Column('json_metadata', sa.Text(), nullable=True))


def downgrade():
op.drop_column('annotation', 'json_metadata')
1 change: 1 addition & 0 deletions superset/models/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Annotation(Model, AuditMixinNullable):
layer = relationship(
AnnotationLayer,
backref='annotation')
json_metadata = Column(Text)

__table_args__ = (
Index('ti_dag_state', layer_id, start_dttm, end_dttm),
Expand Down
10 changes: 9 additions & 1 deletion superset/views/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class AnnotationModelView(SupersetModelView, DeleteMixin): # noqa

list_columns = ['layer', 'short_descr', 'start_dttm', 'end_dttm']
edit_columns = [
'layer', 'short_descr', 'long_descr', 'start_dttm', 'end_dttm']
'layer', 'short_descr', 'long_descr', 'start_dttm', 'end_dttm',
'json_metadata']

add_columns = edit_columns

label_columns = {
Expand All @@ -33,6 +35,12 @@ class AnnotationModelView(SupersetModelView, DeleteMixin): # noqa
'start_dttm': _('Start Dttm'),
'end_dttm': _('End Dttm'),
'long_descr': _('Long Descr'),
'json_metadata': _('JSON Metadata'),
}

description_columns = {
'json_metadata': 'This JSON represents any additional metadata this \
annotation needs to add more context.',
}

def pre_add(self, obj):
Expand Down