Exemplo n.º 1
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()
Exemplo n.º 2
0
from flask import request, Response

from bearblog import current_component, component_route
from .models import Settings
from bearblog.models import Signal
from bearblog.extensions import db

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


@component_route('/settings/<category>',
                 'get_settings',
                 'api_admin',
                 methods=['GET'])
def get_settings(category):
    settings = Settings.query.filter_by(category=category).all()
    return {'value': [setting.to_json() for setting in settings]}


@component_route('/settings/<int:id>',
                 'update_settings',
                 'api_admin',
                 methods=['PATCH'])
def update_settings(id):
    setting = Settings.query.get(id)
    data = request.get_json()
    setting.value = data['rawValue']
    db.session.commit()
    return Response(status=200)