diff --git a/app/models.py b/app/models.py index 3c0530ad..9d900802 100644 --- a/app/models.py +++ b/app/models.py @@ -225,6 +225,11 @@ class Tag(db.Model): banned = db.Column(db.Boolean, default=False, index=True) +class Licence(db.Model): + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String(50)) + + class Language(db.Model): id = db.Column(db.Integer, primary_key=True) code = db.Column(db.String(5), index=True) @@ -1073,6 +1078,7 @@ class Post(db.Model): image_id = db.Column(db.Integer, db.ForeignKey('file.id'), index=True) domain_id = db.Column(db.Integer, db.ForeignKey('domain.id'), index=True) instance_id = db.Column(db.Integer, db.ForeignKey('instance.id'), index=True) + licence_id = db.Column(db.Integer, db.ForeignKey('licence.id'), index=True) slug = db.Column(db.String(255)) title = db.Column(db.String(255)) url = db.Column(db.String(2048)) @@ -1118,6 +1124,7 @@ class Post(db.Model): community = db.relationship('Community', lazy='joined', overlaps='posts', foreign_keys=[community_id]) replies = db.relationship('PostReply', lazy='dynamic', backref='post') language = db.relationship('Language', foreign_keys=[language_id]) + licence = db.relationship('Licence', foreign_keys=[language_id], lazy='dynamic') # db relationship tracked by the "read_posts" table # this is the Post side, so its referencing the User side diff --git a/app/post/routes.py b/app/post/routes.py index 1295a43f..ab9bacf5 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -111,7 +111,7 @@ def show_post(post_id: int): 'name': reply.language_name() }, 'contentMap': { - 'en': reply.body_html + reply.language_code(): reply.body_html } } create_json = { diff --git a/migrations/versions/e23ce3d53def_post_licence.py b/migrations/versions/e23ce3d53def_post_licence.py new file mode 100644 index 00000000..d8a34d66 --- /dev/null +++ b/migrations/versions/e23ce3d53def_post_licence.py @@ -0,0 +1,42 @@ +"""post licence + +Revision ID: e23ce3d53def +Revises: 7fc066ad475a +Create Date: 2024-11-02 15:12:05.885114 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'e23ce3d53def' +down_revision = '7fc066ad475a' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('licence', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('name', sa.String(length=50), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + with op.batch_alter_table('post', schema=None) as batch_op: + batch_op.add_column(sa.Column('licence_id', sa.Integer(), nullable=True)) + batch_op.create_index(batch_op.f('ix_post_licence_id'), ['licence_id'], unique=False) + batch_op.create_foreign_key(None, 'licence', ['licence_id'], ['id']) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('post', schema=None) as batch_op: + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.drop_index(batch_op.f('ix_post_licence_id')) + batch_op.drop_column('licence_id') + + op.drop_table('licence') + # ### end Alembic commands ###