Add separate media license

Fixes #91
This commit is contained in:
rubenwardy 2018-05-29 20:17:18 +01:00
parent f755c7d429
commit e7acd7faa3
No known key found for this signature in database
GPG Key ID: A1E29D52FF81513C
5 changed files with 49 additions and 3 deletions

@ -186,7 +186,6 @@ class Notification(db.Model):
class License(db.Model): class License(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50), nullable=False, unique=True) name = db.Column(db.String(50), nullable=False, unique=True)
packages = db.relationship("Package", backref="license", lazy="dynamic")
def __init__(self, v): def __init__(self, v):
self.name = v self.name = v
@ -327,7 +326,10 @@ class Package(db.Model):
type = db.Column(db.Enum(PackageType)) type = db.Column(db.Enum(PackageType))
created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
license_id = db.Column(db.Integer, db.ForeignKey("license.id")) license_id = db.Column(db.Integer, db.ForeignKey("license.id"), nullable=False, default=1)
license = db.relationship("License", foreign_keys=[license_id])
media_license_id = db.Column(db.Integer, db.ForeignKey("license.id"), nullable=False, default=1)
media_license = db.relationship("License", foreign_keys=[media_license_id])
approved = db.Column(db.Boolean, nullable=False, default=False) approved = db.Column(db.Boolean, nullable=False, default=False)
soft_deleted = db.Column(db.Boolean, nullable=False, default=False) soft_deleted = db.Column(db.Boolean, nullable=False, default=False)

@ -57,6 +57,7 @@
{{ render_field(form.desc, class_="pkg_meta") }} {{ render_field(form.desc, class_="pkg_meta") }}
{{ render_multiselect_field(form.tags, class_="pkg_meta") }} {{ render_multiselect_field(form.tags, class_="pkg_meta") }}
{{ render_field(form.license, class_="pkg_meta") }} {{ render_field(form.license, class_="pkg_meta") }}
{{ render_field(form.media_license, class_="pkg_meta") }}
<div class="pkg_meta"> <div class="pkg_meta">
<h2 class="not_txp">Dependency Info</h2> <h2 class="not_txp">Dependency Info</h2>

@ -92,7 +92,14 @@
</tr> </tr>
<tr> <tr>
<td>License</td> <td>License</td>
<td>{{ package.license.name }}</td> <td>
{% if package.license != package.media_license %}
{{ package.license.name }} for code,<br />
{{ package.media_license.name }} for media.
{% else %}
{{ package.license.name }}
{% endif %}
</td>
</tr> </tr>
<tr> <tr>
<td>Added</td> <td>Added</td>

@ -116,6 +116,7 @@ class PackageForm(FlaskForm):
desc = TextAreaField("Long Description (Markdown)", [Optional(), Length(0,10000)]) desc = TextAreaField("Long Description (Markdown)", [Optional(), Length(0,10000)])
type = SelectField("Type", [InputRequired()], choices=PackageType.choices(), coerce=PackageType.coerce, default=PackageType.MOD) type = SelectField("Type", [InputRequired()], choices=PackageType.choices(), coerce=PackageType.coerce, default=PackageType.MOD)
license = QuerySelectField("License", [InputRequired()], query_factory=lambda: License.query, get_pk=lambda a: a.id, get_label=lambda a: a.name) license = QuerySelectField("License", [InputRequired()], query_factory=lambda: License.query, get_pk=lambda a: a.id, get_label=lambda a: a.name)
media_license = QuerySelectField("Media License", [InputRequired()], query_factory=lambda: License.query, get_pk=lambda a: a.id, get_label=lambda a: a.name)
provides_str = StringField("Provides (mods included in package)", [Optional(), Length(0,1000)]) provides_str = StringField("Provides (mods included in package)", [Optional(), Length(0,1000)])
tags = QuerySelectMultipleField('Tags', query_factory=lambda: Tag.query.order_by(db.asc(Tag.name)), get_pk=lambda a: a.id, get_label=lambda a: a.title) tags = QuerySelectMultipleField('Tags', query_factory=lambda: Tag.query.order_by(db.asc(Tag.name)), get_pk=lambda a: a.id, get_label=lambda a: a.title)
harddep_str = StringField("Hard Dependencies", [Optional(), Length(0,1000)]) harddep_str = StringField("Hard Dependencies", [Optional(), Length(0,1000)])

@ -0,0 +1,35 @@
"""empty message
Revision ID: aa6d7b595a94
Revises: aa6d21889d22
Create Date: 2018-05-29 20:09:56.647358
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'aa6d7b595a94'
down_revision = 'aa6d21889d22'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('package', sa.Column('media_license_id', sa.Integer()))
op.execute('UPDATE package SET media_license_id=license_id')
op.alter_column('package', 'media_license_id', nullable=False)
op.alter_column('package', 'license_id', existing_type=sa.INTEGER(), nullable=False)
op.create_foreign_key(None, 'package', 'license', ['media_license_id'], ['id'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('package', 'license_id',
existing_type=sa.INTEGER(),
nullable=True)
op.drop_column('package', 'media_license_id')
# ### end Alembic commands ###