k4ever/k4ever/buyable/views.py

33 lines
1.2 KiB
Python

# Create your views here.
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from models import Buyable
@login_required
def showItems(request):
# FIXME: Implement pagination here
items = Buyable.objects.all()
return render_to_response("buyables/showItems.html", {'items': items}, RequestContext(request))
@login_required
def showItem(request, itemid):
try:
item = Buyable.objects.get(id=itemid)
except Buyable.DoesNotExist:
# baww, kein item mit der id :( (oder mutax trollt rum)
return HttpResponseRedirect("/buy/")
return render_to_response("buyables/showItem.html", {'item': item}, RequestContext(request))
@login_required
def buyItem(request, itemid):
try:
item = Buyable.objects.get(id=itemid)
except Buyable.DoesNotExist:
# oh no! kein item mit der id :( mutax trollt rum)
return HttpResponseRedirect("/buy/")
purchase = Purchase(user=request.user, price=item.price, isDeposit=false )
purchase.create(item)
purchase.save()
return render_to_response("buyables/itemBought.html", {'item': item}, RequestContext(request))