Beispiel #1
0
# -*- coding: utf-8 -*-
import urllib, json, string, requests, os
from requests.auth import HTTPBasicAuth
from flask import Blueprint
from app import db, manager, admin
from app.catalog.models import Tasks
from flask.ext.admin.contrib.sqla import ModelView

catalog = Blueprint('catalog', __name__)

manager.create_api(Tasks,
                   methods=['GET', 'POST', 'PUT', 'DELETE'],
                   results_per_page=None)

admin.add_view(ModelView(Tasks, db.session))
Beispiel #2
0
            })
        return currencies

    def get_gem_stats(self):
        # get the gems into a dict for easier searching

        gems = Item.query.filter(Item.properties.any(name="Experience")).all()
        return {"all_gems": Counter(g.type for g in gems).most_common()}

    def dispatch_request(self):
        context = {"currencies": self.get_currency_stats()}
        context.update(self.get_gem_stats())

        return render_template('stats.html', **context)


app.add_url_rule('/', view_func=StatsView.as_view('stats'))

if __name__ == '__main__':

    def postprocessor(result, **kwargs):
        json.dumps(result, use_decimal=True)

    # create API endpoints, which will be available at /api/<tablename> by
    manager.create_api(Item,
                       methods=['GET'],
                       postprocessors={
                           'GET_MANY': [postprocessor],
                       })
    app.run(debug=True, port=8000)
Beispiel #3
0
    post = post_deserializer(data)
    post.user = g.user
    data = post_serializer(post)


def get_many_postprocessor(result=None, search_params=None, **kw):
    if result:
        for post in result['objects']:
            post['user'] = user_serializer(user_deserializer(post['user']))


manager.create_api(
    Post,
    methods=['GET', 'POST', 'PATCH', 'PUT', 'DELETE'],
    preprocessors=dict(
        POST=[auth_required, post_preprocessor],
        PATCH_SINGLE=[auth_required, owner_single],
        PATCH_MANY=[auth_required, owner_single],
        PUT=[auth_required, owner_single],
        DELETE_SINGLE=[auth_required, owner_single],
        DELETE_MANY=[auth_required, owner_single]
    ),
    postprocessors=dict(
        GET_MANY=[get_many_postprocessor],
    ),
    url_prefix="/api/v1",
    collection_name="article",
    serializer=post_serializer,
    deserializer=post_deserializer
)
Beispiel #4
0
from app import matrix,DB as db, manager
from models.user import User, Team,	UserAccount
from models.application import Application, Version, Environment, CodeBase, Component, Feature, Datapoint, Datacollection
from models.news import News


manager.create_api(User, methods=['GET', 'POST', 'DELETE'])
manager.create_api(Team	, methods=['GET', 'POST', 'DELETE'])
manager.create_api(Application, methods=['GET', 'POST', 'DELETE'])
manager.create_api(Version, methods=['GET', 'POST', 'DELETE'])
manager.create_api(Feature, methods=['GET', 'POST', 'DELETE'])
manager.create_api(Environment, methods=['GET', 'POST', 'DELETE'])
manager.create_api(Component, methods=['GET', 'POST', 'DELETE'])
manager.create_api(CodeBase, methods=['GET', 'POST', 'DELETE'])
manager.create_api(News, methods=['GET', 'POST', 'DELETE'])
manager.create_api(Datapoint, methods=['GET', 'POST', 'DELETE'])
manager.create_api(Datacollection, methods=['GET', 'POST', 'DELETE'])
Beispiel #5
0
from app import db
from app import manager


