Update trade offer acceptance update template buttons to have better text and styling
This commit is contained in:
parent
fb9f2f5848
commit
2451a6c630
3 changed files with 67 additions and 8 deletions
|
|
@ -52,15 +52,20 @@
|
||||||
<div class="mt-6">
|
<div class="mt-6">
|
||||||
<h3 class="text-xl font-semibold mb-4">Select an action:</h3>
|
<h3 class="text-xl font-semibold mb-4">Select an action:</h3>
|
||||||
{% if form.fields.state.choices %}
|
{% if form.fields.state.choices %}
|
||||||
{% for state_value, state_label in form.fields.state.choices %}
|
<div class="flex flex-row gap-2">
|
||||||
<form method="post" class="mb-2">
|
{% for state_value, state_label in form.fields.state.choices %}
|
||||||
{% csrf_token %}
|
<form method="post" class="mb-2 flex-1">
|
||||||
<input type="hidden" name="state" value="{{ state_value }}">
|
{% csrf_token %}
|
||||||
<button type="submit" class="btn btn-primary w-full">{{ state_label }}</button>
|
<input type="hidden" name="state" value="{{ state_value }}">
|
||||||
</form>
|
<button type="submit" class="{{ state_value|action_button_class }} w-full">
|
||||||
{% endfor %}
|
{{ object|get_action_label:state_value }}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No available actions.</p>
|
<p>No available actions.</p>
|
||||||
|
<!--button class="btn-info"></button-->
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,35 @@ class TradeAcceptance(models.Model):
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
updated_at = models.DateTimeField(auto_now=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
|
@property
|
||||||
def is_completed(self):
|
def is_completed(self):
|
||||||
return self.state in {
|
return self.state in {
|
||||||
|
|
|
||||||
|
|
@ -44,3 +44,28 @@ def render_trade_acceptance(context, acceptance):
|
||||||
"acceptance": acceptance,
|
"acceptance": acceptance,
|
||||||
"request": context.get("request"),
|
"request": context.get("request"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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')
|
||||||
Loading…
Add table
Add a link
Reference in a new issue