From 2451a6c63012eff654c7e71555b60926877c1dc5 Mon Sep 17 00:00:00 2001
From: badbl0cks <4161747+badbl0cks@users.noreply.github.com>
Date: Tue, 18 Mar 2025 14:21:18 -0700
Subject: [PATCH] Update trade offer acceptance update template buttons to have
better text and styling
---
.../trades/trade_acceptance_update.html | 19 +++++++-----
trades/models.py | 29 +++++++++++++++++++
trades/templatetags/trade_offer_tags.py | 27 ++++++++++++++++-
3 files changed, 67 insertions(+), 8 deletions(-)
diff --git a/theme/templates/trades/trade_acceptance_update.html b/theme/templates/trades/trade_acceptance_update.html
index 6c26fd0..8783937 100644
--- a/theme/templates/trades/trade_acceptance_update.html
+++ b/theme/templates/trades/trade_acceptance_update.html
@@ -52,15 +52,20 @@
Select an action:
{% if form.fields.state.choices %}
- {% for state_value, state_label in form.fields.state.choices %}
-
- {% endfor %}
+
+ {% for state_value, state_label in form.fields.state.choices %}
+
+ {% endfor %}
+
{% else %}
No available actions.
+
{% endif %}
diff --git a/trades/models.py b/trades/models.py
index c8f776c..12e2978 100644
--- a/trades/models.py
+++ b/trades/models.py
@@ -143,6 +143,35 @@ class TradeAcceptance(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
+ # A mapping for alternate action labels
+ ALTERNATE_ACTION_LABELS = {
+ AcceptanceState.REJECTED_BY_INITIATOR: "Cancel This Trade",
+ AcceptanceState.REJECTED_BY_ACCEPTOR: "Cancel This Trade",
+ # Optionally add alternate labels for other states:
+ AcceptanceState.ACCEPTED: "Accept This Trade Offer",
+ AcceptanceState.SENT: "Mark as Sent",
+ AcceptanceState.RECEIVED: "Mark as Received",
+ AcceptanceState.THANKED_BY_INITIATOR: "Send Thanks",
+ AcceptanceState.THANKED_BY_ACCEPTOR: "Send Thanks",
+ AcceptanceState.THANKED_BY_BOTH: "Send Thanks",
+ }
+
+ @classmethod
+ def get_action_label_for_state(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.get(state_value, default)
+
+ @property
+ def action_label(self):
+ """
+ For the current acceptance state, return the alternate action label.
+ """
+ return self.get_action_label_for_state(self.state)
+
@property
def is_completed(self):
return self.state in {
diff --git a/trades/templatetags/trade_offer_tags.py b/trades/templatetags/trade_offer_tags.py
index 16b3799..75d3b48 100644
--- a/trades/templatetags/trade_offer_tags.py
+++ b/trades/templatetags/trade_offer_tags.py
@@ -43,4 +43,29 @@ def render_trade_acceptance(context, acceptance):
return {
"acceptance": acceptance,
"request": context.get("request"),
- }
\ No newline at end of file
+ }
+
+@register.filter
+def get_action_label(acceptance, state_value):
+ """
+ Calls the acceptance's method to return the alternate action label.
+ """
+ return acceptance.get_action_label_for_state(state_value)
+
+@register.filter
+def action_button_class(state_value):
+ """
+ Returns daisyUI button classes based on the provided state value.
+ """
+ mapping = {
+ 'ACCEPTED': 'btn btn-primary',
+ 'SENT': 'btn btn-info',
+ 'RECEIVED': 'btn btn-info',
+ 'THANKED_BY_INITIATOR': 'btn btn-success',
+ 'THANKED_BY_ACCEPTOR': 'btn btn-success',
+ 'THANKED_BY_BOTH': 'btn btn-success',
+ 'REJECTED_BY_INITIATOR': 'btn btn-error',
+ 'REJECTED_BY_ACCEPTOR': 'btn btn-error',
+ }
+ # Return a default style if the state isn't in the mapping.
+ return mapping.get(state_value, 'btn btn-outline')
\ No newline at end of file