From 1ad1e1d6d5e9e5e52763d88944085f5295480871 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Setni=C4=8Dka?= <setnicka@seznam.cz>
Date: Fri, 16 Apr 2021 23:45:58 +0200
Subject: [PATCH] =?UTF-8?q?Nastaven=C3=AD=20kola=20-=20coerce=20na=20selec?=
 =?UTF-8?q?t=20pro=20points=5Fstep=20+=20zach=C3=A1zen=C3=AD=20s=20points?=
 =?UTF-8?q?=5Fstep=20v=C5=A1ude=20jako=20s=20Decimal?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Řeší situace "String, float a Decimal vejdou společně do baru..."

Solve #215
---
 mo/db.py            | 10 +++++-----
 mo/web/org_round.py |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/mo/db.py b/mo/db.py
index 141fb727..6309a5a9 100644
--- a/mo/db.py
+++ b/mo/db.py
@@ -190,9 +190,9 @@ round_score_mode_names = {
 
 # V DB jako numeric(2,1), používá se tak snadněji, než enum
 round_points_step_names = {
-    1: "Celé body",
-    0.5: "Půlbody",
-    0.1: "Desetinné body",
+    decimal.Decimal('1'): "Celé body",
+    decimal.Decimal('0.5'): "Půlbody",
+    decimal.Decimal('0.1'): "Desetinné body",
 }
 round_points_step_choices = round_points_step_names.items()
 
@@ -259,8 +259,8 @@ class Round(Base):
             return self.state
 
     def points_step_name(self) -> str:
-        if float(self.points_step) in round_points_step_names:
-            return round_points_step_names[float(self.points_step)]
+        if self.points_step in round_points_step_names:
+            return round_points_step_names[self.points_step]
         return str(self.points_step)
 
 
diff --git a/mo/web/org_round.py b/mo/web/org_round.py
index 08864412..446c29d3 100644
--- a/mo/web/org_round.py
+++ b/mo/web/org_round.py
@@ -442,7 +442,7 @@ class RoundEditForm(FlaskForm):
         description="Řešitelé s alespoň tolika body budou označeni za úspěšné řešitele, prázdná hodnota = žádné neoznačovat",
     )
     points_step = wtforms.SelectField(
-        "Přesnost bodování", choices=db.round_points_step_choices,
+        "Přesnost bodování", choices=db.round_points_step_choices, coerce=decimal.Decimal,
         description="Ovlivňuje možnost zadávání nových bodů, již uložené body nezmění"
     )
     has_messages = wtforms.BooleanField("Zprávičky pro účastníky (aktivuje možnost vytvářet novinky zobrazované účastníkům)")
-- 
GitLab