make purchase price a float
Django CI/CD / test (push) Successful in 1m7s Details
Django CI/CD / build-and-push (push) Successful in 2m8s Details

This commit is contained in:
Lukáš Kucharczyk 2024-10-04 11:36:46 +02:00
parent 7f5a1889f3
commit 7ec622a38a
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
5 changed files with 27 additions and 4 deletions

View File

@ -60,3 +60,7 @@ def generate_split_ranges(
except IndexError: except IndexError:
end = len(value_list) end = len(value_list)
yield (value_list[start], value_list[end - 1]) yield (value_list[start], value_list[end - 1])
def format_float_or_int(number: int | float):
return int(number) if float(number).is_integer() else f"{number:03.2f}"

View File

@ -0,0 +1,18 @@
# Generated by Django 5.1.1 on 2024-10-04 09:23
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('games', '0037_platform_icon'),
]
operations = [
migrations.AlterField(
model_name='purchase',
name='price',
field=models.FloatField(default=0),
),
]

View File

@ -111,7 +111,7 @@ class Purchase(models.Model):
date_finished = models.DateField(blank=True, null=True) date_finished = models.DateField(blank=True, null=True)
date_dropped = models.DateField(blank=True, null=True) date_dropped = models.DateField(blank=True, null=True)
infinite = models.BooleanField(default=False) infinite = models.BooleanField(default=False)
price = models.IntegerField(default=0) price = models.FloatField(default=0)
price_currency = models.CharField(max_length=3, default="USD") price_currency = models.CharField(max_length=3, default="USD")
ownership_type = models.CharField( ownership_type = models.CharField(
max_length=2, choices=OWNERSHIP_TYPES, default=DIGITAL max_length=2, choices=OWNERSHIP_TYPES, default=DIGITAL

View File

@ -25,7 +25,7 @@ from common.time import (
local_strftime, local_strftime,
timeformat, timeformat,
) )
from common.utils import safe_division, truncate from common.utils import format_float_or_int, safe_division, truncate
from games.forms import GameForm from games.forms import GameForm
from games.models import Edition, Game, Purchase, Session from games.models import Edition, Game, Purchase, Session
from games.views.general import use_custom_redirect from games.views.general import use_custom_redirect
@ -247,7 +247,7 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
), ),
purchase.get_type_display(), purchase.get_type_display(),
purchase.date_purchased.strftime(dateformat), purchase.date_purchased.strftime(dateformat),
f"{purchase.price} {purchase.price_currency}", f"{format_float_or_int(purchase.price)} {purchase.price_currency}",
render_to_string( render_to_string(
"cotton/button_group.html", "cotton/button_group.html",
{ {

View File

@ -15,6 +15,7 @@ from django.utils import timezone
from common.components import A, Button, Icon, LinkedNameWithPlatformIcon from common.components import A, Button, Icon, LinkedNameWithPlatformIcon
from common.time import dateformat from common.time import dateformat
from common.utils import format_float_or_int
from games.forms import PurchaseForm from games.forms import PurchaseForm
from games.models import Edition, Purchase from games.models import Edition, Purchase
from games.views.general import use_custom_redirect from games.views.general import use_custom_redirect
@ -65,7 +66,7 @@ def list_purchases(request: HttpRequest) -> HttpResponse:
platform=purchase.platform, platform=purchase.platform,
), ),
purchase.get_type_display(), purchase.get_type_display(),
purchase.price, format_float_or_int(purchase.price),
purchase.price_currency, purchase.price_currency,
purchase.infinite, purchase.infinite,
purchase.date_purchased.strftime(dateformat), purchase.date_purchased.strftime(dateformat),