mirror of https://github.com/zulip/zulip.git
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:
parent
8bd9a91216
commit
787d64e327
|
@ -124,8 +124,7 @@ def format_discount_percentage(discount: Optional[Decimal]) -> Optional[str]:
|
||||||
if type(discount) is not Decimal or discount == Decimal(0):
|
if type(discount) is not Decimal or discount == Decimal(0):
|
||||||
return None
|
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:
|
if discount * 100 % 100 == 0:
|
||||||
precision = 0
|
precision = 0
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -101,10 +101,10 @@
|
||||||
{{ csrf_input }}
|
{{ csrf_input }}
|
||||||
<input type="hidden" name="realm_id" value="{{ realm.id }}" />
|
<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 %}
|
{% 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>
|
<button type="submit" class="btn btn-default support-submit-button" disabled>Update</button>
|
||||||
{% else %}
|
{% 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>
|
<button type="submit" class="btn btn-default support-submit-button">Update</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
{% set sponsorship_data = support_data[remote_realm.id].sponsorship_data %}
|
{% set sponsorship_data = support_data[remote_realm.id].sponsorship_data %}
|
||||||
{% set remote_id = remote_realm.id %}
|
{% set remote_id = remote_realm.id %}
|
||||||
{% set remote_type = "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 %}
|
{% set has_fixed_price = support_data[remote_realm.id].plan_data.has_fixed_price %}
|
||||||
{% include 'analytics/sponsorship_forms_support.html' %}
|
{% include 'analytics/sponsorship_forms_support.html' %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
|
@ -67,6 +67,7 @@
|
||||||
{% set sponsorship_data = remote_servers_support_data[remote_server.id].sponsorship_data %}
|
{% set sponsorship_data = remote_servers_support_data[remote_server.id].sponsorship_data %}
|
||||||
{% set remote_id = remote_server.id %}
|
{% set remote_id = remote_server.id %}
|
||||||
{% set remote_type = "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 %}
|
{% set has_fixed_price = remote_servers_support_data[remote_server.id].plan_data.has_fixed_price %}
|
||||||
{% include 'analytics/sponsorship_forms_support.html' %}
|
{% include 'analytics/sponsorship_forms_support.html' %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
|
@ -25,10 +25,10 @@
|
||||||
{{ csrf_input }}
|
{{ csrf_input }}
|
||||||
<input type="hidden" name="{{ remote_type }}" value="{{ remote_id }}" />
|
<input type="hidden" name="{{ remote_type }}" value="{{ remote_id }}" />
|
||||||
{% if has_fixed_price %}
|
{% 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>
|
<button type="submit" class="btn btn-default support-submit-button" disabled>Update</button>
|
||||||
{% else %}
|
{% 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>
|
<button type="submit" class="btn btn-default support-submit-button">Update</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue