コード例 #1
0
from Database import db

from flask import Flask,request,abort
app=Flask(__name__)

db.create_all();

if __name__=='__main__':
     app.run(debug=True)
コード例 #2
0
from Database import db
from Models import Voter, History
import graphene
from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField
from flask_graphql import GraphQLView
import os

VOTER_LIMIT = 50  # Maximum number of results per query to limit excessive ram usage
HISTORY_LIMIT = 10
app = Flask("VoterLookup")
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///voters.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config["SECRET_KEY"] = os.urandom(24)
db.init_app(app)
db.create_all(app=app)


# Schema Objects
class VoterObject(SQLAlchemyObjectType):
	class Meta:
		model = Voter
		interfaces = (graphene.relay.Node,)


class VoterHistoryObject(SQLAlchemyObjectType):
	class Meta:
		model = History
		interfaces = (graphene.relay.Node,)

コード例 #3
0
from Database import db, ma


class Product(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(40))
    description = db.Column(db.String(100))
    price = db.Column(db.Float)
    barcode = db.Column(db.String(100))
    promotion = db.Column(db.Boolean)

    def __init__(self, name, description, price, barcode, promotion):
        self.name = name
        self.description = description
        self.price = price
        self.barcode = barcode
        self.promotion = promotion


db.create_all()


class ProductSchema(ma.Schema):
    class Meta:
        fields = ('id', 'name', 'description', 'price', 'barcode', 'promotion')


product_schema = ProductSchema()
products_schema = ProductSchema(many=True)
コード例 #4
0
 def __init__(self):
     db.create_all()
コード例 #5
0
def cria_db():
    db.create_all()
コード例 #6
0
    else:
        return jsonify(upvote_count=answer.upvote_count)


@app.route('/api/matchscore', methods=['GET'])
def get_match_score():
    subject = request.args.get('subject')
    match_score = matcher.get_match_scores(subject)
    return jsonify({"matchscore":match_score})


@app.route('/reset', methods=['GET'])
def reset():
    Question.query.delete()
    Answer.query.delete()
    db.session.commit()
    return flask.redirect('/')


def make_json_error(ex):
    response = jsonify(message=str(ex))
    response.status_code = (ex.code
                            if isinstance(ex, HTTPException)
                            else 500)
    return response


if __name__ == '__main__':
    app.run()
    db.create_all()
コード例 #7
0
 def __init__(self):
     db.create_all()
     if User.query.count() == 0:
         self.create_user('admin', 'development', 5, 'jw')
コード例 #8
0
def init_db():
    db.init_app(app)
    with app.app_context():
        db.create_all()