Exemplo n.º 1
0
def reset():
    # 指定ディレクトリ内のファイルを取得
    images = glob("static/images/*.png")
    # DB内を一括で削除
    Image.query.delete()
    # 新たにDBへ登録
    for image in images:
        col = Image(filename=image)
        db_session.add(col)
    db_session.commit()  # 更新をDBに反映
    return render_template("reset.html", images=images)
Exemplo n.º 2
0
def create_shop():
    json = request.get_json()
    if json:
        v = Validator()
        if not v.validate(json, shop_schema):
            return jsonify(v.errors), 400
    else:
        return jsonify({'message': 'no json data'}), 400
    content = Shop(**json)
    db_session.add(content)
    db_session.commit()
    return jsonify(content.to_dict()), 201
Exemplo n.º 3
0
def post_connection(title=None):
    if title is None:
        abort(404)
    content = WikiContent.query.filter_by(title=title).first()
    if content is None:
        content = WikiContent(title, request.form["body"])
        flash('New entry!')
    else:
        content.body = request.form["body"]
        content.date = datetime.now()
        flash('Update entry!')
    db_session.add(content)
    db_session.commit()
    return render_template("show_content.html", content=content)
Exemplo n.º 4
0
Arquivo: app.py Projeto: kzfm/flaski
def post_content(title=None):
    if title is None:
        abort(404)
    content = WikiContent.query.filter_by(title=title).first()
    if content is None:
        content = WikiContent(title,
                              request.form["body"]
                              )
    else:
        content.body = request.form["body"]
        content.date = datetime.now()
    db_session.add(content)
    db_session.commit()
    return content.html
Exemplo n.º 5
0
def create_shop_products(id):
    json = request.get_json()
    if json:
        v = Validator()
        if not v.validate(json, product_schema):
            return jsonify(v.errors), 400
    else:
        return jsonify({'message': 'no json data'}), 400
    shop = Shop.query.get(id)
    if not shop:
        return jsonify({'message': 'invalid shops id'}), 400
    json['shops_id'] = shop.id
    content = Product(**json)
    db_session.add(content)
    db_session.commit()
    return jsonify(content.to_dict()), 201
Exemplo n.º 6
0
def post_content(title=None):
    if title is None:
        abort(404)
    content = WikiContent.query.filter_by(title=title).first()
    # contentが取得できていなければinsertするため、WikiContentのインスタンスを生成
    if content is None:
        content = WikiContent(title, request.form["body"])
    # contentが取得できていればupdateするため、bodyの内容とdatetime=現在時刻をセット
    else:
        content.body = request.form["body"]
        content.date = datetime.now()

    # contentの内容をaddしてcommit
    db_session.add(content)
    db_session.commit()
    return content.body
Exemplo n.º 7
0
def people():

    people_data = []
    all_column = People_flow.query.all()

    if request.method == "POST":
        people_data = []
        people_data = request.json

        counts = People_flow()
        counts.count = float(people_data["people_float"])
        counts.date = datetime.datetime.now()

        db_session.add(counts)
        db_session.commit()

    return render_template("people.html",
                           info=people_data,
                           all_column=all_column)
Exemplo n.º 8
0
from flaski.database import init_db
from flaski.database import db_session
from flaski.models import Shop, Product
import json

f = open("english_shops.json", 'r')
json_data_all = json.load(f)
for index, shop_name in enumerate(json_data_all):
    # insert shop
    shop = Shop(shop_name, index + 1)
    db_session.add(shop)
    db_session.commit()
    for json_data in json_data_all[shop_name]:
        # insert product
        json_data['shops_id'] = index + 1
        product = Product(**json_data)
        db_session.add(product)
        db_session.commit()
Exemplo n.º 9
0
 def create_new_product_with_json(self, product_json):
     product = Product(**product_json)
     db_session.add(product)
     db_session.commit()
     return product
Exemplo n.º 10
0
 def create_new_product(self, shops_id=None):
     product_json = self.build_product_json(shops_id)
     product = Product(**product_json)
     db_session.add(product)
     db_session.commit()
     return product
Exemplo n.º 11
0
 def create_new_shop(self):
     shop_json = self.build_shop_json()
     shop = Shop(**shop_json)
     db_session.add(shop)
     db_session.commit()
     return shop
Exemplo n.º 12
0
# -*- coding: utf-8 -*-

from flaski.database import init_db
from flaski.database import db_session
from flaski.models import WikiContent

# init_dbでwikicontentsテーブル作成
# init_db()

# idは連番。title、textを指定。dateは日時が勝手に入る(model.pyのデフォルト設定により)。
c1 = WikiContent("Flask", "micro framework")  # カラム1:'Flask' カラム2:'micro framework'を指定してインスタンス作成
db_session.add(c1)                            # insert実行
db_session.commit()                           # commit実行
c2 = WikiContent("python", "pppython")        # 以下同上
c3 = WikiContent("kobito", "kakure-momojiri")
db_session.add(c2)
db_session.add(c3)
db_session.commit()