def rearrange_same_statused_cells(newid, oldid, id_in_db):
    moved_cell = Cell.get(Cell.id == id_in_db)
    if newid > oldid:
        cells = Cell.select().where((Cell.order > oldid)
                                    & (Cell.order <= newid)
                                    & (Cell.board == moved_cell.board))
        for cell in cells:
            cell.order -= 1
            cell.save()
    else:
        cells = Cell.select().where((Cell.order < oldid)
                                    & (Cell.order >= newid)
                                    & (Cell.status == moved_cell.status)
                                    & (Cell.board == moved_cell.board))
        for cell in cells:
            cell.order += 1
            cell.save()
    moved_cell.order = newid
    moved_cell.save()
Ejemplo n.º 2
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 rearrange_different_statused_cells(newid, oldid, oldstatus, newstatus,
                                       id_in_db):
    moved_cell = Cell.get(Cell.id == id_in_db)
    # newStatused rearrange
    cells = Cell.select().where((Cell.status == Status.get(
        Status.status == newstatus)) & (Cell.board == moved_cell.board)
                                & (Cell.order >= newid))
    for cell in cells:
        cell.order += 1
        cell.save()
    # oldStatus rearrange
    cells = Cell.select().where((Cell.status == Status.get(
        Status.status == oldstatus)) & (Cell.board == moved_cell.board)
                                & (Cell.order > oldid))
    for cell in cells:
        cell.order -= 1
        cell.save()

    moved_cell.order = newid
    moved_cell.status = Status.get(Status.status == newstatus)
    moved_cell.save()
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
    })
def init_cell_list(board_id):
    cells = Cell.select().join(Board).where(Cell.board == board_id)
    Cell_list.cell_list.clear()
    for cell in cells:
        Cell_list.cell_list.append(cell_to_json(cell))