Fix trade offer png generation (fixes #27).

- Updated `card_badge.html` to adjust width properties for better layout consistency.
- Modified `trade_offer_png.html` to change padding for improved visual appearance.
- Enhanced `bubble_up_trade_offer_updates` signal to delete cached images when related instances change, ensuring up-to-date content.
- Updated `TradeOfferPNGView` to pass the request context when rendering the template, improving compatibility with Django's template rendering.
- Refactored `render_trade_offer_png` to use constants for dimensions and improve readability, while also updating context handling for better integration.
This commit is contained in:
badblocks 2025-05-05 21:50:52 -07:00
parent 9c41f63247
commit 9b3b3d099f
5 changed files with 40 additions and 17 deletions

View file

@ -271,8 +271,12 @@ def trade_acceptance_reputation_delete(sender, instance, **kwargs):
@receiver(post_delete, sender=TradeAcceptance)
def bubble_up_trade_offer_updates(sender, instance, **kwargs):
"""
Bubble up updates to the TradeOffer model when TradeOfferHaveCard, TradeOfferWantCard,
or TradeAcceptance instances are created, updated, or deleted.
Bubble up updated_at to the TradeOffer model when related instances change.
Also invalidates any cached image by deleting the file.
"""
if instance.trade_offer:
instance.trade_offer.save(update_fields=['updated_at'])
trade_offer = getattr(instance, 'trade_offer', None)
if trade_offer and trade_offer.image:
trade_offer.image.delete(save=True) # deleting the image will trigger a save, which updates the updated_at field
elif trade_offer:
trade_offer.save(update_fields=['updated_at'])