diff --git a/app/hlds/models.py b/app/hlds/models.py index 881cdf5..cbeafe8 100644 --- a/app/hlds/models.py +++ b/app/hlds/models.py @@ -1,10 +1,10 @@ #!/usr/bin/env python3 # pylint: disable=too-few-public-methods -from typing import List, Mapping, Any +from typing import Iterable, List, Mapping, Any -def _format_tags(tags): +def _format_tags(tags: Iterable[str]) -> str: return ( " :: {}".format(" ".join(["{" + tag + "}" for tag in tags])) if tags else @@ -12,6 +12,10 @@ def _format_tags(tags): ) +def _format_price(price: int) -> str: + return " € {}.{:02}".format(*divmod(price, 100)) if price else "" + + def _format_type_and_choice(type_and_choice): type_, choice = type_and_choice return "{} {}".format(type_, choice) @@ -30,7 +34,7 @@ class Option: self, " -- {}".format(self.description) if self.description else "", _format_tags(self.tags), - " {}".format(self.price) if self.price else "" + _format_price(self.price) ) @@ -65,7 +69,7 @@ class Dish: self, " -- {}".format(self.description) if self.description else "", _format_tags(self.tags), - " {}".format(self.price) if self.price else "", + _format_price(self.price), "\n\t".join(map(_format_type_and_choice, self.choices)) ) diff --git a/app/hlds/testfrituur.hlds b/app/hlds/testfrituur.hlds index 826822a..93ee50f 100644 --- a/app/hlds/testfrituur.hlds +++ b/app/hlds/testfrituur.hlds @@ -6,8 +6,8 @@ testfrituur: Testfrituur sauce: Saus ketchup: Ketchup -- Een tomatensaus met veel suiker € 0.8 mayo: Mayonaise -- Eierdooier en olie € 0.8 - curry: Currysaus € 0.8 - stoofvlees: Stoofvleessaus € 1.4 + curry: Currysaus € 0.80 + stoofvlees: Stoofvleessaus € 1.41 base veggieburger: Veggieburger € 4.2