[boardgames] Fix lookups using BGG library
All checks were successful
build & deploy / test (push) Successful in 1m52s
build & deploy / deploy (push) Successful in 22s

This commit is contained in:
2026-03-20 14:14:28 -04:00
parent 34a48c8c7b
commit e8f120f85e
2 changed files with 15 additions and 5 deletions

View File

@ -321,6 +321,8 @@ class BoardGame(ScrobblableMixin):
) -> "BoardGame":
"""Given a Lookup ID (either BGG or BGA ID), return a board game object"""
game = cls.objects.filter(bggeek_id=lookup_id).first()
if not game:
game = cls.objects.filter(title=lookup_id).first()
if game:
logger.info(
@ -329,17 +331,18 @@ class BoardGame(ScrobblableMixin):
)
return game
if data.get("name"):
if data.get("bggId"):
bgg_data = lookup_boardgame_from_bgg(lookup_id=data.get("bggId"))
elif data.get("name"):
bgg_data = lookup_boardgame_from_bgg(title=data.get("name"))
if data.get("bgg_id"):
bgg_data = lookup_boardgame_from_bgg(lookup_id=data.get("bgg_id"))
else:
bgg_data = lookup_boardgame_from_bgg(lookup_id=lookup_id)
bgg_data = lookup_boardgame_from_bgg(title=lookup_id)
mechanics = bgg_data.pop("mechanics", [])
designers = bgg_data.pop("designers", [])
categories = bgg_data.pop("categories", [])
publishers = bgg_data.pop("publishers", [])
publisher = bgg_data.pop("publisher", [])
cover_url = bgg_data.pop("cover_url")
game = cls.objects.create(**bgg_data)
@ -350,6 +353,11 @@ class BoardGame(ScrobblableMixin):
game.no_points = data.get("noPoints", False)
game.uses_teams = data.get("useTeams", False)
game.bgstats_id = data.get("uuid", None)
if publisher:
publisher, _ = BoardGamePublisher.objects.get_or_create(
name=publisher
)
game.publisher = publisher
game.save()
if designers:

View File

@ -14,7 +14,7 @@ def lookup_boardgame_from_bgg(
if lookup_id:
game = bgg.game(game_id=lookup_id)
else:
game = bgg.game(lookup_id)
game = bgg.game(title)
if game:
game_dict["title"] = game.name
@ -34,5 +34,7 @@ def lookup_boardgame_from_bgg(
game_dict["categories"] = game.categories
game_dict["designers"] = game.designers
game_dict["publishers"] = game.publishers
if game.publishers:
game_dict["publisher"] = game.publishers[0]
return game_dict