From 2c170793e9d7e1c61910c908b97eaf1f3cb4de11 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 6 Mar 2021 15:17:10 +0100 Subject: add project type --- animism-align/cli/app/sql/models/annotation.py | 4 ++- animism-align/cli/app/sql/models/episode.py | 2 ++ animism-align/cli/app/sql/models/media.py | 2 ++ animism-align/cli/app/sql/models/project.py | 32 ++++++++++++++++++++ animism-align/cli/app/sql/models/venue.py | 2 ++ ...202103061516_add_projects_and_related_fields.py | 35 ++++++++++++++++++++++ animism-align/cli/commands/site/export.py | 1 + 7 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 animism-align/cli/app/sql/models/project.py create mode 100644 animism-align/cli/app/sql/versions/202103061516_add_projects_and_related_fields.py (limited to 'animism-align/cli') diff --git a/animism-align/cli/app/sql/models/annotation.py b/animism-align/cli/app/sql/models/annotation.py index 7363d16..750267a 100644 --- a/animism-align/cli/app/sql/models/annotation.py +++ b/animism-align/cli/app/sql/models/annotation.py @@ -13,6 +13,7 @@ class Annotation(Base): """Table for storing references to annotations""" __tablename__ = 'annotation' id = Column(Integer, primary_key=True) + episode_id = Column(Integer) type = Column(String(16, convert_unicode=True), nullable=False) paragraph_id = Column(Integer, nullable=True) start_ts = Column(Float, nullable=False) @@ -23,8 +24,9 @@ class Annotation(Base): def toJSON(self): return { 'id': self.id, - 'type': self.type, + 'episode_id': self.episode_id, 'paragraph_id': self.paragraph_id, + 'type': self.type, 'start_ts': self.start_ts, 'end_ts': self.end_ts, 'text': self.text, diff --git a/animism-align/cli/app/sql/models/episode.py b/animism-align/cli/app/sql/models/episode.py index 60c94ed..916c5dc 100644 --- a/animism-align/cli/app/sql/models/episode.py +++ b/animism-align/cli/app/sql/models/episode.py @@ -16,6 +16,7 @@ class Episode(Base): title = Column(String(256, convert_unicode=True), nullable=False) release_date = Column(String(256, convert_unicode=True)) is_live = Column(Boolean, default=False) + show_venues = Column(Boolean, default=False) settings = Column(JSON, default={}, nullable=True) def toJSON(self): @@ -25,6 +26,7 @@ class Episode(Base): 'title': self.title, 'release_date': self.release_date, 'is_live': self.is_live, + 'show_venues': self.show_venues, 'settings': self.settings, } diff --git a/animism-align/cli/app/sql/models/media.py b/animism-align/cli/app/sql/models/media.py index 4628f4d..ae16255 100644 --- a/animism-align/cli/app/sql/models/media.py +++ b/animism-align/cli/app/sql/models/media.py @@ -12,6 +12,7 @@ class Media(Base): """Table for storing references to media""" __tablename__ = 'media' id = Column(Integer, primary_key=True) + episode_id = Column(Integer) type = Column(String(16, convert_unicode=True), nullable=False) tag = Column(String(64, convert_unicode=True), nullable=True) url = Column(String(256, convert_unicode=True), nullable=True) @@ -30,6 +31,7 @@ class Media(Base): def toJSON(self): return { 'id': self.id, + 'episode_id': self.episode_id, 'type': self.type, 'tag': self.tag, 'url': self.url, diff --git a/animism-align/cli/app/sql/models/project.py b/animism-align/cli/app/sql/models/project.py new file mode 100644 index 0000000..eb94fd6 --- /dev/null +++ b/animism-align/cli/app/sql/models/project.py @@ -0,0 +1,32 @@ +from sqlalchemy import create_engine, Table, Column, Text, String, Integer, Boolean, Float, DateTime, JSON, ForeignKey +from sqlalchemy.orm import relationship +import sqlalchemy.sql.functions as func +from sqlalchemy_utc import UtcDateTime, utcnow +from wtforms_alchemy import ModelForm + +from app.sql.common import db, Base, Session + +from app.settings import app_cfg + +class Project(Base): + """Table for storing projects and their metadata""" + __tablename__ = 'project' + id = Column(Integer, primary_key=True) + title = Column(String(256, convert_unicode=True), nullable=False) + is_live = Column(Boolean, default=False) + settings = Column(JSON, default={}, nullable=True) + + def toJSON(self): + return { + 'id': self.id, + 'title': self.title, + 'is_live': self.is_live, + 'settings': self.settings, + } + +class ProjectForm(ModelForm): + class Meta: + model = Episode + exclude = ['settings'] + def get_session(): + return Session() diff --git a/animism-align/cli/app/sql/models/venue.py b/animism-align/cli/app/sql/models/venue.py index 74a928c..e9d3015 100644 --- a/animism-align/cli/app/sql/models/venue.py +++ b/animism-align/cli/app/sql/models/venue.py @@ -12,6 +12,7 @@ class Venue(Base): """Table for storing the venue list""" __tablename__ = 'venue' id = Column(Integer, primary_key=True) + project_id = Column(Integer) title = Column(String(256, convert_unicode=True), nullable=False) date = Column(String(256, convert_unicode=True), nullable=False) settings = Column(JSON, default={}, nullable=True) @@ -19,6 +20,7 @@ class Venue(Base): def toJSON(self): return { 'id': self.id, + 'project_id': self.project_id, 'title': self.title, 'date': self.date, 'settings': self.settings, diff --git a/animism-align/cli/app/sql/versions/202103061516_add_projects_and_related_fields.py b/animism-align/cli/app/sql/versions/202103061516_add_projects_and_related_fields.py new file mode 100644 index 0000000..021ed2f --- /dev/null +++ b/animism-align/cli/app/sql/versions/202103061516_add_projects_and_related_fields.py @@ -0,0 +1,35 @@ +"""add projects and related fields + +Revision ID: 8c3c66f68ce2 +Revises: 135ba3ff136a +Create Date: 2021-03-06 15:16:47.345002 + +""" +from alembic import op +import sqlalchemy as sa +import sqlalchemy_utc + + +# revision identifiers, used by Alembic. +revision = '8c3c66f68ce2' +down_revision = '135ba3ff136a' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('annotation', sa.Column('episode_id', sa.Integer(), nullable=True)) + op.add_column('episode', sa.Column('show_venues', sa.Boolean(), nullable=True)) + op.add_column('media', sa.Column('episode_id', sa.Integer(), nullable=True)) + op.add_column('venue', sa.Column('project_id', sa.Integer(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('venue', 'project_id') + op.drop_column('media', 'episode_id') + op.drop_column('episode', 'show_venues') + op.drop_column('annotation', 'episode_id') + # ### end Alembic commands ### diff --git a/animism-align/cli/commands/site/export.py b/animism-align/cli/commands/site/export.py index d706a55..41e41ed 100644 --- a/animism-align/cli/commands/site/export.py +++ b/animism-align/cli/commands/site/export.py @@ -80,6 +80,7 @@ def cli(ctx, opt_output_dir, opt_sync, opt_js): index_html = index_html.replace('PAGE_TITLE', page_title) index_html = index_html.replace('PAGE_DESCRIPTION', page_desc) index_html = index_html.replace('PAGE_SHARE_IMAGE', page_image) + index_html = index_html.replace('PAGE_SHARE_URL', site_url + "/") index_html = index_html.replace('PLAIN_CONTENT', plain_content(db, site_title)) index_html = index_html.replace('BUNDLE_PATH', join(page_url, 'bundle.js')) write_text(index_html, join(site_fp_out, 'index.html')) -- cgit v1.2.3-70-g09d2