Skip to content

Commit

Permalink
Lots of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
spurll committed Nov 22, 2018
1 parent c692bf7 commit 1fc0222
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
14 changes: 10 additions & 4 deletions goodplays/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ def parse_gb_game(gb):
# Super Mario Bros.) Maybe use stubs?
result = platform_gb(platform.get('id'))
# TODO: This is also dangerous because what if a search results in
# multiple games with overlapping platforms? We'll end up with
# multiple instances of each platform before any of them are added
# to the DB, then when we go to add them we'll get integrity errors
if result:
platforms.append(result)
"""
Expand All @@ -48,6 +44,13 @@ def parse_gb_game(gb):
# the alternative is extremely expensive, so just update the stubs later
platforms = map(existing_or_parse_platform, gb.get('platforms', {}))

# This may be dangerous: what if a search result returns multiple games
# with overlapping platforms? We may end up with multiple instances of each
# platform (because it won't be in the DB yet) before any of them are
# committed, then end up with integrity/nonunique errors on commit.
# (Edit: Turns out that so long as it's all in one session, which it seems
# to be, this works fine!)

return Game(
name=gb.get('name'),
description=gb.get('deck'),
Expand Down Expand Up @@ -169,6 +172,7 @@ def search_gb(query):
if error:
print(error)
else:
# TODO: Don't map unless you want them added to the session!
return map(parse_gb_game, results)


Expand All @@ -178,6 +182,7 @@ def platform_gb(gb_id):
if error:
print(error)
else:
# TODO: Don't map unless you want them added to the session!
return parse_gb_platform(results)


Expand All @@ -192,6 +197,7 @@ def platforms_gb(query):
if error:
print(error)
else:
# TODO: Don't map unless you want them added to the session!
return map(parse_gb_platform, results)


Expand Down
8 changes: 4 additions & 4 deletions goodplays/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Platform(db.Model):
image_url = db.Column(db.String)
games = db.relationship(
'Game',
backref='platform',
back_populates='platforms',
secondary=GamePlatform,
lazy='dynamic'
)
Expand All @@ -100,7 +100,7 @@ class Game(db.Model):
image_url = db.Column(db.String)
platforms = db.relationship(
'Platform',
backref='game',
back_populates='games',
secondary=GamePlatform,
lazy='dynamic'
)
Expand Down Expand Up @@ -133,7 +133,7 @@ class Tag(db.Model):
name = db.Column(db.String, unique=True)
plays = db.relationship(
'Play',
backref='tag',
back_populates='tags',
secondary=PlayTag,
lazy='dynamic'
)
Expand All @@ -152,7 +152,7 @@ class Play(db.Model):
comments = db.Column(db.String)
tags = db.relationship(
'Tag',
backref='play',
back_populates='plays',
secondary=PlayTag,
lazy='dynamic'
)
Expand Down
15 changes: 13 additions & 2 deletions goodplays/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tfoot { font-weight: bold; font-variant: small-caps; }

#content {
width: 100%;
max-width: 500px;
max-width: 700px;
margin: auto;
padding-top: 10px;
}
Expand All @@ -52,7 +52,7 @@ tfoot { font-weight: bold; font-variant: small-caps; }
}

#search {
width: 500px;
width: 700px;
margin: auto;
text-align: center;
}
Expand Down Expand Up @@ -106,6 +106,17 @@ a:visited { text-decoration: none; color: #888888; }
a:hover { text-decoration: none; color: #ffffff; }
a:active { text-decoration: none; color: #888888; }

img.art {
margin: auto;
max-height: 512px;
max-width: 512px;
}

img.art.small {
max-height: 64px;
max-width: 64px;
}

form {
margin: 0;
}
Expand Down
4 changes: 2 additions & 2 deletions goodplays/list.html → goodplays/templates/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
<tbody>
{% for game in games %}
<tr id="{{ game.id }}">
<td class="art"><img class="art" url="{{ game.art_url if game.art_url else url_for('static', filename='default.png')}}" /></td>
<td class="art"><img class="art small" src="{{ game.image_url if game.image_url else url_for('static', filename='default.png')}}" /></td>
<td class="name">{{ game.name }}</td>
<td class="added">{{ game.added }}</td>
<td class="platforms">{{ ", ".join(game.platforms.all()) }}</td>
<td class="platforms">{{ game.platforms|map(attribute="abbreviation")|join(", ") }}</td>
<td class="rating">{{ "&#9733" * round(game.rating) + "&#9734" * (5 - round(game.rating)) if game.rating else ""}}</td>
</tr>
{% endfor %}
Expand Down
2 changes: 2 additions & 0 deletions goodplays/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def index():
# TODO: on game details page, "Update" button (for games linked with Giant
# Bomb)

# TODO: if game not linked to Giant Bomb, a button to link it

# TODO: on platform details page, "Update" button (for platforms with a gb_id)


Expand Down

0 comments on commit 1fc0222

Please sign in to comment.