Beispiel #1
0
    def __init__(self,
                 name,
                 directory,
                 slug=None,
                 show_in_sidebar=True,
                 config=None):
        if slug is None:
            caller = inspect.getframeinfo(inspect.stack()[1][0])
            caller_path = caller.filename
            slug = Path(caller_path).parent.name
        Plugin.plugins[slug] = self
        self.name = name
        self.slug = slug
        self.directory = directory
        self.show_in_sidebar = show_in_sidebar
        self.signal = Signal(self)
        self.rule_map = Map()
        self.view_functions = {}
        self.config = config or {}

        if 'default_setting_category' in self.config:
            add_default_cateogry(self.directory,
                                 self.config['default_setting_category'])
Beispiel #2
0
from flask import flash, jsonify, redirect, request

from bearblog.plugins import current_plugin, plugin_route, plugin_url_for
from .models import Tag
from bearblog.models import Signal
from bearblog.extensions import db
from bearblog.utils import slugify
from bearblog.settings import get_setting

Signal = Signal(None)
Signal.set_default_scope(current_plugin.slug)


@Signal.connect('restore')
def restore_tags(tags):
    restored_tags = []
    for tag in tags:
        if type(tag) is str:
            tag = {'name': tag}
        t = Tag.query.filter_by(name=tag['name']).first()
        if t is None:
            t = Tag.create(name=tag['name'],
                           slug=slugify(tag['name']),
                           description=tag.get('description', ''))
            db.session.add(t)
            db.session.flush()
        else:
            if t.description is None or t.description == '':
                t.description = tag.get('description', '')
        restored_tags.append(t)
    db.session.flush()