Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Convert the price field to bootstrap

Patryk Zawadzki640a71ffd4d3
diff --git a/saleor/core/widgets.py b/saleor/core/widgets.py
index 8b13789179..96ebb81da9 100644
--- a/saleor/core/widgets.py
+++ b/saleor/core/widgets.py
@@ -1 +1,16 @@
+from django.utils.html import escape
+from django.utils.safestring import mark_safe
+from django_prices.widgets import PriceInput as BasePriceInput
+
+class PriceInput(BasePriceInput):
+ TEMPLATE = '''<div class="input-group">
+ %(widget)s
+ <div class="input-group-addon">%(currency)s</div>
+</div>'''
+
+ def render(self, name, value, attrs=None):
+ widget = super(BasePriceInput, self).render(name, value, attrs)
+ result = self.TEMPLATE % {'widget': widget,
+ 'currency': escape(self.currency)}
+ return mark_safe(result)
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.py
index 1bc8905ed9..8ee78315c6 100644
--- a/saleor/dashboard/product/forms.py
+++ b/saleor/dashboard/product/forms.py
@@ -4,14 +4,13 @@ from django import forms
from django.forms.models import inlineformset_factory
from django.forms.widgets import ClearableFileInput
+from ...core.widgets import PriceInput
from ...product.models import (ProductImage, Product, ShirtVariant, BagVariant,
Shirt, Bag)
-
PRODUCT_CLASSES = {
'shirt': Shirt,
- 'bag': Bag
-}
+ 'bag': Bag}
class ProductClassForm(forms.Form):
@@ -29,12 +28,14 @@ class ShirtForm(ProductForm):
class Meta:
model = Shirt
exclude = []
+ widgets = {'price': PriceInput}
class BagForm(ProductForm):
class Meta:
model = Bag
exclude = []
+ widgets = {'price': PriceInput}
class ImageInputWidget(ClearableFileInput):