Example #1
0
def database():
    db.create_all()
    for subject in TEST_SUBJECTS:
        user = User(
            **{
                "id": subject["id"],
                "pw_hash": pbkdf2_sha256.hash(subject["password"]),
                "email": subject["email"],
            })
        profile = UserProfile(
            **{
                "user_id": subject["id"],
                "given_name": subject["given_name"],
                "family_name": subject["family_name"],
                "nickname": subject["given_name"] + "ster",
                "handle": subject["email"].split("@")[0],
                "visibility": subject["visibility"],
            })
        db.session.add(user)
        db.session.add(profile)
        important_tt = ThingyType(
            **{
                "id": 1,
                "user_id": subject["id"],
                "tag": "important",
                "name": "Important",
            })
        db.session.add(important_tt)
        deferred_tt = ThingyType(
            **{
                "id": 2,
                "user_id": subject["id"],
                "tag": "deferred",
                "name": "Deferred"
            })
        db.session.add(deferred_tt)
        delayed_tt = ThingyType(**{
            "id": 3,
            "user_id": subject["id"],
            "tag": "delayed",
            "name": "Delayed"
        })
        db.session.add(delayed_tt)
        thingy = Thingy(**{
            "id": 1,
            "user_id": subject["id"],
            "type_id": important_tt.id
        })
        db.session.add(thingy)

    db.session.commit()

    yield db

    db.drop_all()
Example #2
0
    article = Article.query.filter_by(link=article_url).first()
    if article is None:  # if article doesn't exist then create the article in the database
        article = Article(link=article_url, content=post_data['content'], title=post_data['title'], image=post_data['image'], author=post_data['author'])
        db.session.add(article)
        db.session.commit()
        article = Article.query.filter_by(link=article_url).first()
    return flask.jsonify(article_id=article.id)

@app.route('/article/<int:article_id>/get')
def get_comments(article_id):
    article = Article.query.get(article_id)
    return flask.jsonify(content=article.content, comments=[c.serialize for c in article.comments.all()], title=article.title, image=article.image, author=article.author, id=article.id)

@app.route('/article/<int:article_id>/comments/new', methods=['POST'])
def new_comment(article_id):
    post_data = flask.request.form
    comment = Comment(name=post_data['name'], text=post_data['text'])
    if post_data['location'] is not None:
        comment.location = post_data['location']
    article = Article.query.get(article_id)
    article.comments.append(comment)
    article.content = post_data['content']
    db.session.commit()
    return flask.jsonify(content=article.content, comments=[c.serialize for c in article.comments.all()])

if __name__ == "__main__":
    #Create necessary db
    db.create_all()
    #Run
    app.run()
Example #3
0
CORS(app)
if env("ENV") == "dev":
    app.debug = True
    app.config['SQLALCHEMY_DATABASE_URI'] = env("SQLALCHEMY_LOCAL_DATABASE_URI")
else:
    app.debug = False
    app.config['SQLALCHEMY_DATABASE_URI'] = env("SQLALCHEMY_REMOTE_DATABASE_URI")
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db.app = app
db.init_app(app)

# Create the database tables and delete previous data
db.reflect()
db.drop_all()
db.create_all()
# Add initial data to the tables
seed_all()

# Connect routes to app
app.register_blueprint(routes_blueprint)

if env("ENV") == "dev":
    from flask_swagger_ui import get_swaggerui_blueprint
    SWAGGERUI_BLUEPRINT = get_swaggerui_blueprint(
        SWAGGER_URL,
        API_URL,
        config={
            'app_name': "Best-PMS-ever"
        }
    )
Example #4
0
def create_database():
    db.create_all()
 def __init__(self):
     db.create_all()
     self.session = db.session
Example #6
0
def create_database():
     db.create_all()
Example #7
0
def initdb():
    """Creates all database tables."""
    db.create_all()
def create_app():
    # app = Flask(__name__)
    db.create_all()
    db.init_app(app)
    return app