ich schreib mal alles up. das is nu kaputt
purchase, order, foo
This commit is contained in:
parent
b43c1df865
commit
60fe5ca2d2
BIN
devel/er.dia
BIN
devel/er.dia
Binary file not shown.
|
@ -18,12 +18,39 @@ class Buyable(models.Model):
|
|||
description = models.TextField()
|
||||
buyableType = models.ManyToManyField(BuyableType)
|
||||
|
||||
def createPurchase(self, user, isDeposit=False):
|
||||
p = Purchase()
|
||||
p.user = user
|
||||
if isDeposit:
|
||||
p.price = self.deposit
|
||||
else:
|
||||
p.price = self.price
|
||||
p.dateTime = datetime.datetime.now()
|
||||
p.buyable = self
|
||||
|
||||
return p
|
||||
|
||||
|
||||
def __unicode__(self):
|
||||
return "%s (%s EUR/%s Pfand)" % (self.name, self.price, self.deposit)
|
||||
|
||||
class Purchase(models.Model):
|
||||
class Order(models.Model):
|
||||
user = models.ForeignKey(User)
|
||||
purchase = models.ManyToManyField('Purchase')
|
||||
price = models.FloatField()
|
||||
dateTime = models.DateTimeField()
|
||||
|
||||
def __init__(self, user=None, items=None):
|
||||
if user:
|
||||
self.user = user
|
||||
if items:
|
||||
for item in items:
|
||||
purchase.add(item)
|
||||
|
||||
def __unicode__(self):
|
||||
return "Price %s, User %s" % (self.price, self.user)
|
||||
|
||||
class Purchase(models.Model):
|
||||
price = models.FloatField()
|
||||
isDeposit = models.BooleanField()
|
||||
buyable = models.ForeignKey(Buyable)
|
||||
|
@ -31,20 +58,12 @@ class Purchase(models.Model):
|
|||
def __unicode__(self):
|
||||
return "%s%s, %s by %s" % (self.buyable.name, self.isDeposit and " (deposit)" or "", self.price, self.user)
|
||||
|
||||
def create(self, buyable, isDeposit=None):
|
||||
"""constructor"""
|
||||
if isDeposit is not None:
|
||||
self.isDeposit = isDeposit
|
||||
self.dateTime = datetime.datetime.now()
|
||||
self.buyable = buyable
|
||||
if self.isDeposit:
|
||||
self.price = buyable.deposit
|
||||
else:
|
||||
self.price = buyable.price
|
||||
def save(self, *args, **kwargs):
|
||||
profile = self.user.get_profile()
|
||||
if self.id == None:
|
||||
# new item, get it!
|
||||
profile.balance -= self.price
|
||||
profile.save()
|
||||
# profile = self.user.get_profile()
|
||||
# if self.id == None:
|
||||
# # new item, get it!
|
||||
# profile.balance -= self.price
|
||||
# profile.save()
|
||||
super(Purchase, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ def showItem(request, itemid):
|
|||
|
||||
@login_required
|
||||
def buyItem(request, itemid, buymode=""):
|
||||
user = request.user
|
||||
try:
|
||||
item = Buyable.objects.get(id=itemid)
|
||||
except Buyable.DoesNotExist:
|
||||
|
@ -33,21 +34,19 @@ def buyItem(request, itemid, buymode=""):
|
|||
"with/deposit" item and deposit
|
||||
"only/deposit" only deposit
|
||||
"""
|
||||
purchase = None
|
||||
deposit = None
|
||||
items = []
|
||||
if buymode == "" or buymode == "with/deposit":
|
||||
purchase = Purchase(user=request.user, isDeposit=False)
|
||||
purchase.create(item)
|
||||
purchase.save()
|
||||
p = item.createPurchase(user, isDeposit=False)
|
||||
p.save()
|
||||
items.append(p)
|
||||
# TANNEK! if buymode == "with/dopsit" or buymode == "only/deposit":
|
||||
if buymode == "with/deposit" or buymode == "only/deposit":
|
||||
deposit = Purchase(user=request.user, isDeposit=True)
|
||||
deposit.create(item)
|
||||
deposit.save()
|
||||
if purchase == None:
|
||||
purchase = deposit
|
||||
deposit = None
|
||||
return HttpResponseRedirect("/store/bought/%s/%s" % (purchase.id, deposit and str(deposit.id) or ""))
|
||||
p = item.createPurchase(user, isDeposit=True)
|
||||
p.save()
|
||||
items.append(p)
|
||||
order = Order(user, items)
|
||||
order.save()
|
||||
return HttpResponseRedirect("/store/bought/%s/" % (order.id, deposit))
|
||||
|
||||
@login_required
|
||||
def boughtItem(request, item1id, item2id=None):
|
||||
|
|
BIN
k4ever/k4ever.db
BIN
k4ever/k4ever.db
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 15 KiB |
Loading…
Reference in New Issue