When a user is thanking, check state to see if other user thanked first, if so switch new_state to THANKED_BY_BOTH. fixes #13
This commit is contained in:
parent
52663c83ef
commit
a83ce746b5
7 changed files with 35 additions and 42 deletions
|
|
@ -13,7 +13,7 @@ from django.conf import settings
|
|||
from django.template.loader import render_to_string
|
||||
from django.contrib.sites.models import Site
|
||||
|
||||
ACTIVE_STATES = [
|
||||
POSITIVE_STATES = [
|
||||
TradeAcceptance.AcceptanceState.ACCEPTED,
|
||||
TradeAcceptance.AcceptanceState.SENT,
|
||||
TradeAcceptance.AcceptanceState.RECEIVED,
|
||||
|
|
@ -70,14 +70,14 @@ def trade_acceptance_pre_save(sender, instance, **kwargs):
|
|||
def trade_acceptance_post_save(sender, instance, created, **kwargs):
|
||||
delta = 0
|
||||
if created:
|
||||
if instance.state in ACTIVE_STATES:
|
||||
if instance.state in POSITIVE_STATES:
|
||||
delta = 1
|
||||
else:
|
||||
old_state = getattr(instance, '_old_state', None)
|
||||
if old_state is not None:
|
||||
if old_state in ACTIVE_STATES and instance.state not in ACTIVE_STATES:
|
||||
if old_state in POSITIVE_STATES and instance.state not in POSITIVE_STATES:
|
||||
delta = -1
|
||||
elif old_state not in ACTIVE_STATES and instance.state in ACTIVE_STATES:
|
||||
elif old_state not in POSITIVE_STATES and instance.state in POSITIVE_STATES:
|
||||
delta = 1
|
||||
|
||||
if delta != 0:
|
||||
|
|
@ -88,7 +88,7 @@ def trade_acceptance_post_save(sender, instance, created, **kwargs):
|
|||
|
||||
@receiver(post_delete, sender=TradeAcceptance)
|
||||
def trade_acceptance_post_delete(sender, instance, **kwargs):
|
||||
if instance.state in ACTIVE_STATES:
|
||||
if instance.state in POSITIVE_STATES:
|
||||
delta = -1
|
||||
trade_offer = instance.trade_offer
|
||||
adjust_qty_for_trade_offer(trade_offer, instance.requested_card, side='have', delta=delta)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue