fix png generation to align with new card badges, fixes #2
This commit is contained in:
parent
a83ce746b5
commit
1cdeaa9bba
11 changed files with 27 additions and 32 deletions
|
|
@ -1,5 +1,5 @@
|
|||
from django import template
|
||||
|
||||
from math import ceil
|
||||
register = template.Library()
|
||||
|
||||
@register.inclusion_tag('templatetags/trade_offer.html', takes_context=True)
|
||||
|
|
@ -83,23 +83,18 @@ def action_button_class(state_value):
|
|||
|
||||
@register.inclusion_tag('templatetags/trade_offer_png.html', takes_context=True)
|
||||
def render_trade_offer_png(context, offer, show_friend_code=False):
|
||||
trade_offer_have_cards = list(offer.trade_offer_have_cards.all())
|
||||
trade_offer_want_cards = list(offer.trade_offer_want_cards.all())
|
||||
|
||||
have_cards_available = [
|
||||
card for card in trade_offer_have_cards
|
||||
if card.quantity > card.qty_accepted
|
||||
]
|
||||
want_cards_available = [
|
||||
card for card in trade_offer_want_cards
|
||||
if card.quantity > card.qty_accepted
|
||||
]
|
||||
have_cards_available = offer.have_cards_available
|
||||
want_cards_available = offer.want_cards_available
|
||||
|
||||
num_cards = max(len(have_cards_available), len(want_cards_available))
|
||||
expanded = (len(have_cards_available) + len(want_cards_available)) > 4
|
||||
if expanded:
|
||||
num_cards = ceil(num_cards / 2)
|
||||
image_height = (num_cards * 40) + 106
|
||||
# cards incl pad + header/footer
|
||||
if (len(have_cards_available) + len(want_cards_available)) >= 4:
|
||||
image_width = (4 * 160) + 160
|
||||
# cards incl pad + header/footer
|
||||
|
||||
if expanded:
|
||||
image_width = (4 * 160) + 110
|
||||
else:
|
||||
image_width = (2 * 160) + 92
|
||||
|
||||
|
|
@ -121,7 +116,7 @@ def render_trade_offer_png(context, offer, show_friend_code=False):
|
|||
'friend_code': offer.initiated_by.friend_code,
|
||||
'show_friend_code': show_friend_code,
|
||||
'num_cards_available': len(have_cards_available) + len(want_cards_available),
|
||||
'expanded': (len(have_cards_available) + len(want_cards_available)) >= 4,
|
||||
'expanded': expanded,
|
||||
'image_width': image_width,
|
||||
'image_height': image_height,
|
||||
'base_url': base_url,
|
||||
|
|
|
|||
|
|
@ -525,7 +525,7 @@ class TradeOfferPNGView(View):
|
|||
|
||||
# if query string has "debug=true", render the HTML instead of the PNG
|
||||
if request.GET.get("debug") == "html":
|
||||
return render(request, "trades/trade_offer_png_debug.html", {"html": html})
|
||||
return render(request, "templatetags/trade_offer_png.html", tag_context)
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue