Adds purchase feedback
This commit is contained in:
1 parent
fc400dffd4
commit
54ec001fb1
3 files changed
+21
-1
No files matched your search
+7
-1
@@ -1,3 +1,4 @@
|
||||
# coding: utf-8
|
||||
# Create your views here.
|
||||
from django.contrib.auth import login, logout as auth_logout
|
||||
from django.contrib.auth.decorators import login_required
|
||||
@@ -7,6 +8,7 @@ from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.template import RequestContext
|
||||
from django.forms.formsets import formset_factory
|
||||
from django.contrib import messages
|
||||
|
||||
from models import *
|
||||
|
||||
@@ -38,7 +40,7 @@ def register(request):
|
||||
orderform = OrderForm(request.POST)
|
||||
formset = OrderLineFormSet(request.POST)
|
||||
if formset.is_valid() and orderform.is_valid():
|
||||
order_sum = sum([orderline['amount'] * orderline['unit_price'] for orderline in formset.cleaned_data])
|
||||
order_sum = sum([ol['amount'] * ol['unit_price'] for ol in formset.cleaned_data])
|
||||
order = orderform.save(commit=False)
|
||||
order.order_sum = order_sum
|
||||
order.save()
|
||||
@@ -47,6 +49,7 @@ def register(request):
|
||||
profile.balance -= order.order_sum
|
||||
profile.save()
|
||||
|
||||
orderlines = []
|
||||
for ol in formset.cleaned_data:
|
||||
if ol['amount'] > 0:
|
||||
product = Product.objects.get(pk=ol['product'])
|
||||
@@ -56,6 +59,9 @@ def register(request):
|
||||
amount=ol['amount'],
|
||||
unit_price=ol['unit_price'])
|
||||
|
||||
orderlines.append(str(ol['amount']) + " stk " + str(product))
|
||||
|
||||
messages.success(request, '{0} kjøpte nettopp {1}.'.format(order.customer, ",".join(orderlines)))
|
||||
return HttpResponseRedirect( reverse('main.views.register') )
|
||||
else:
|
||||
# errors
|
||||
|
||||
@@ -57,5 +57,12 @@ $(document).ready(function() {
|
||||
$("span.total_text").html("");
|
||||
enable_all_customers();
|
||||
});
|
||||
/* Hide alert messages */
|
||||
$("a[data-dismiss=alert]").click(function(){
|
||||
$(this).parent().hide()
|
||||
});
|
||||
setTimeout( function() {
|
||||
$("a[data-dismiss=alert]").parent().slideUp();
|
||||
}, 5000);
|
||||
|
||||
});
|
||||
@@ -5,6 +5,13 @@
|
||||
|
||||
{% block content %}
|
||||
<section id="register" class="row-fluid">
|
||||
<section class="row-fluid">
|
||||
<div class="span4">
|
||||
{% for message in messages %}
|
||||
<div {% if message.tags %} class="alert alert-{{ message.tags }}"{% endif %}>{{ message }}<a class="close" data-dismiss="alert">×</a></div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
<form id="order" method="post" autocomplete="off">
|
||||
<fieldset>
|
||||
{% csrf_token %}
|
||||
|
||||
Reference in new issue
Block a user