[boardgames] Fix lookups using BGG library
This commit is contained in:
@ -321,6 +321,8 @@ class BoardGame(ScrobblableMixin):
|
|||||||
) -> "BoardGame":
|
) -> "BoardGame":
|
||||||
"""Given a Lookup ID (either BGG or BGA ID), return a board game object"""
|
"""Given a Lookup ID (either BGG or BGA ID), return a board game object"""
|
||||||
game = cls.objects.filter(bggeek_id=lookup_id).first()
|
game = cls.objects.filter(bggeek_id=lookup_id).first()
|
||||||
|
if not game:
|
||||||
|
game = cls.objects.filter(title=lookup_id).first()
|
||||||
|
|
||||||
if game:
|
if game:
|
||||||
logger.info(
|
logger.info(
|
||||||
@ -329,17 +331,18 @@ class BoardGame(ScrobblableMixin):
|
|||||||
)
|
)
|
||||||
return game
|
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"))
|
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:
|
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", [])
|
mechanics = bgg_data.pop("mechanics", [])
|
||||||
designers = bgg_data.pop("designers", [])
|
designers = bgg_data.pop("designers", [])
|
||||||
categories = bgg_data.pop("categories", [])
|
categories = bgg_data.pop("categories", [])
|
||||||
publishers = bgg_data.pop("publishers", [])
|
publishers = bgg_data.pop("publishers", [])
|
||||||
|
publisher = bgg_data.pop("publisher", [])
|
||||||
cover_url = bgg_data.pop("cover_url")
|
cover_url = bgg_data.pop("cover_url")
|
||||||
|
|
||||||
game = cls.objects.create(**bgg_data)
|
game = cls.objects.create(**bgg_data)
|
||||||
@ -350,6 +353,11 @@ class BoardGame(ScrobblableMixin):
|
|||||||
game.no_points = data.get("noPoints", False)
|
game.no_points = data.get("noPoints", False)
|
||||||
game.uses_teams = data.get("useTeams", False)
|
game.uses_teams = data.get("useTeams", False)
|
||||||
game.bgstats_id = data.get("uuid", None)
|
game.bgstats_id = data.get("uuid", None)
|
||||||
|
if publisher:
|
||||||
|
publisher, _ = BoardGamePublisher.objects.get_or_create(
|
||||||
|
name=publisher
|
||||||
|
)
|
||||||
|
game.publisher = publisher
|
||||||
game.save()
|
game.save()
|
||||||
|
|
||||||
if designers:
|
if designers:
|
||||||
|
|||||||
@ -14,7 +14,7 @@ def lookup_boardgame_from_bgg(
|
|||||||
if lookup_id:
|
if lookup_id:
|
||||||
game = bgg.game(game_id=lookup_id)
|
game = bgg.game(game_id=lookup_id)
|
||||||
else:
|
else:
|
||||||
game = bgg.game(lookup_id)
|
game = bgg.game(title)
|
||||||
|
|
||||||
if game:
|
if game:
|
||||||
game_dict["title"] = game.name
|
game_dict["title"] = game.name
|
||||||
@ -34,5 +34,7 @@ def lookup_boardgame_from_bgg(
|
|||||||
game_dict["categories"] = game.categories
|
game_dict["categories"] = game.categories
|
||||||
game_dict["designers"] = game.designers
|
game_dict["designers"] = game.designers
|
||||||
game_dict["publishers"] = game.publishers
|
game_dict["publishers"] = game.publishers
|
||||||
|
if game.publishers:
|
||||||
|
game_dict["publisher"] = game.publishers[0]
|
||||||
|
|
||||||
return game_dict
|
return game_dict
|
||||||
|
|||||||
Reference in New Issue
Block a user