Skip to content

Commit

Permalink
Update annotation model to have JSON Metadata field (apache#5745)
Browse files Browse the repository at this point in the history
* add column to annotation model

* update migration file

* change to Text

* remove old migration file

* add migration file

* remove JSON

* add new column to view

* add comma back

* linting

* lint some more

* missing comma

* rename columns

* add degrade and new migration file

* update version

* fixe changed name

* remove json from list columns

(cherry picked from commit 5e3f833)
  • Loading branch information
hughhhh authored and youngyjd committed Oct 17, 2018
1 parent a4b4212 commit 2efb4e3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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

0 comments on commit 2efb4e3

Please sign in to comment.