Beispiel #1
0
def create_example_data():
    if not Cell.select():
        user = User(name='Example User', login_name='user', password='******')
        batman = User(name='Batman', login_name='batman', password='******')
        user.save()
        batman.save()

        board1 = Board(name='First')
        board2 = Board(name='Second')
        board3 = Board(name='Third')
        batman1 = Board(name='Batmobil')
        batman2 = Board(name='BatBarlang')
        batman3 = Board(name='BatRobin')

        board1.save()
        board2.save()
        board3.save()
        batman1.save()
        batman2.save()
        batman3.save()

        Boardstable.create(board=board1, user=user)
        Boardstable.create(board=board2, user=user)
        Boardstable.create(board=board3, user=user)

        Boardstable.create(board=batman1, user=batman)
        Boardstable.create(board=batman2, user=batman)
        Boardstable.create(board=batman3, user=batman)

        Cell.create(text="Rocket",
                    name="Weapon",
                    order=1,
                    board=board1,
                    status=Status.get(Status.status == "new"))
        Cell.create(text="Pistol",
                    name="Weapon",
                    order=2,
                    board=board1,
                    status=Status.get(Status.status == "new"))
        Cell.create(text="Sword",
                    name="Weapon",
                    order=3,
                    board=board1,
                    status=Status.get(Status.status == "new"))
        Cell.create(text="Kalasnyikov",
                    name="Weapon",
                    order=1,
                    board=board1,
                    status=Status.get(Status.status == "progress"))
        Cell.create(text="Grenade",
                    name="Weapon",
                    order=1,
                    board=board1,
                    status=Status.get(Status.status == "done"))
def create_new_cell():
    cell_name = request.form['cell_title']
    boardid = request.form['boardid']
    if cell_name != "":
        query = Cell.select().join(Status).where((Status.status == 'new')
                                                 & (Cell.board == boardid))
        new_cell = Cell.create(name=cell_name,
                               status=1,
                               board=boardid,
                               order=(len(query) + 1))
    return jsonify({
        'id': new_cell.id,
        'name': new_cell.name,
        'order': new_cell.order
    })