update trade acceptance styling and layout, and also trade acceptance update/details page. fixes #16
This commit is contained in:
parent
1c95ccfff7
commit
5fbe80e83a
14 changed files with 257 additions and 139 deletions
|
|
@ -100,7 +100,6 @@ class TradeOffer(models.Model):
|
|||
# Use super().save() here to avoid recursion.
|
||||
super(TradeOffer, self).save(update_fields=["rarity_level", "rarity_icon"])
|
||||
|
||||
# New derived properties for available cards
|
||||
@property
|
||||
def have_cards_available(self):
|
||||
# Returns the list of have_cards (through objects) that still have available quantity.
|
||||
|
|
@ -136,6 +135,10 @@ class TradeOfferHaveCard(models.Model):
|
|||
quantity = models.PositiveIntegerField(default=1)
|
||||
qty_accepted = models.PositiveIntegerField(default=0, editable=False)
|
||||
|
||||
@property
|
||||
def qty_available(self):
|
||||
return self.quantity - self.qty_accepted
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.card.name} x{self.quantity} (Accepted: {self.qty_accepted})"
|
||||
|
||||
|
|
@ -166,6 +169,10 @@ class TradeOfferWantCard(models.Model):
|
|||
quantity = models.PositiveIntegerField(default=1)
|
||||
qty_accepted = models.PositiveIntegerField(default=0, editable=False)
|
||||
|
||||
@property
|
||||
def qty_available(self):
|
||||
return self.quantity - self.qty_accepted
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.card.name} x{self.quantity} (Accepted: {self.qty_accepted})"
|
||||
|
||||
|
|
@ -246,6 +253,17 @@ class TradeAcceptance(models.Model):
|
|||
AcceptanceState.THANKED_BY_BOTH: "Send Thanks",
|
||||
}
|
||||
|
||||
ALTERNATE_ACTION_LABELS_2 = {
|
||||
AcceptanceState.REJECTED_BY_INITIATOR: "Rejected this Trade",
|
||||
AcceptanceState.REJECTED_BY_ACCEPTOR: "Rejected this Trade",
|
||||
AcceptanceState.ACCEPTED: "Accepted this Trade",
|
||||
AcceptanceState.SENT: "Sent the Card",
|
||||
AcceptanceState.RECEIVED: "Received the Card and Responded",
|
||||
AcceptanceState.THANKED_BY_INITIATOR: "Sent Thanks",
|
||||
AcceptanceState.THANKED_BY_ACCEPTOR: "Sent Thanks",
|
||||
AcceptanceState.THANKED_BY_BOTH: "Sent Thanks",
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def get_action_label_for_state(cls, state_value):
|
||||
"""
|
||||
|
|
@ -262,6 +280,46 @@ class TradeAcceptance(models.Model):
|
|||
"""
|
||||
return self.get_action_label_for_state(self.state)
|
||||
|
||||
@property
|
||||
def next_action_label(self):
|
||||
"""
|
||||
Returns what the next action label would be based on the current state.
|
||||
"""
|
||||
if self.state == self.AcceptanceState.ACCEPTED:
|
||||
return self.get_action_label_for_state(self.AcceptanceState.SENT)
|
||||
elif self.state == self.AcceptanceState.SENT:
|
||||
return self.get_action_label_for_state(self.AcceptanceState.RECEIVED)
|
||||
elif self.state == self.AcceptanceState.RECEIVED or self.state == self.AcceptanceState.THANKED_BY_ACCEPTOR or self.state == self.AcceptanceState.THANKED_BY_INITIATOR:
|
||||
return self.get_action_label_for_state(self.AcceptanceState.THANKED_BY_BOTH)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_action_label_for_state_2(cls, state_value):
|
||||
"""
|
||||
Returns the alternate action label for the provided state_value.
|
||||
If no alternate label exists, falls back to the default label.
|
||||
"""
|
||||
default = dict(cls.AcceptanceState.choices).get(state_value, state_value)
|
||||
return cls.ALTERNATE_ACTION_LABELS_2.get(state_value, default)
|
||||
|
||||
@property
|
||||
def action_label_2(self):
|
||||
"""
|
||||
For the current acceptance state, return the alternate action label.
|
||||
"""
|
||||
return self.get_action_label_for_state_2(self.state)
|
||||
|
||||
@property
|
||||
def is_initiator_state(self):
|
||||
return self.state in [self.AcceptanceState.SENT.value, self.AcceptanceState.THANKED_BY_INITIATOR.value, self.AcceptanceState.THANKED_BY_BOTH.value]
|
||||
|
||||
@property
|
||||
def is_acceptor_state(self):
|
||||
return self.state in [self.AcceptanceState.ACCEPTED.value, self.AcceptanceState.RECEIVED.value, self.AcceptanceState.THANKED_BY_ACCEPTOR.value, self.AcceptanceState.THANKED_BY_BOTH.value]
|
||||
|
||||
|
||||
@property
|
||||
def is_completed(self):
|
||||
return self.state in {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue