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 576343a..e53bb24 100644 Binary files a/k4ever/k4ever.db and b/k4ever/k4ever.db differ