コード例 #1
0
ファイル: api.py プロジェクト: amylopes/buildersrecords
"""

from app import api_manager
from app.jwt import auth_func
from app.models import User, Project, Category, Item


# Users: /api/users
# methods allowed: GET, POST, DELETE, PUT
# results_per_page: pagination turned off (set to 0)
# GET_MANY and POST are unprotected (not listed in preprocessors)
api_manager.create_api(User,
    methods          = ['GET', 'POST', 'DELETE', 'PUT'],
    url_prefix       = '/api',
    results_per_page = 0,
    preprocessors    = dict(GET_SINGLE    = [auth_func],
                            PUT_SINGLE    = [auth_func],
                            PUT_MANY      = [auth_func],
                            DELETE_SINGLE = [auth_func],
                            DELETE_MANY   = [auth_func]),
    collection_name  = 'users')

# Projects: /api/projects
# methods allowed: GET, POST, DELETE, PUT
# results_per_page: pagination turned off (set to 0)
# All methods are protected (all of them are listed in preprocessors)
api_manager.create_api(Project,
    methods          = ['GET', 'POST', 'DELETE', 'PUT'],
    url_prefix       = '/api',
    results_per_page = 0,
    preprocessors    = dict(POST          = [auth_func],
                            GET_SINGLE    = [auth_func],
コード例 #2
0
ファイル: user.py プロジェクト: ravipunj/flashy
    email = db.Column(db.String(), nullable=False, unique=True)

    decks = db.relationship("Deck", backref="owner")


def process_password(data):
    password = data.pop("password")
    password_salt = binascii.hexlify(os.urandom(16))
    password_hash = binascii.hexlify(
        hashlib.pbkdf2_hmac("sha256",
                            password=password,
                            salt=password_salt,
                            iterations=40000,
                            dklen=32))

    data["password_salt"] = password_salt
    data["password_hash"] = password_hash


api_manager.create_api(
    User,
    methods=["POST", "GET"],
    exclude_columns=[
        "created", "modified", "password_salt", "password_hash",
        "decks.created", "decks.modified"
    ],
    preprocessors={
        "POST": [process_password],
    },
)
コード例 #3
0
ファイル: api.py プロジェクト: ezamrik/flask-angularjs
# -*- coding: utf-8 -*-

"""
    app.api
    ~~~~~~~~~~~~~~~~
    API module
"""

from app import api_manager
from app.models import User, Project, Category, Item


api_manager.create_api(User, methods = ['GET', 'POST', 'DELETE', 'PUT'])
api_manager.create_api(Project, methods = ['GET', 'POST', 'DELETE', 'PUT'])
api_manager.create_api(Category, methods = ['GET', 'POST', 'DELETE', 'PUT'])
api_manager.create_api(Item, methods = ['GET', 'POST', 'DELETE', 'PUT'])
コード例 #4
0
ファイル: api.py プロジェクト: boyska/colibri
'''
API for colibri
'''

from datetime import datetime

from flask import request, escape, url_for, Response
from werkzeug.contrib.atom import AtomFeed

from app import app, utils, api_manager, models

#TODO: forbid GET_MANY for unauthenticated users
api_manager.create_api(models.Opera)
api_manager.create_api(models.Esemplare)


def results_rss(iterable):
    feed = AtomFeed("OpenSearch results",
                    feed_url=request.url,
                    url=request.url_root)
    for r in iterable:
        feed.add(r.opera.title,
                 'Libro bello eh %s' %
                 (','.join((escape(a.name) for a in r.opera.authors))),
                 updated=datetime.now(),
                 url=url_for('esemplare', id=r.id))
    return feed.get_response()


@app.route('/opensearch/search.xml')
def os_search():
コード例 #5
0
ファイル: deck.py プロジェクト: ravipunj/flashy
from attrs_sqlalchemy import attrs_sqlalchemy

from app import api_manager, db
from models.mixins import BaseModelMixin


@attrs_sqlalchemy
class Deck(BaseModelMixin, db.Model):
    __tablename__ = "deck"

    name = db.Column(db.String(), nullable=False)

    owner_id = db.Column(db.String(32), db.ForeignKey("user.id"))

    cards = db.relationship("Card", backref="deck")


api_manager.create_api(
    Deck,
    methods=["POST", "GET"],
    exclude_columns=[
        "created", "modified", "owner_id", "owner.created", "owner.modified",
        "owner.password_salt", "owner.password_hash", "cards.created",
        "cards.modified"
    ],
)
コード例 #6
0
ファイル: views.py プロジェクト: shanehead/AnimalTracker
from app import app, api_manager
from flask import request, Response
from models import api_models
from tools import google_storage_upload
import json

# Create API endpoints
for model_name in api_models:
    model_class = api_models[model_name]
    api_manager.create_api(model_class,
                           methods=['GET', 'POST', 'DELETE', 'PUT', 'PATCH'],
                           allow_patch_many=True)


@app.route('/')
@app.route('/index')
def index():
    return app.send_static_file('index.html')


@app.route('/add_animal', methods=['POST'])
def add_animal():
    upload_file = request.files['file']
    if upload_file:
        photo_uri = google_storage_upload(upload_file)
        data = {'photo_uri': photo_uri}
        resp = Response(json.dumps(data),
                        status=200,
                        mimetype='application/json')
        return resp
コード例 #7
0
from app import db, api_manager
from datetime import datetime


class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    food = db.Column(db.String(255))
    source = db.Column(db.String(255))
    destination = db.Column(db.String(255))
    time = db.Column(db.DateTime)
    payment = db.Column(db.String(255))
    contact = db.Column(db.String(255))
    info = db.Column(db.String(255))
    name = db.Column(db.String(255))


api_manager.create_api(Post, methods=['GET', 'POST', 'DELETE', 'PUT'])
コード例 #8
0
from attrs_sqlalchemy import attrs_sqlalchemy
from sqlalchemy.dialects.postgresql import JSON

from app import api_manager, db
from models.mixins import BaseModelMixin


@attrs_sqlalchemy
class Card(BaseModelMixin, db.Model):
    __tablename__ = "card"

    data = db.Column(JSON(none_as_null=True), nullable=False)
    deck_id = db.Column(db.String(32), db.ForeignKey("deck.id"))


api_manager.create_api(
    Card,
    methods=["POST", "GET"],
    exclude_columns=[
        "created", "modified", "deck_id", "deck.created", "deck.modified",
        "deck.owner_id"
    ],
)
コード例 #9
0
'''
API for colibri
'''

from datetime import datetime

from flask import request, escape, url_for, Response
from werkzeug.contrib.atom import AtomFeed

from app import app, utils, api_manager, models

#TODO: forbid GET_MANY for unauthenticated users
api_manager.create_api(models.Opera)
api_manager.create_api(models.Esemplare)


def results_rss(iterable):
    feed = AtomFeed("OpenSearch results",
                    feed_url=request.url,
                    url=request.url_root)
    for r in iterable:
        feed.add(r.opera.title,
                 'Libro bello eh %s' % (','.join(
                     (escape(a.name) for a in r.opera.authors))),
                 updated=datetime.now(),
                 url=url_for('esemplare', id=r.id))
    return feed.get_response()


@app.route('/opensearch/search.xml')
def os_search():