From a486ec6007f93adfd8636011c36de2432a350c73 Mon Sep 17 00:00:00 2001 From: Frank Sauerburger <frank@sauerburger.com> Date: Mon, 29 Mar 2021 13:35:20 +0200 Subject: [PATCH] Protect plot count against math domain error --- uhepp_org/uhepp_vault/templates/uhepp_vault/home.html | 8 +++++++- uhepp_org/uhepp_vault/views.py | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/uhepp_org/uhepp_vault/templates/uhepp_vault/home.html b/uhepp_org/uhepp_vault/templates/uhepp_vault/home.html index 486b69c..4a16441 100644 --- a/uhepp_org/uhepp_vault/templates/uhepp_vault/home.html +++ b/uhepp_org/uhepp_vault/templates/uhepp_vault/home.html @@ -5,7 +5,13 @@ <div class="jumbotron jumbo-fluid plot-background shadow"> <div class="container"> <h1 class="display-4">uhepp hub</h1> - <h2>Home of over {{ plot_count }} plots</h2> + <h2> + {% if plot_count < 10 %} + Home of plots + {% else %} + Home of over {{ plot_count }} plots + {% endif %} + </h2> </div> </div> {% endblock %} diff --git a/uhepp_org/uhepp_vault/views.py b/uhepp_org/uhepp_vault/views.py index 61ac321..529894c 100644 --- a/uhepp_org/uhepp_vault/views.py +++ b/uhepp_org/uhepp_vault/views.py @@ -22,6 +22,9 @@ from .models import PUBLIC_LEVEL, INTERNAL_LEVEL, PUBLIC_LEVEL, \ from .forms import TokenForm def quantize(value, sig_digits): + if value <= 100: + return value + magnitude = math.floor(math.log10(value)) scale = magnitude - sig_digits + 1 return math.floor(value / 10**scale) * 10**scale -- GitLab