From c05fe944c0cac1fae9c3bbb419379d76731a14d0 Mon Sep 17 00:00:00 2001 From: seba Date: Thu, 2 Dec 2010 13:31:52 +0100 Subject: [PATCH] everything is much better now! --- k4ever/buyable/models.py | 16 +++++++++++----- k4ever/buyable/views.py | 8 +++++--- k4ever/k4ever.db | Bin 62464 -> 62464 bytes 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/k4ever/buyable/models.py b/k4ever/buyable/models.py index aba9d77..d9025ac 100644 --- a/k4ever/buyable/models.py +++ b/k4ever/buyable/models.py @@ -37,7 +37,7 @@ class Order(models.Model): price = models.FloatField() dateTime = models.DateTimeField() - def resetWithUser(self, user=None): + def create(self, user=None): models.Model.__init__(self) self.price = 0.0 self.dateTime = datetime.datetime.now() @@ -49,6 +49,11 @@ class Order(models.Model): self.purchase.add(item) self.price += item.price + def updatePrice(self): + self.price = 0.0 + for item in self.purchase_set.all(): + self.price += item.price + def __unicode__(self): return "Price %s, User %s" % (self.price, self.user) @@ -57,14 +62,15 @@ class Purchase(models.Model): price = models.FloatField() isDeposit = models.BooleanField() buyable = models.ForeignKey(Buyable) - - def create(order, buyable): + + @staticmethod + def create(order, buyable, isDeposit=False): p = Purchase() p.order = order if isDeposit: - p.price = self.deposit + p.price = buyable.deposit else: - p.price = self.price + p.price = buyable.price p.dateTime = datetime.datetime.now() p.buyable = buyable diff --git a/k4ever/buyable/views.py b/k4ever/buyable/views.py index 753a293..d4b35e8 100644 --- a/k4ever/buyable/views.py +++ b/k4ever/buyable/views.py @@ -35,17 +35,19 @@ def buyItem(request, itemid, buymode=""): "only/deposit" only deposit """ order = Order() - order.resetWithUser(user) + order.create(user) order.save() # for the id! if buymode == "" or buymode == "with/deposit": - p = item.createPurchase(isDeposit=False) + p = Purchase.create(order, item, isDeposit=False) p.order = order p.save() # TANNEK! if buymode == "with/dopsit" or buymode == "only/deposit": if buymode == "with/deposit" or buymode == "only/deposit": - p = item.createPurchase(isDeposit=True) + p = Purchase.create(order, item, isDeposit=True) p.order = order p.save() + order.updatePrice() + order.save() return HttpResponseRedirect("/store/bought/%s/" % (order.id)) @login_required diff --git a/k4ever/k4ever.db b/k4ever/k4ever.db index 15e28873764e81671decd8505b19068a6f5a215b..1c88490835c2c93c3dd29a7414014d3bd836008d 100644 GIT binary patch delta 924 zcmb7>y>HV%7>9lLHvYDwNJtD6s5^D(aUVW^2`LKv1q^H*kXYClieO-HM%1BdyMr8Q?S#zFCF8HpHyIgJwStwrU zlt~#2rFVj*IaherP0eDSDV|4uZITf&{#ImGNX>GQ^IS(>tCZ)Rq!1ZPc`CVz-0nvF}ue`wzGKbZ)>Ie1Z?~29Dtn9>YDj4L9H#Y=T37()o1qj+TSI zSzi|+;qYU7Uj`Y3ztQqyY813682&+ii~JSjts}QZ-iqb4$ZgQDx%s+pudpSuTI8%e zX|AE!@uRzY5W?%qI=MU>Y&?Nc4@mtvxB;$@>*2b%4z7)B;hMNT-0JMrMd-uJI(fBD tj^TQP!#*yC0}T5Z_A%^X*u}7mVF$yGS)G2~Uat|X{r_vuPQPBc@C&T0mI?p> delta 154 zcmZp8!QAkId4e=!$wV1v#*&Q*OY(VGm`fO#?=tUVp3YpdS&$`#nMsjla$}M3 zllzLx_*j`2GBCeozQuf;c?