[boardgames] Format board game data
This commit is contained in:
@ -103,6 +103,35 @@ class BoardGameLogData(BaseLogData, LongPlayLogData):
|
||||
)
|
||||
return ""
|
||||
|
||||
def as_html(self) -> str:
|
||||
html_parts = []
|
||||
|
||||
if self.board:
|
||||
html_parts.append(f'<div class="boardgame-board">{self.board}</div>')
|
||||
|
||||
if self.location:
|
||||
html_parts.append(f'<div class="boardgame-location">{self.location}</div>')
|
||||
|
||||
if self.players:
|
||||
players_html = []
|
||||
for player_data in self.players:
|
||||
player = BoardGameScoreLogData(**player_data)
|
||||
player_info = player.name
|
||||
if player.score:
|
||||
player_info += f" ({player.score})"
|
||||
if player.win:
|
||||
player_info += " 🏆"
|
||||
if player.new:
|
||||
player_info += " (new)"
|
||||
players_html.append(
|
||||
f'<div class="boardgame-player">{player_info}</div>'
|
||||
)
|
||||
html_parts.append(
|
||||
f'<div class="boardgame-players">{"".join(players_html)}</div>'
|
||||
)
|
||||
|
||||
return "".join(html_parts)
|
||||
|
||||
@classmethod
|
||||
def override_fields(cls) -> dict:
|
||||
fields = {}
|
||||
@ -262,7 +291,6 @@ class BoardGame(ScrobblableMixin):
|
||||
def fix_metadata(self, data: dict = {}, force_update=False) -> None:
|
||||
|
||||
if not self.published_date or force_update:
|
||||
|
||||
if not data:
|
||||
data = lookup_boardgame_from_bgg(str(self.bggeek_id))
|
||||
|
||||
|
||||
@ -71,7 +71,7 @@
|
||||
<tr>
|
||||
<td><a href={{scrobble.get_absolute_url}}>{{scrobble.local_timestamp}}</a></td>
|
||||
<td>{{scrobble.logdata.location }}</td>
|
||||
<td>{% if scrobble.logdata.player_log %}{{scrobble.logdata.player_log}}{% else %}No data{% endif %}</td>
|
||||
<td>{% if scrobble.logdata.player_log %}{{scrobble.logdata.as_html|safe }}{% else %}No data{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
@ -28,6 +28,13 @@
|
||||
<p>Rate: {{object.logdata.avg_seconds_per_page}}s per page</p>
|
||||
{% endif %}
|
||||
|
||||
{% if object.media_type == "BoardGame" and object.logdata.as_html %}
|
||||
<div class="mb-3">
|
||||
<h5>Game Details</h5>
|
||||
{{ object.logdata.as_html|safe }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<button class="btn btn-secondary mb-3" type="button" data-bs-toggle="collapse" data-bs-target="#editLogForm">
|
||||
Edit Log
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user