Skip to content

Commit

Permalink
Merge pull request #6750 from PennyDreadfulMTG/fetchtools
Browse files Browse the repository at this point in the history
Give decks api ability to request tournament decks only.
  • Loading branch information
vorpal-buildbot committed Nov 7, 2019
2 parents 2025e99 + a5de043 commit ca59787
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 2 additions & 0 deletions decksite/api.py
Expand Up @@ -46,6 +46,8 @@ def decks_api() -> Response:
where = query.exclude_active_league_runs()
if request.args.get('deckType') == 'league':
where = f"({where}) AND ct.name = 'League'"
elif request.args.get('deckType') == 'tournament':
where = f"({where}) AND ct.name = 'Gatherling'"
total = deck.load_decks_count(where=where, season_id=season_id)
pages = ceil(total / page_size) - 1 # 0-indexed
ds = deck.load_decks(where=where, order_by=order_by, limit=limit, season_id=season_id)
Expand Down
1 change: 1 addition & 0 deletions decksite/templates/decks.mustache
Expand Up @@ -11,4 +11,5 @@
data-show-legal-seasons="{{#show_legal_seasons}}1{{/show_legal_seasons}}"
data-show-omw="{{#show_omw}}1{{/show_omw}}"
data-season-id="{{season_id}}"
data-tournament-only="{{#tournament_only}}1{{/tournament_only}}"
</section>
10 changes: 2 additions & 8 deletions decksite/view.py
Expand Up @@ -51,6 +51,7 @@ def __init__(self) -> None:
self.tournaments: List[Container] = []
self.content_class = self.__class__.__name__.lower()
self.page_size = request.cookies.get('page_size', 20)
self.tournament_only = False

def season_id(self) -> int:
return get_season_id()
Expand Down Expand Up @@ -165,14 +166,7 @@ def prepare_cards(self) -> None:
self.prepare_card(c)

def prepare_card(self, c: Card) -> None:
try:
tournament_only = self.tournament_only #type: ignore
# mypy complains we haven't declared tournament_only, but that's fine since we're
# catching the error if it isn't defined by a subclass
except AttributeError:
tournament_only = False

if tournament_only:
if self.tournament_only:
c.url = url_for('.card_tournament', name=c.name)
else:
c.url = url_for('.card', name=c.name)
Expand Down
8 changes: 7 additions & 1 deletion shared_web/static/js/index.jsx
Expand Up @@ -32,7 +32,13 @@ class DeckTable extends React.Component {

loadDecks() {
const {page, pageSize, sortBy, sortOrder} = this.state;
Axios.get("/api/decks/", {"params": { deckType: this.props.leagueOnly ? "league" : "all", page, pageSize, sortBy, sortOrder, "seasonId": this.props.seasonId }})
let deckType = "all";
if (this.props.leagueOnly) {
deckType = "league";
} else if (this.props.tournamentOnly) {
deckType = "tournament";
}
Axios.get("/api/decks/", {"params": { deckType, page, pageSize, sortBy, sortOrder, "seasonId": this.props.seasonId }})
.then(
(response) => { this.setState({"decks": response.data.decks, "pages": response.data.pages}); PD.initTables(); },
(error) => { this.setState({ error }); }
Expand Down

0 comments on commit ca59787

Please sign in to comment.