diff --git a/eggplant/market/templates/eggplant/market/market_home.html b/eggplant/market/templates/eggplant/market/market_home.html index a94f50f..f8c7222 100644 --- a/eggplant/market/templates/eggplant/market/market_home.html +++ b/eggplant/market/templates/eggplant/market/market_home.html @@ -58,41 +58,22 @@

{% trans 'Basket' %}

{% endfor %} + + {% trans 'Go to checkout' %} + + + {% trans 'Your basket' %} + {% endif %} {% endblock %} {% block content_right_col %} +

Market

-
-
-

Order groceries:

-
-
- -
-
-

Filter products:

-
-
- -
-
- {{product_filter.form}} -
-
- -{% if products %} -
-
- your basket - {% if basket_items %} - go to checkout - {% endif %} -
+
+ Filter products: {{product_filter.form}}
-
-{% endif %} {% for sublist in product_filter|partition:"3" %}
diff --git a/eggplant/market/templatetags/cart_tags.py b/eggplant/market/templatetags/cart_tags.py index f19a994..7eb9e96 100644 --- a/eggplant/market/templatetags/cart_tags.py +++ b/eggplant/market/templatetags/cart_tags.py @@ -1,4 +1,5 @@ from django import template +from django.template import Template from django.core.urlresolvers import reverse from django.template.base import TemplateSyntaxError @@ -25,24 +26,23 @@ def cart_action(context, action, product_id=None, quantity=None, else: raise TemplateSyntaxError("action `{}` not supported".format(action)) quantity = quantity or 1 - fmt = { + context.update({ 'action': action, 'action_url': url, 'btn_css_classes': btn_css_classes, 'product_id': int(product_id), 'quantity': int(quantity), 'csrf_token': context['csrf_token'], - } - html = (''' -
+ }) + return Template(''' + ''' + delivery_date_field + ''' - - - + + +

+ class="{{btn_css_classes}}" + role="button" >{{action}}

-
''').format(**fmt) - return html + ''').render(context) diff --git a/eggplant/market/views/cart.py b/eggplant/market/views/cart.py index a7d8893..0365868 100644 --- a/eggplant/market/views/cart.py +++ b/eggplant/market/views/cart.py @@ -39,15 +39,17 @@ def form_valid(self, form): "than %d items in your basket.") % (max_items) messages.warning(self.request, msg) return redirect('eggplant:market:market_home') - if form.cleaned_data['product'].stock < 1 or not form.cleaned_data['product'].enabled: - msg = _("Sorry, this product is currently out of stock") + product = form.cleaned_data['product'] + quantity = form.cleaned_data['quantity'] + if not product.enabled or (product.stock is not None and + product.stock < quantity): + msg = _("Sorry, this product is currently not this much on stock") messages.warning(self.request, msg) return redirect('eggplant:market:market_home') self.basket.add_to_items(**form.cleaned_data) - stock = form.cleaned_data['product'].stock - \ - form.cleaned_data['quantity'] - Product.objects.filter(id=form.cleaned_data['product'].id)\ - .update(stock=stock) + if product.stock is not None: + stock = product.stock - quantity + Product.objects.filter(id=product.id).update(stock=stock) msg = _("You have just added %s to your basket.") % \ (form.cleaned_data['product'].title) messages.info(self.request, msg) @@ -60,10 +62,10 @@ def form_valid(self, form): with transaction.atomic(): super().form_valid(form) self.basket.remove_from_items(**form.cleaned_data) - stock = form.cleaned_data['product'].stock + \ - form.cleaned_data['quantity'] - Product.objects.filter(id=form.cleaned_data['product'].id)\ - .update(stock=stock) + product = form.cleaned_data['product'] + if product.stock is not None: + stock = product.stock + form.cleaned_data['quantity'] + Product.objects.filter(id=product.id).update(stock=stock) return redirect('eggplant:market:cart_details') remove_from_cart = login_required(RemoveFromCart.as_view())