Ejemplo n.º 1
0
def index():
    if request.method == 'GET':
        if "user_name" in session:
            name = session["user_name"]
            posts = Post.query.order_by(Post.due, Post.title).all()
            all_user = User.query.order_by(User.user_name).all()
            title_name = 'index'

            return render_template("index.html",
                                   name=name,
                                   posts=posts,
                                   all_user=all_user,
                                   today=date.today(),
                                   title_name=title_name)
        else:
            return redirect(url_for("top", status="logout"))
    else:
        title = request.form.get('title')
        detail = request.form.get('detail')
        due = request.form.get('due')
        due = datetime.strptime(due, '%Y-%m-%d')
        user_name = session['user_name']
        new_post = Post(title=title,
                        detail=detail,
                        due=due,
                        user_name=user_name)
        db_session.add(new_post)
        db_session.commit()
        db_session.close()
        return redirect('/index')
Ejemplo n.º 2
0
def update(id):
    post = Post.query.get(id)
    if request.method == 'GET':
        return render_template('update.html', post=post)
    else:
        post.title = request.form.get('title')
        post.detail = request.form.get('detail')
        post.due = datetime.strptime(request.form.get('due'), '%Y-%m-%d')
        db_session.commit()
        db_session.close()
        return redirect('/')

    return render_template('detail.html', post=post)
Ejemplo n.º 3
0
def registar():
    user_name = request.form["user_name"]
    user = User.query.filter_by(user_name=user_name).first()
    if user:
        return redirect(url_for("newcomer", status="exist_user"))
    else:
        password = request.form["password"]
        hashed_password = sha256(
            (user_name + password + key.SALT).encode("utf-8")).hexdigest()
        user = User(user_name, hashed_password)
        db_session.add(user)
        db_session.commit()
        db_session.close()
        session["user_name"] = user_name
        return redirect(url_for("index"))
Ejemplo n.º 4
0
def info2():
    global addr2
    addr2 = str(request.form['addr2'])
    addr2 = addr2.split()
    addr2 = set(addr2)
    counted = len(list(addr | addr2))
    counted = int(counted / 0.7366)
    print(counted)

    if counted < 0:
        counted = 0

    current = SensorCurrent.query.first()
    current.j_merged_num = int(counted)
    db_session.add(current)
    db_session.commit()
    db_session.close()
    return render_template('index.html', addr2=addr2)
Ejemplo n.º 5
0
def getCurrData():
    users = db_session.query(SensorCurrent).first()

    j = users.j_merged_num
    z = users.z_merged_num
    date = datetime.now()

    print(j, z, date)
    data = SensorCurrent(j ,z , date)

    db_session.add(data)
    db_session.commit()
    db_session.close()
    people = SensorCurrent.query.first()

    json_data = {
        'j_merged_num': people.j_merged_num,
        'z_merged_num': people.z_merged_num
    }

    print(json_data)
    return jsonify(Result=json.dumps(json_data))
Ejemplo n.º 6
0
def delete(id):
    post = Post.query.get(id)
    db_session.delete(post)
    db_session.commit()
    db_session.close()
    return redirect('/index')
Ejemplo n.º 7
0
def session_clear(exception):
    if exception and db_session.is_active:
        db_session.rollback()
    else:
        db_session.commit()
    db_session.close()
Ejemplo n.º 8
0
from flask import Flask, render_template, request, json, jsonify
from models.models import SensorCurrent
from models.database import db_session

print("レコード削除中...")
db_session.query(SensorCurrent).delete()
db_session.commit()
db_session.close()

print("削除完了")
print("初期データ挿入中...")

# 初期データ
data = SensorCurrent(999, 999)
db_session.add(data)
db_session.commit()
db_session.close()

print("挿入完了")

# users = db_session.query(SensorCurrent).all()

# for user in users:
#     j = user.j_merged_num
#     z = user.z_merged_num
#     date = user.date
#     print(j, z, date.strftime('%Y-%m-%d %H:%M:%S'))

# print("\n--------------------\n")

# for user in users: