You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.1 KiB

# -*- coding: utf-8 -*-
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
import datetime
from models import Buyable, Purchase, Order
def showItems(request):
# FIXME: Implement pagination here
items = Buyable.objects.all()
return render_to_response("buyables/showItems.html", {'items': items}, RequestContext(request))
def showItem(request, itemid):
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))
def buyItem(request, itemid, buymode=""):
user = request.user
item = Buyable.objects.get(id=itemid)
except Buyable.DoesNotExist:
# oh no! kein item mit der id :( mutax trollt rum)
return HttpResponseRedirect("/store/buy/")
""" tristate variable buymode:
"" only item
"with/deposit" item and deposit
"only/deposit" only deposit
items = []
if buymode == "" or buymode == "with/deposit":
p = item.createPurchase(isDeposit=False)
# TANNEK! if buymode == "with/dopsit" or buymode == "only/deposit":
if buymode == "with/deposit" or buymode == "only/deposit":
p = item.createPurchase(isDeposit=True)
order = Order()
order.resetWithUser(user) # for the id!
return HttpResponseRedirect("/store/bought/%s/" % (
def boughtItem(request, orderid):
error = None
item = Order.objects.get(id=orderid)
except Order.DoesNotExist:
error = "Die angegebene Order existiert nicht"
if error == None and (item.user != request.user):
item1 = None
error = u"Diese Items gehören dir nicht"
return render_to_response("buyables/itemBought.html", {'order': item, 'error': error}, RequestContext(request))