Bugfixes for emails and bugfixes for trade acceptance quantities being checked on create, closes #1

This commit is contained in:
badblocks 2025-04-08 00:59:40 -07:00
parent 32da8157a6
commit bd7a65975f
21 changed files with 95 additions and 86 deletions

View file

@ -58,6 +58,10 @@ def update_trade_offer_closed_status(trade_offer):
@receiver(pre_save, sender=TradeAcceptance)
def trade_acceptance_pre_save(sender, instance, **kwargs):
# Skip signal processing during raw fixture load or when saving a new instance
if kwargs.get("raw", False) or instance._state.adding:
return
if instance.pk:
old_instance = TradeAcceptance.objects.get(pk=instance.pk)
instance._old_state = old_instance.state
@ -98,9 +102,9 @@ def trade_acceptance_email_notification(sender, instance, created, **kwargs):
return
# check if were in debug mode
if settings.DEBUG:
print("DEBUG: skipping email notification in debug mode")
return
# if settings.DEBUG:
# print("DEBUG: skipping email notification in debug mode")
# return
acting_user = instance._actioning_user
state = instance.state
@ -126,14 +130,16 @@ def trade_acceptance_email_notification(sender, instance, created, **kwargs):
# Determine the non-acting party:
if instance.trade_offer.initiated_by == acting_user:
if instance.trade_offer.initiated_by.user.pk == acting_user.pk:
# The initiator made the change; notify the acceptor.
recipient_user = instance.accepted_by.user
else:
elif instance.accepted_by.user.pk == acting_user.pk:
# The acceptor made the change; notify the initiator.
recipient_user = instance.trade_offer.initiated_by.user
else:
return
is_initiator = instance.trade_offer.initiated_by == acting_user
is_initiator = instance.trade_offer.initiated_by.user.pk == acting_user.pk
email_context = {
"has_card": instance.requested_card,
@ -145,7 +151,7 @@ def trade_acceptance_email_notification(sender, instance, created, **kwargs):
"recipient_user_ign": instance.accepted_by.in_game_name if is_initiator else instance.trade_offer.initiated_by.in_game_name,
"acting_user_friend_code": instance.trade_offer.initiated_by.friend_code if is_initiator else instance.accepted_by.friend_code,
"is_initiator": is_initiator,
"domain": Site.objects.get_current().domain,
"domain": "https://" + Site.objects.get_current().domain,
"pk": instance.pk,
}
email_template = "email/trades/trade_update_" + state + ".txt"