From fe3502d775d5343c102963aecd40e8bbb741239e Mon Sep 17 00:00:00 2001 From: seba Date: Sat, 5 Mar 2011 00:41:37 +0100 Subject: [PATCH] kaufen zieht nun geld ab --- k4ever/buyable/models.py | 19 ++++++++++++++++++- k4ever/buyable/views.py | 3 ++- k4ever/k4ever.db | Bin 64512 -> 64512 bytes 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/k4ever/buyable/models.py b/k4ever/buyable/models.py index d9025ac..7eafee7 100644 --- a/k4ever/buyable/models.py +++ b/k4ever/buyable/models.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from django.db import models from django.contrib.auth.models import User import datetime @@ -49,13 +50,29 @@ class Order(models.Model): self.purchase.add(item) self.price += item.price - def updatePrice(self): + def updatePrice(self, commit=False, updateBalance=False): self.price = 0.0 for item in self.purchase_set.all(): self.price += item.price + if commit or updateBalance: + # TROLL MODE ON! + profile = self.user.get_profile() + profile.balance -= self.price + profile.save() def __unicode__(self): return "Price %s, User %s" % (self.price, self.user) + + #def save(self, *args, **kwargs): + #profile = self.user.get_profile() + #if self.id == None: + ## new item, get it! + #profile.balance -= self.price + #profile.save() + #else: + ## get old + #super(Order, self).save(*args, **kwargs) + class Purchase(models.Model): order = models.ForeignKey(Order) diff --git a/k4ever/buyable/views.py b/k4ever/buyable/views.py index 5a91198..0403957 100644 --- a/k4ever/buyable/views.py +++ b/k4ever/buyable/views.py @@ -21,6 +21,7 @@ def showItem(request, itemid): return HttpResponseRedirect("/buy/") return render_to_response("buyables/showItem.html", {'item': item}, RequestContext(request)) + @login_required def buyItem(request, itemid, buymode=""): user = request.user @@ -46,7 +47,7 @@ def buyItem(request, itemid, buymode=""): p = Purchase.create(order, item, isDeposit=True) p.order = order p.save() - order.updatePrice() + order.updatePrice(commit=True) order.save() return HttpResponseRedirect("/store/bought/%s/" % (order.id)) diff --git a/k4ever/k4ever.db b/k4ever/k4ever.db index 576343a2f4fec36c73978632ed96904b0badfc9b..e53bb24b3eeb008db4bdc14d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