class Texts(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    textname = db.Column(db.String(100))
    text = db.Column(db.String(100))


db.create_all()
manager.create_api(Texts, methods=['POST', 'GET', 'PUT', 'DELETE'])
Beispiel #6
0
from flask import Flask
from app import db, manager


class Task(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(40))
    description = db.Column(db.String(900))
    status = db.Column(db.String(1))
    active = db.Column(db.Boolean)

    def __init__(self, title, description=None, status='P', active=True):
        self.title = title
        self.description = description
        self.status = status
        self.active = active

    def add(task):
        db.session.add(task)
        return db.session.commit()

    def update():
        return db.session.commit()


db.create_all()
manager.create_api(Task, methods=['POST', 'GET', 'PUT'])
Beispiel #7
0
from app import db
from app import manager


class Vendedor(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    nome = db.Column(db.String(100))
    cpf = db.Column(db.String(11))
    sexo = db.Column(db.String(50))


db.create_all()
manager.create_api(Vendedor, methods=['POST', 'DELETE', 'PUT', 'GET'])
Beispiel #8
0
from app import db, manager


class Endereco(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    logradouro = db.Column(db.String(100))
    numero = db.Column(db.Integer)
    bairro = db.Column(db.String(50))


db.create_all()
manager.create_api(Endereco, methods=['GET', 'POST', 'PUT', 'DELETE'])
Beispiel #9
0
    def get_gem_stats(self):
        # get the gems into a dict for easier searching

        gems = Item.query.filter(
            Item.properties.any(name="Experience")
        ).all()
        return {
            "all_gems": Counter(g.type for g in gems).most_common()
        }

    def dispatch_request(self):
        context = {
            "currencies": self.get_currency_stats()
        }
        context.update(self.get_gem_stats())

        return render_template('stats.html', **context)
app.add_url_rule('/', view_func=StatsView.as_view('stats'))


if __name__ == '__main__':
    def postprocessor(result, **kwargs):
        json.dumps(result, use_decimal=True)

    # create API endpoints, which will be available at /api/<tablename> by
    manager.create_api(Item, methods=['GET'], postprocessors={
        'GET_MANY': [postprocessor],
    })
    app.run(debug=True, port=8000)
Beispiel #10
0
# -*- coding: utf-8 -*-
from flask import Blueprint
from app import db, manager, admin
from app.catalog.models import Classifier, Skill
from flask.ext.admin.contrib.sqla import ModelView

catalog = Blueprint('catalog', __name__)

# Create API endpoints, which will be available at /api/<tablename> by
# default. Allowed HTTP methods can be specified as well.
manager.create_api(Classifier,
                   methods=['GET'],
                   results_per_page=None,
                   exclude_columns=['skills'])

admin.add_view(ModelView(Classifier, db.session))
Beispiel #11
0
    else:
        raise ProcessingException(description="Not Found", code=404)


def post_preprocessor(data=None, **kwargs):
    post = post_deserializer(data)
    post.user = g.user
    data = post_serializer(post)


def get_many_postprocessor(result=None, search_params=None, **kw):
    if result:
        for post in result['objects']:
            post['user'] = user_serializer(user_deserializer(post['user']))


manager.create_api(Post,
                   methods=['GET', 'POST', 'PATCH', 'PUT', 'DELETE'],
                   preprocessors=dict(
                       POST=[auth_required, post_preprocessor],
                       PATCH_SINGLE=[auth_required, owner_single],
                       PATCH_MANY=[auth_required, owner_single],
                       PUT=[auth_required, owner_single],
                       DELETE_SINGLE=[auth_required, owner_single],
                       DELETE_MANY=[auth_required, owner_single]),
                   postprocessors=dict(GET_MANY=[get_many_postprocessor], ),
                   url_prefix="/api/v1",
                   collection_name="article",
                   serializer=post_serializer,
                   deserializer=post_deserializer)
Beispiel #12
0
from app import db
from app import manager


class Noticias(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    titulo = db.Column(db.String(100))
    texto = db.Column(db.String(200))
    autor = db.Column(db.String(20))


db.create_all()
manager.create_api(Noticias, methods=['POST', 'GET', 'PUT', 'DELETE'])
Beispiel #13
0
from app.table_model.number.asset_name_model import AssetNameModel
from app.table_model.number.buy_model import BuyModel
from app.table_model.number.standard_model import StandardModel
from app.table_model.rack_location.device_info import DeviceInfo
from app.table_model.rack_location.for_server_model import DeviceInfoForServerModel
from app.table_model.rack_location.for_switch_model import DeviceInfoForSwitchModel
from app.table_model.rack_location.rack_location_for_server_model import RackLocationForServerModel
from app.table_model.rack_location.rack_location_for_switch_model import RackLocationForSwitchModel
from app.table_model.rack_location.rack_location_model import RackLocationModel
from app.table_model.service.service_model import ServiceModel
from app.table_model.service.service_name_model import ServiceNameModel

METHODS = ['GET', 'POST', 'DELETE', 'PUT']

manager.create_api(AssetModel,
                   methods=METHODS,
                   results_per_page=1000,
                   max_results_per_page=1000)
manager.create_api(StorageSpecNameModel,
                   methods=METHODS,
                   results_per_page=1000,
                   max_results_per_page=1000)
manager.create_api(StorageSpecTypeModel,
                   methods=METHODS,
                   results_per_page=1000,
                   max_results_per_page=1000)
manager.create_api(StorageSpecModel,
                   methods=METHODS,
                   results_per_page=1000,
                   max_results_per_page=1000)
manager.create_api(RackSpecModel,
                   methods=METHODS,
from app import db
from app import manager

class Endereco(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    logradouro = db.Column(db.String(100))
    numero = db.Column(db.String(10))
    bairro = db.Column(db.String(50))

db.create_all()
manager.create_api(Endereco, collection_name='endereco', methods=['POST','DELETE','PUT','GET'])
# collection_name = 'nome da tabela no banco de dados'
Beispiel #15
0
    def make_object(self, data):
        return User(api_purpose=True, **data)


def user_serializer(instance):
    return UserSchema().dump(instance).data


def user_deserializer(data):
    return UserSchema().load(data).data


def get_many_postprocessor(result=None, search_params=None, **kw):
    if result:
        for user in result['objects']:
            new = user_serializer(user_deserializer(user))
            user.clear()
            user.update(new)


manager.create_api(User,
                   methods=[
                       'GET',
                   ],
                   postprocessors=dict(GET_MANY=[
                       get_many_postprocessor,
                   ], ),
                   url_prefix="/api/v1",
                   serializer=user_serializer,
                   deserializer=user_deserializer)
    r = requests.post(url,
                      auth=HTTPBasicAuth(
                          os.environ.get('INITIAL_ADMIN_USER'),
                          os.environ.get('INITIAL_ADMIN_PASSWORD')))
    #install_rec = Install(instance_id, app.name, app.source_url)
    install_rec = Install(instance_id, app.name, app.source_url, r.status_code,
                          r.reason)
    db.session.add(install_rec)
    db.session.commit()
    pass


manager.create_api(Extensions,
                   methods=['GET', 'POST', 'DELETE'],
                   preprocessors={
                       'GET_SINGLE': [pre_get_catalog],
                       'GET_MANY': [pre_get_catalog]
                   },
                   results_per_page=None)
manager.create_api(Metadata,
                   methods=['GET', 'POST', 'DELETE'],
                   results_per_page=None)
manager.create_api(Install,
                   methods=['GET', 'POST', 'DELETE'],
                   preprocessors={
                       'GET_SINGLE': [pre_get_installapp],
                       'GET_MANY': [pre_get_installapp]
                   },
                   results_per_page=None)

admin.add_view(ModelView(Extensions, db.session))
Beispiel #17
0
    def make_object(self, data):
        return User(api_purpose=True, **data)


def user_serializer(instance):
    return UserSchema().dump(instance).data


def user_deserializer(data):
    return UserSchema().load(data).data


def get_many_postprocessor(result=None, search_params=None, **kw):
    if result:
        for user in result['objects']:
            new = user_serializer(user_deserializer(user))
            user.clear()
            user.update(new)

manager.create_api(
    User,
    methods=['GET', ],
    postprocessors=dict(
        GET_MANY=[get_many_postprocessor,],
    ),
    url_prefix="/api/v1",
    serializer=user_serializer,
    deserializer=user_deserializer
)
Beispiel #18
0
from app import db
from app import manager


class Register(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    projeto = db.Column(db.String(100))
    ponto = db.Column(db.String(100))
    time = db.Column(db.DateTime)


db.create_all()
manager.create_api(Register, methods=['POST', 'DELETE', 'GET'])
Beispiel #19
0
                'description': project.get('description'),
                'start': project.get('start'),
                'end': project.get('end'),
                'missions': ids_only_missions
            }
        )

    uavs = uavs_schema.dump(user.uavs).data
    sensors = sensors_schema.dump(user.sensors).data

    ret['missions'] = missions
    # ret['personnel'] = personnel
    ret['personnel'] = user_personnel
    ret['projects'] = ids_only_projects
    ret['roles'] = [role_schema.dump(role).data for role in user.roles]
    ret['sensors'] = sensors
    ret['uavs'] = uavs
    del ret['user_personnel']

    return ret


# https://flask-restless.readthedocs.io/en/stable/
manager.create_api(User, methods=methods, serializer=user_serializer)
manager.create_api(Project, methods=methods, serializer=project_serializer)
manager.create_api(UAV, methods=methods)
manager.create_api(Sensor, methods=methods)
manager.create_api(Mission, methods=methods, serializer=mission_serializer)
manager.create_api(MissionSensors, methods=methods)
manager.create_api(Role, methods=methods)
Beispiel #20
0
from app import db, manager


class Cliente(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    nome = db.Column(db.String(100))
    nascimento = db.Column(db.DateTime)
    rg = db.Column(db.String(20))
    email = db.Column(db.String(20), unique=True)

    endereco_id = db.Column(db.Integer, db.ForeignKey('endereco.id'))
    endereco = db.relationship('Endereco')


db.create_all()
manager.create_api(Cliente, methods=['POST', 'GET', 'PUT', 'DELETE'])
Beispiel #21
0
from app import db
from app import manager

class Cliente(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    nome = db.Column(db.Integer, primary_key=True)
    nascimento = db.Column(db.DateTime)
    cpf = db.Column(db.Integer, unique=True)
    email = db.Column(db.String(50), unique=True)
    time_id = db.Column(db.Integer, db.ForeignKey('time.id'))
    time = db.relationship('Time')
db.create_all()
manager.create_api(Cliente, methods=['GET','POST','DELETE','PUT'])