Browse Source

added view to buy single products

master
Frederic 11 years ago
parent
commit
4c1eb6f227
  1. 21
      cash/templates/cash/buy_confirm.html
  2. 12
      cash/templates/cash/buy_thanks.html
  3. 5
      cash/urls.py
  4. 15
      cash/views.py

21
cash/templates/cash/buy_confirm.html

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
{% extends "cash/base.html" %}
{% load url from future %}
{% block content %}
<h1>Produkt kaufen</h1>
<table>
<tr><th>Name:</th><td>{{ product.name }}</td></tr>
<tr><th>Preis:</th><td>{{ product.price }}</td></tr>
<tr><th>Kategorie:</th><td>{{ product.category }}</td></tr>
</table>
Möchten Sie dieses Produkt wirklich kaufen?<br/>
<a class="actionlink" href="{% url 'buy_really' product.id %}">Ja</a>
<a class="actionlink" href="{% url 'products' %}">Nein</a>
{% endblock %}

12
cash/templates/cash/buy_thanks.html

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
{% extends "cash/base.html" %}
{% load url from future %}
{% block content %}
<h1>Produkt kaufen</h1>
Vielen Dank fuer Ihren Einkauf!
{% endblock %}

5
cash/urls.py

@ -13,7 +13,10 @@ urlpatterns = patterns('', @@ -13,7 +13,10 @@ urlpatterns = patterns('',
url(r'products/((?P<category_id>\d+)/)?$', views.products, name='products'),
url(r'^/buy/(?P<product_id>\d+)/$', 'cash.views.overview', name='buy'),
url(r'buy/(?P<product_id>\d+)/$', 'cash.views.buy', name='buy'),
url(r'buy/(?P<product_id>\d+)/really/$', 'cash.views.buy',
{'confirm': True}, name='buy_really'),
)

15
cash/views.py

@ -58,5 +58,20 @@ def products(request, category_id=None): @@ -58,5 +58,20 @@ def products(request, category_id=None):
return render_to_response('cash/product_list.html',
context_instance=context)
@login_required
def buy(request, product_id, confirm=False):
product = get_object_or_404(Product, id=product_id)
if confirm:
request.user.account.buy_product(product, 1)
context = RequestContext(request)
return render_to_response('cash/buy_thanks.html',
context_instance=context)
else:
context = RequestContext(request, {'product': product})
return render_to_response('cash/buy_confirm.html',
context_instance=context)

Loading…
Cancel
Save