예제 #1
0
__all__ = ["bp"]


def patch_single_preprocessor(instance_id=None, data=None, **kw):
    """Accepts two arguments, `instance_id`, the primary key of the
    instance of the model to patch, and `data`, the dictionary of fields
    to change on the instance.

    """
    return g.token_user.id == instance_id


# 需要一点小 hack ..
bp = api_manager.create_api_blueprint(
    Account,
    methods=["GET", "PUT"],
    preprocessors=dict(PUT_SINGLE=[need_auth, patch_single_preprocessor], ),
    exclude_columns=EXCLUDE_COLUMNS)


@bp.route("/account/authorize/", methods=["POST"])
def _account_authorize():
    from .forms import LoginForm
    form = LoginForm()
    if not form.validate_on_submit():
        return jsonify(code=400, msg="Wrong username/password")
    user = form.user
    if not user.api_token:
        user.generate_api_token()
    return jsonify(code=200, token=user.api_token)
예제 #2
0
파일: api.py 프로젝트: NyankoRevo/Gather
__all__ = ["bp"]


def patch_single_preprocessor(instance_id=None, data=None, **kw):
    """Accepts two arguments, `instance_id`, the primary key of the
    instance of the model to patch, and `data`, the dictionary of fields
    to change on the instance.

    """
    return g.token_user.id == instance_id


# 需要一点小 hack ..
bp = api_manager.create_api_blueprint(
    Account,
    methods=["GET", "PUT"],
    preprocessors=dict(PUT_SINGLE=[need_auth, patch_single_preprocessor],),
    exclude_columns=EXCLUDE_COLUMNS
)


@bp.route("/account/authorize/", methods=["POST"])
def _account_authorize():
    from .forms import LoginForm
    form = LoginForm()
    if not form.validate_on_submit():
        return jsonify(
            code=400,
            msg="Wrong username/password"
        )
    user = form.user
    if not user.api_token:
예제 #3
0
파일: api.py 프로젝트: NyankoRevo/Gather
# -*- coding:utf-8 -*-
from flask import g, jsonify

from gather.api import need_auth, EXCLUDE_COLUMNS

from gather.extensions import api_manager
from gather.topic.models import Topic, Reply


bp = api_manager.create_api_blueprint(
    Topic,
    methods=["GET", "POST"],
    preprocessors={
        'POST': [need_auth],
    },
    include_methods=["have_read"],
    exclude_columns=EXCLUDE_COLUMNS
)


@bp.route("/topic/<int:topic_id>/mark_read")
def _mark_read_for_topic(topic_id):
    need_auth()
    topic = Topic.query.get_or_404(topic_id)
    topic.mark_read(g.token_user)
    return jsonify({"code": 200})


def _update_topic_updated(result=None, **kw):
    if not result:
        return
예제 #4
0
# -*- coding:utf-8 -*-
from flask import g, jsonify

from gather.api import need_auth, EXCLUDE_COLUMNS

from gather.extensions import api_manager
from gather.topic.models import Topic, Reply

bp = api_manager.create_api_blueprint(Topic,
                                      methods=["GET", "POST"],
                                      preprocessors={
                                          'POST': [need_auth],
                                      },
                                      include_methods=["have_read"],
                                      exclude_columns=EXCLUDE_COLUMNS)


@bp.route("/topic/<int:topic_id>/mark_read")
def _mark_read_for_topic(topic_id):
    need_auth()
    topic = Topic.query.get_or_404(topic_id)
    topic.mark_read(g.token_user)
    return jsonify({"code": 200})


def _update_topic_updated(result=None, **kw):
    if not result:
        return
    reply = Reply.query.get(result["id"])
    reply.topic.updated = reply.created
    reply.topic.clear_read()
예제 #5
0
파일: api.py 프로젝트: NyankoRevo/Gather
# -*- coding:utf-8 -*-
from gather.api import EXCLUDE_COLUMNS

from gather.extensions import api_manager
from gather.node.models import Node


bp = api_manager.create_api_blueprint(
    Node,
    methods=["GET"],
    exclude_columns=EXCLUDE_COLUMNS
)