updated solution
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -8,28 +8,29 @@ from utils.logger import (
|
||||
log_content_duration_changed, log_content_added
|
||||
)
|
||||
|
||||
def create_group(name, player_ids):
|
||||
def create_group(name, player_ids, orientation='Landscape'):
|
||||
"""
|
||||
Create a new group with the given name and add selected players to it.
|
||||
Clears individual playlists of players and locks them to the group.
|
||||
Create a new group with the given name, orientation, and add selected players.
|
||||
Only players with the same orientation can be added.
|
||||
"""
|
||||
new_group = Group(name=name)
|
||||
# Check all players have the same orientation
|
||||
for player_id in player_ids:
|
||||
player = Player.query.get(player_id)
|
||||
if player and player.orientation != orientation:
|
||||
raise ValueError(f"Player '{player.username}' has orientation '{player.orientation}', which does not match group orientation '{orientation}'.")
|
||||
|
||||
new_group = Group(name=name, orientation=orientation)
|
||||
db.session.add(new_group)
|
||||
db.session.flush() # Get the group ID
|
||||
|
||||
|
||||
# Add players to the group and lock them
|
||||
for player_id in player_ids:
|
||||
player = Player.query.get(player_id)
|
||||
if player:
|
||||
# Add player to group
|
||||
new_group.players.append(player)
|
||||
|
||||
# Delete player's individual playlist
|
||||
Content.query.filter_by(player_id=player.id).delete()
|
||||
|
||||
# Lock player to this group
|
||||
player.locked_to_group_id = new_group.id
|
||||
|
||||
|
||||
db.session.commit()
|
||||
log_group_created(name)
|
||||
return new_group
|
||||
@@ -106,7 +107,7 @@ def delete_group(group_id):
|
||||
db.session.commit()
|
||||
log_group_deleted(group_name)
|
||||
|
||||
def add_player(username, hostname, password, quickconnect_password):
|
||||
def add_player(username, hostname, password, quickconnect_password, orientation='Landscape'):
|
||||
"""
|
||||
Add a new player with the given details.
|
||||
"""
|
||||
@@ -120,7 +121,8 @@ def add_player(username, hostname, password, quickconnect_password):
|
||||
username=username,
|
||||
hostname=hostname,
|
||||
password=hashed_password,
|
||||
quickconnect_password=hashed_quickconnect
|
||||
quickconnect_password=hashed_quickconnect,
|
||||
orientation=orientation
|
||||
)
|
||||
|
||||
db.session.add(new_player)
|
||||
|
||||
Reference in New Issue
Block a user