support: Update validation for adding or updating a discount.

Updates the HTML input field to have a min of 0, max of 99.99 and
allow increments of 0.01.

Also, use format_discount_percentage for displaying the customer
default discount in the support form.
This commit is contained in:
Lauryn Menard 2024-01-04 15:59:36 +01:00 committed by Tim Abbott
parent 8bd9a91216
commit 787d64e327
5 changed files with 7 additions and 6 deletions

View File

@ -124,8 +124,7 @@ def format_discount_percentage(discount: Optional[Decimal]) -> Optional[str]:
if type(discount) is not Decimal or discount == Decimal(0):
return None
# Even though it looks like /activity/support only finds integers valid,
# this will look good for any custom discounts that we apply.
# This will look good for any custom discounts that we apply.
if discount * 100 % 100 == 0:
precision = 0
else:

View File

@ -101,10 +101,10 @@
{{ csrf_input }}
<input type="hidden" name="realm_id" value="{{ realm.id }}" />
{% if plan_data[realm.id].current_plan and plan_data[realm.id].current_plan.fixed_price %}
<input type="number" name="discount" value="{{ get_discount(plan_data[realm.id].customer) }}" disabled />
<input type="number" name="discount" value="{{ format_discount(get_discount(plan_data[realm.id].customer)) }}" step="0.01" min="0" max="99.99" disabled />
<button type="submit" class="btn btn-default support-submit-button" disabled>Update</button>
{% else %}
<input type="number" name="discount" value="{{ get_discount(plan_data[realm.id].customer) }}" required />
<input type="number" name="discount" value="{{ format_discount(get_discount(plan_data[realm.id].customer)) }}" step="0.01" min="0" max="99.99" required />
<button type="submit" class="btn btn-default support-submit-button">Update</button>
{% endif %}
</form>

View File

@ -32,6 +32,7 @@
{% set sponsorship_data = support_data[remote_realm.id].sponsorship_data %}
{% set remote_id = remote_realm.id %}
{% set remote_type = "remote_realm_id" %}
{% set format_discount = format_discount %}
{% set has_fixed_price = support_data[remote_realm.id].plan_data.has_fixed_price %}
{% include 'analytics/sponsorship_forms_support.html' %}
{% endwith %}

View File

@ -67,6 +67,7 @@
{% set sponsorship_data = remote_servers_support_data[remote_server.id].sponsorship_data %}
{% set remote_id = remote_server.id %}
{% set remote_type = "remote_server_id" %}
{% set format_discount = format_discount %}
{% set has_fixed_price = remote_servers_support_data[remote_server.id].plan_data.has_fixed_price %}
{% include 'analytics/sponsorship_forms_support.html' %}
{% endwith %}

View File

@ -25,10 +25,10 @@
{{ csrf_input }}
<input type="hidden" name="{{ remote_type }}" value="{{ remote_id }}" />
{% if has_fixed_price %}
<input type="number" name="discount" value="{{ sponsorship_data.default_discount }}" disabled />
<input type="number" name="discount" value="{{ format_discount(sponsorship_data.default_discount) }}" step="0.01" min="0" max="99.99" disabled />
<button type="submit" class="btn btn-default support-submit-button" disabled>Update</button>
{% else %}
<input type="number" name="discount" value="{{ sponsorship_data.default_discount }}" required />
<input type="number" name="discount" value="{{ format_discount(sponsorship_data.default_discount) }}" step="0.01" min="0" max="99.99" required />
<button type="submit" class="btn btn-default support-submit-button">Update</button>
{% endif %}
</form>