예제 #1
0
import flask_marshmallow
import flask_restful
import importlib
import lime_endpoints
import lime_endpoints.endpoints
import logging
import pkgutil

URL_PREFIX = '/lime-mud'

logger = logging.getLogger(__name__)

bp = lime_endpoints.endpoints.create_blueprint('lime_mud',
                                               __name__,
                                               URL_PREFIX,
                                               static_folder='static')
api = flask_restful.Api(bp)
ma = flask_marshmallow.Marshmallow(bp)


def register_blueprint(app, config=None):
    for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
        if module_name.endswith('_test'):
            continue
        module_fullname = '{}.{}'.format(__name__, module_name)
        logger.info('Loading {}'.format(module_fullname))
        importlib.import_module(module_fullname)

    app.register_blueprint(bp)
    return bp
예제 #2
0
파일: app.py 프로젝트: EpicEric/ilo-toki
import scripts.jan_pije as jan_pije

DEFAULT_RANDOM_SAMPLE_SIZE = 25
MAXIMUM_RANDOM_SAMPLE_SIZE = 100

app = flask.Flask(__name__,
                  static_url_path='',
                  static_folder='dist',
                  template_folder='dist')
flask_cors.CORS(app)
app.config.from_mapping(SECRET_KEY=os.environ.get('SECRET_KEY', 'dev_key'),
                        SQLALCHEMY_DATABASE_URI=os.environ.get(
                            'DATABASE_URL', 'postgresql://localhost/ilo-toki'),
                        SQLALCHEMY_TRACK_MODIFICATIONS=False)
database.db.init_app(app)
ma = flask_marshmallow.Marshmallow(app)


class TranslationSchema(ma.ModelSchema):
    class Meta:
        model = database.Translation


@app.errorhandler(404)
def not_found(error):
    error_dict = {'status': 'error', 'reason': 'Page not found'}
    return error_dict, 404


# Database healthcheck API
@app.route('/api/healthcheck', methods=['GET'])
예제 #3
0
from flask import current_app

from project import db, app
from project import bcrypt
import datetime
import jwt

import flask_marshmallow as fm
import marshmallow_mongoengine as ma
mm = fm.Marshmallow(app)


class TaskModel(db.Document):
    name = db.StringField(required=True)
    description = db.StringField()
    duration = db.IntField()
    startdate = db.DateTimeField()
    status = db.BooleanField(default=True)  #convert to enum

    # shouldnt need this on task model
    def encode_auth_token(self, user_id):
        try:
            payload = {
                'exp':
                datetime.datetime.utcnow() + datetime.timedelta(
                    days=current_app.config.get('TOKEN_EXPIRATION_DAYS'),
                    seconds=current_app.config.get(
                        'TOKEN_EXPIRATION_SECONDS')),
                'iat':
                datetime.datetime.utcnow(),
                'sub': {
예제 #4
0
파일: apis.py 프로젝트: cnapp/cnapp-flask
import flask_apispec
import flask_marshmallow
import marshmallow

from cnapps.api import commons
from cnapps.api import docs
from cnapps.api.v1 import core as v1_core
from cnapps.api.v1alpha import core as v1alpha_core

REST = flask.Blueprint("apis", __name__)

API_PATH = "/api/apis"

LOGGER = logging.getLogger(__name__)

MA = flask_marshmallow.Marshmallow()


class APIVersionSchema(MA.Schema):

    name = marshmallow.fields.Str()

    class Meta(object):
        strict = True


API_SCHEMA = APIVersionSchema()
API_SCHEMAS = APIVersionSchema(many=True)


@REST.route(API_PATH, methods=["GET"])