|
@@ -1,84 +1,45 @@
|
|
|
-# -*- coding: utf-8 -*-
|
|
|
-"""
|
|
|
- flaskbb.plugins
|
|
|
- ~~~~~~~~~~~~~~~
|
|
|
+from flask.ext.plugins import Plugin
|
|
|
+from flask import current_app
|
|
|
|
|
|
- The Plugin class that every plugin should implement
|
|
|
|
|
|
- :copyright: (c) 2014 by the FlaskBB Team.
|
|
|
- :license: BSD, see LICENSE for more details.
|
|
|
-"""
|
|
|
-
|
|
|
-
|
|
|
-class PluginError(Exception):
|
|
|
- """Error class for all plugin errors."""
|
|
|
- pass
|
|
|
-
|
|
|
-
|
|
|
-class Plugin(object):
|
|
|
- """Every plugin should implement this class. It handles the registration
|
|
|
- for the plugin hooks, creates or modifies additional relations or
|
|
|
- registers plugin specific thinks"""
|
|
|
-
|
|
|
- #: If you want create your tables with one command, put your models
|
|
|
- #: in here.
|
|
|
- models = []
|
|
|
-
|
|
|
- #: The name of the plugin
|
|
|
- #: E.g. "Example Plugin"
|
|
|
- name = None
|
|
|
-
|
|
|
- #: A small description of the plugin
|
|
|
- description = None
|
|
|
-
|
|
|
- def install(self, app=None):
|
|
|
- """The plugin should specify here what needs to be installed.
|
|
|
- For example, create the database and register the hooks."""
|
|
|
- raise NotImplementedError
|
|
|
-
|
|
|
- def uninstall(self, app=None):
|
|
|
- """Uninstalls the plugin and deletes the things that
|
|
|
- the plugin has installed."""
|
|
|
- raise NotImplementedError
|
|
|
+class FlaskBBPlugin(Plugin):
|
|
|
+ # Some helpers
|
|
|
+ def register_blueprint(self, blueprint, **kwargs):
|
|
|
+ """Registers a blueprint."""
|
|
|
+ current_app.register_blueprint(blueprint, **kwargs)
|
|
|
|
|
|
def create_table(self, model, db):
|
|
|
- """Creates the table for the model
|
|
|
+ """Creates the relation for the model
|
|
|
|
|
|
:param model: The Model which should be created
|
|
|
:param db: The database instance.
|
|
|
"""
|
|
|
- model.__table__.create(bind=db.engine)
|
|
|
+ if not model.__table__.exists(bind=db.engine):
|
|
|
+ model.__table__.create(bind=db.engine)
|
|
|
|
|
|
def drop_table(self, model, db):
|
|
|
- """Drops the table for the bounded model.
|
|
|
+ """Drops the relation for the bounded model.
|
|
|
|
|
|
:param model: The model on which the table is bound.
|
|
|
:param db: The database instance.
|
|
|
"""
|
|
|
model.__table__.drop(bind=db.engine)
|
|
|
|
|
|
- def create_all_tables(self, db):
|
|
|
+ def create_all_tables(self, models, db):
|
|
|
"""A interface for creating all models specified in ``models``.
|
|
|
- If no models are specified in that variable it will abort
|
|
|
- with a exception.
|
|
|
|
|
|
+ :param models: A list with models
|
|
|
:param db: The database instance
|
|
|
"""
|
|
|
- if len(self.models) > 0:
|
|
|
- for model in self.models:
|
|
|
- self.create_table(model, db)
|
|
|
- else:
|
|
|
- raise PluginError("No models found in 'models'.")
|
|
|
+ for model in models:
|
|
|
+ self.create_table(model, db)
|
|
|
|
|
|
- def drop_all_tables(self, db):
|
|
|
+ def drop_all_tables(self, models, db):
|
|
|
"""A interface for dropping all models specified in the
|
|
|
- variable ``models``. If no models are specified in that variable,
|
|
|
- it will abort with an exception.
|
|
|
+ variable ``models``.
|
|
|
|
|
|
+ :param models: A list with models
|
|
|
:param db: The database instance.
|
|
|
"""
|
|
|
- if len(self.models) > 0:
|
|
|
- for model in self.models:
|
|
|
- self.drop_table(model, db)
|
|
|
- else:
|
|
|
- raise PluginError("No models found in 'models'.")
|
|
|
+ for model in models:
|
|
|
+ self.drop_table(model, db)
|