Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
206 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
flaskbb.plugins.models | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
This module provides registration and a basic DB backed key-value store for plugins. | ||
:copyright: (c) 2017 by the FlaskBB Team. | ||
:license: BSD, see LICENSE for more details. | ||
""" | ||
from sqlalchemy import UniqueConstraint | ||
from sqlalchemy.ext.associationproxy import association_proxy | ||
from sqlalchemy.orm.collections import attribute_mapped_collection | ||
|
||
from flaskbb.extensions import db | ||
|
||
|
||
class PluginStore(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
name = db.Column(db.Unicode(255), nullable=False) | ||
value = db.Column(db.Unicode(255)) | ||
plugin_id = db.Column(db.Integer, db.ForeignKey('plugin_registry.id')) | ||
|
||
__table_args__ = (UniqueConstraint('name', 'plugin_id', name='plugin_kv_uniq'), ) | ||
|
||
def __repr__(self): | ||
return '<FlaskBBPluginSetting plugin={} name={} value={}>'.format( | ||
self.plugin.name, self.name, self.value | ||
) | ||
|
||
|
||
class PluginRegistry(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
name = db.Column(db.Unicode(255), unique=True, nullable=False) | ||
enabled = db.Column(db.Boolean, default=True) | ||
values = db.relationship( | ||
'PluginStore', | ||
collection_class=attribute_mapped_collection('name'), | ||
cascade='all, delete-orphan', | ||
backref='plugin' | ||
) | ||
settings = association_proxy( | ||
'values', 'value', creator=lambda k, v: PluginStore(name=k, value=v) | ||
) | ||
|
||
def __repr__(self): | ||
return '<FlaskBBPlugin name={} enabled={}>'.format(self.name, self.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
flaskbb.plugins.spec | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
This module provides the core FlaskBB plugin hook definitions | ||
:copyright: (c) 2017 by the FlaskBB Team. | ||
:license: BSD, see LICENSE for more details. | ||
""" | ||
|
||
from pluggy import HookspecMarker | ||
|
||
spec = HookspecMarker('flaskbb') | ||
|
||
|
||
@spec | ||
def flaskbb_extensions(app): | ||
""" | ||
Hook for initializing any plugin loaded extensions | ||
""" | ||
|
||
|
||
@spec | ||
def flaskbb_load_blueprints(app): | ||
""" | ||
Hook for registering blueprints | ||
""" | ||
|
||
|
||
@spec | ||
def flaskbb_request_processors(app): | ||
""" | ||
Hook for registering pre/post request processors | ||
""" | ||
|
||
|
||
@spec | ||
def flaskbb_errorhandlers(app): | ||
""" | ||
Hook for registering error handlers | ||
""" | ||
|
||
|
||
@spec | ||
def flaskbb_jinja_directives(app): | ||
""" | ||
Hook for registering jinja filters, context processors, etc | ||
""" | ||
|
||
|
||
@spec | ||
def flaskbb_additional_setup(app, pluggy): | ||
""" | ||
Hook for any additional setup a plugin wants to do after all other application | ||
setup has finished | ||
""" | ||
|
||
|
||
@spec | ||
def flaskbb_cli(cli): | ||
""" | ||
Hook for registering CLI commands | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Add plugin tables | ||
Revision ID: 7c3fcf8a3335 | ||
Revises: | ||
Create Date: 2017-08-12 12:41:04.725309 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '7c3fcf8a3335' | ||
down_revision = None | ||
branch_labels = ('default',) | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('plugin_registry', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('name', sa.Unicode(length=255), nullable=False), | ||
sa.Column('enabled', sa.Boolean(), nullable=True), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('name') | ||
) | ||
op.create_table('plugin_store', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('name', sa.Unicode(length=255), nullable=False), | ||
sa.Column('value', sa.Unicode(length=255), nullable=True), | ||
sa.Column('plugin_id', sa.Integer(), nullable=True), | ||
sa.ForeignKeyConstraint(['plugin_id'], ['plugin_registry.id'], ), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('name', 'plugin_id', name='plugin_kv_uniq') | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('plugin_store') | ||
op.drop_table('plugin_registry') | ||
# ### end Alembic commands ### |