Compare commits
No commits in common. "b12b1501e76505682e7c86ee1d073da415c997da" and "86a1678f41dbc048034074f2ae3a8781969fe60c" have entirely different histories.
b12b1501e7
...
86a1678f41
@ -335,17 +335,21 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
Move the playlist rows given to to_row and below.
|
Move the playlist rows given to to_row and below.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# New thinking:
|
||||||
|
# Move relocated rows to correct place in mirror array
|
||||||
|
# Copy souurce to mirror around them
|
||||||
|
# Move mirror to original
|
||||||
|
# Fixup plr rownumbers and update db and display
|
||||||
|
# Signal rows have changed
|
||||||
|
|
||||||
|
# Prep
|
||||||
|
# modified_rows: List[int] = []
|
||||||
|
# moving_rows: dict[int, PlaylistRowData] = {}
|
||||||
new_playlist_rows: dict[int, PlaylistRowData] = {}
|
new_playlist_rows: dict[int, PlaylistRowData] = {}
|
||||||
|
|
||||||
# Move the from_row records from the playlist_rows dict to the
|
# Move the from_row records from the playlist_rows dict to the
|
||||||
# new_playlist_rows dict. The total number of elements in the
|
# new_playlist_rows dict
|
||||||
# playlist doesn't change, so check that adding the moved rows
|
next_to_row = to_row
|
||||||
# starting at to_row won't overshoot the end of the playlist.
|
|
||||||
if to_row + len(from_rows) > len(self.playlist_rows):
|
|
||||||
next_to_row = len(self.playlist_rows) - len(from_rows)
|
|
||||||
else:
|
|
||||||
next_to_row = to_row
|
|
||||||
|
|
||||||
for from_row in from_rows:
|
for from_row in from_rows:
|
||||||
new_playlist_rows[next_to_row] = self.playlist_rows[from_row]
|
new_playlist_rows[next_to_row] = self.playlist_rows[from_row]
|
||||||
del self.playlist_rows[from_row]
|
del self.playlist_rows[from_row]
|
||||||
@ -380,6 +384,7 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
self.playlist_rows[idx].plr_rownum = idx
|
self.playlist_rows[idx].plr_rownum = idx
|
||||||
# Update display
|
# Update display
|
||||||
self.invalidate_rows([idx])
|
self.invalidate_rows([idx])
|
||||||
|
print(f"Fixup {idx=}")
|
||||||
|
|
||||||
def refresh_data(self):
|
def refresh_data(self):
|
||||||
"""Populate dicts for data calls"""
|
"""Populate dicts for data calls"""
|
||||||
|
|||||||
@ -8,7 +8,8 @@ from sqlalchemy.orm import scoped_session, sessionmaker
|
|||||||
|
|
||||||
from app.models import Base, Tracks
|
from app.models import Base, Tracks
|
||||||
|
|
||||||
DB_CONNECTION = "mysql+mysqldb://musicmuster_testing:musicmuster_testing@localhost/dev_musicmuster_testing"
|
DB_CONNECTION = \
|
||||||
|
"mysql+mysqldb://musicmuster_testing:musicmuster_testing@localhost/dev_musicmuster_testing"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
|
|||||||
@ -75,117 +75,31 @@ def test_move_rows_test2(monkeypatch, Session):
|
|||||||
assert model.playlist_rows[row].note == str(3)
|
assert model.playlist_rows[row].note == str(3)
|
||||||
|
|
||||||
|
|
||||||
def test_move_rows_test3(monkeypatch, Session):
|
# def test_move_rows_test3(Session):
|
||||||
# move row 4 to row 3
|
# # move row 4 to row 3
|
||||||
|
# pass
|
||||||
monkeypatch.setattr(playlistmodel, "Session", Session)
|
|
||||||
|
|
||||||
with Session() as session:
|
|
||||||
model = create_model_with_playlist_rows(session, 11)
|
|
||||||
model.move_rows([4], 3)
|
|
||||||
|
|
||||||
# Check we have all rows and plr_rownums are correct
|
|
||||||
for row in range(model.rowCount()):
|
|
||||||
assert row in model.playlist_rows
|
|
||||||
assert model.playlist_rows[row].plr_rownum == row
|
|
||||||
if row not in [3, 4]:
|
|
||||||
assert model.playlist_rows[row].note == str(row)
|
|
||||||
elif row == 3:
|
|
||||||
assert model.playlist_rows[row].note == str(4)
|
|
||||||
elif row == 4:
|
|
||||||
assert model.playlist_rows[row].note == str(3)
|
|
||||||
|
|
||||||
|
|
||||||
def test_move_rows_test4(monkeypatch, Session):
|
# def test_move_rows_test4(Session):
|
||||||
# move row 4 to row 2
|
# # move row 4 to row 2
|
||||||
|
# pass
|
||||||
monkeypatch.setattr(playlistmodel, "Session", Session)
|
|
||||||
|
|
||||||
with Session() as session:
|
|
||||||
model = create_model_with_playlist_rows(session, 11)
|
|
||||||
model.move_rows([4], 2)
|
|
||||||
|
|
||||||
# Check we have all rows and plr_rownums are correct
|
|
||||||
for row in range(model.rowCount()):
|
|
||||||
assert row in model.playlist_rows
|
|
||||||
assert model.playlist_rows[row].plr_rownum == row
|
|
||||||
if row not in [2, 3, 4]:
|
|
||||||
assert model.playlist_rows[row].note == str(row)
|
|
||||||
elif row == 2:
|
|
||||||
assert model.playlist_rows[row].note == str(4)
|
|
||||||
elif row == 3:
|
|
||||||
assert model.playlist_rows[row].note == str(2)
|
|
||||||
elif row == 4:
|
|
||||||
assert model.playlist_rows[row].note == str(3)
|
|
||||||
|
|
||||||
|
|
||||||
def test_move_rows_test5(monkeypatch, Session):
|
# def test_move_rows_test5(Session):
|
||||||
# move rows [1, 4, 5, 10] → 8
|
# # move rows [1, 4, 5, 10] → 8
|
||||||
|
# pass
|
||||||
monkeypatch.setattr(playlistmodel, "Session", Session)
|
|
||||||
|
|
||||||
with Session() as session:
|
|
||||||
model = create_model_with_playlist_rows(session, 11)
|
|
||||||
model.move_rows([1, 4, 5, 10], 8)
|
|
||||||
|
|
||||||
# Check we have all rows and plr_rownums are correct
|
|
||||||
new_order = []
|
|
||||||
for row in range(model.rowCount()):
|
|
||||||
assert row in model.playlist_rows
|
|
||||||
assert model.playlist_rows[row].plr_rownum == row
|
|
||||||
new_order.append(int(model.playlist_rows[row].note))
|
|
||||||
assert new_order == [0, 2, 3, 6, 7, 8, 9, 1, 4, 5, 10]
|
|
||||||
|
|
||||||
|
|
||||||
def test_move_rows_test6(monkeypatch, Session):
|
# def test_move_rows_test6(Session):
|
||||||
# move rows [3, 6] → 5
|
# # move rows [3, 6] → 5
|
||||||
|
# pass
|
||||||
monkeypatch.setattr(playlistmodel, "Session", Session)
|
|
||||||
|
|
||||||
with Session() as session:
|
|
||||||
model = create_model_with_playlist_rows(session, 11)
|
|
||||||
model.move_rows([3, 6], 5)
|
|
||||||
|
|
||||||
# Check we have all rows and plr_rownums are correct
|
|
||||||
new_order = []
|
|
||||||
for row in range(model.rowCount()):
|
|
||||||
assert row in model.playlist_rows
|
|
||||||
assert model.playlist_rows[row].plr_rownum == row
|
|
||||||
new_order.append(int(model.playlist_rows[row].note))
|
|
||||||
assert new_order == [0, 1, 2, 4, 5, 3, 6, 7, 8, 9, 10]
|
|
||||||
|
|
||||||
|
|
||||||
def test_move_rows_test7(monkeypatch, Session):
|
# def test_move_rows_test7(Session):
|
||||||
# move rows [3, 5, 6] → 8
|
# # move rows [3, 5, 6] → 8
|
||||||
|
# pass
|
||||||
monkeypatch.setattr(playlistmodel, "Session", Session)
|
|
||||||
|
|
||||||
with Session() as session:
|
|
||||||
model = create_model_with_playlist_rows(session, 11)
|
|
||||||
model.move_rows([3, 5, 6], 8)
|
|
||||||
|
|
||||||
# Check we have all rows and plr_rownums are correct
|
|
||||||
new_order = []
|
|
||||||
for row in range(model.rowCount()):
|
|
||||||
assert row in model.playlist_rows
|
|
||||||
assert model.playlist_rows[row].plr_rownum == row
|
|
||||||
new_order.append(int(model.playlist_rows[row].note))
|
|
||||||
assert new_order == [0, 1, 2, 4, 7, 8, 9, 10, 3, 5, 6]
|
|
||||||
|
|
||||||
|
|
||||||
def test_move_rows_test8(monkeypatch, Session):
|
# def test_move_rows_test8(Session):
|
||||||
# move rows [7, 8, 10] → 5
|
# # move rows [7, 8, 10] → 5
|
||||||
|
# pass
|
||||||
monkeypatch.setattr(playlistmodel, "Session", Session)
|
|
||||||
|
|
||||||
with Session() as session:
|
|
||||||
model = create_model_with_playlist_rows(session, 11)
|
|
||||||
model.move_rows([7, 8, 10], 5)
|
|
||||||
|
|
||||||
# Check we have all rows and plr_rownums are correct
|
|
||||||
new_order = []
|
|
||||||
for row in range(model.rowCount()):
|
|
||||||
assert row in model.playlist_rows
|
|
||||||
assert model.playlist_rows[row].plr_rownum == row
|
|
||||||
new_order.append(int(model.playlist_rows[row].note))
|
|
||||||
assert new_order == [0, 1, 2, 3, 4, 7, 8, 10, 5, 6, 9]
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user