more broken than before
This commit is contained in:
parent
a3254919a3
commit
4f37807ef1
|
@ -1,7 +1,8 @@
|
||||||
from models import Buyable, BuyableType, Purchase
|
from models import Buyable, BuyableType, Purchase, Order
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
admin.site.register(Buyable)
|
admin.site.register(Buyable)
|
||||||
admin.site.register(BuyableType)
|
admin.site.register(BuyableType)
|
||||||
admin.site.register(Purchase)
|
admin.site.register(Purchase)
|
||||||
|
admin.site.register(Order)
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,8 @@ class Buyable(models.Model):
|
||||||
description = models.TextField()
|
description = models.TextField()
|
||||||
buyableType = models.ManyToManyField(BuyableType)
|
buyableType = models.ManyToManyField(BuyableType)
|
||||||
|
|
||||||
def createPurchase(self, user, isDeposit=False):
|
def createPurchase(self, isDeposit=False):
|
||||||
p = Purchase()
|
p = Purchase()
|
||||||
p.user = user
|
|
||||||
if isDeposit:
|
if isDeposit:
|
||||||
p.price = self.deposit
|
p.price = self.deposit
|
||||||
else:
|
else:
|
||||||
|
@ -29,7 +28,6 @@ class Buyable(models.Model):
|
||||||
p.buyable = self
|
p.buyable = self
|
||||||
|
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "%s (%s EUR/%s Pfand)" % (self.name, self.price, self.deposit)
|
return "%s (%s EUR/%s Pfand)" % (self.name, self.price, self.deposit)
|
||||||
|
@ -40,12 +38,16 @@ class Order(models.Model):
|
||||||
price = models.FloatField()
|
price = models.FloatField()
|
||||||
dateTime = models.DateTimeField()
|
dateTime = models.DateTimeField()
|
||||||
|
|
||||||
def __init__(self, user=None, items=None):
|
def resetWithUser(self, user=None):
|
||||||
|
models.Model.__init__(self)
|
||||||
|
self.price = 0.0
|
||||||
|
self.dateTime = datetime.datetime.now()
|
||||||
if user:
|
if user:
|
||||||
self.user = user
|
self.user = user
|
||||||
if items:
|
|
||||||
for item in items:
|
def addItems(self, items):
|
||||||
purchase.add(item)
|
for item in items:
|
||||||
|
self.purchase.add(item)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "Price %s, User %s" % (self.price, self.user)
|
return "Price %s, User %s" % (self.price, self.user)
|
||||||
|
@ -58,12 +60,12 @@ class Purchase(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "%s%s, %s by %s" % (self.buyable.name, self.isDeposit and " (deposit)" or "", self.price, self.user)
|
return "%s%s, %s by %s" % (self.buyable.name, self.isDeposit and " (deposit)" or "", self.price, self.user)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
# def save(self, *args, **kwargs):
|
||||||
# profile = self.user.get_profile()
|
# profile = self.user.get_profile()
|
||||||
# if self.id == None:
|
# if self.id == None:
|
||||||
# # new item, get it!
|
# # new item, get it!
|
||||||
# profile.balance -= self.price
|
# profile.balance -= self.price
|
||||||
# profile.save()
|
# profile.save()
|
||||||
super(Purchase, self).save(*args, **kwargs)
|
# super(Purchase, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,10 @@
|
||||||
|
|
||||||
{% block "content" %}
|
{% block "content" %}
|
||||||
{% if not error %}
|
{% if not error %}
|
||||||
{% if item1 %}
|
You got the order {{ order }}
|
||||||
You got the item {{ item1 }}
|
{% for item in order.purchase.all %}
|
||||||
{% endif %}
|
{{ item }}
|
||||||
{% if item2 %}
|
{% endfor %}
|
||||||
You got the second item {{ item2 }}
|
|
||||||
{% endif %}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ error }}
|
{{ error }}
|
||||||
Junge junge junge
|
Junge junge junge
|
||||||
|
|
|
@ -5,5 +5,5 @@ urlpatterns = patterns('',
|
||||||
(r'^$', 'buyable.views.showItems'),
|
(r'^$', 'buyable.views.showItems'),
|
||||||
(r'^show/(\d+)/$', 'buyable.views.showItem'),
|
(r'^show/(\d+)/$', 'buyable.views.showItem'),
|
||||||
(r'^buy/(\d+)/(|with/deposit|only/deposit)/?$', 'buyable.views.buyItem'),
|
(r'^buy/(\d+)/(|with/deposit|only/deposit)/?$', 'buyable.views.buyItem'),
|
||||||
(r'^bought/(\d+)/(\d+)?/?$', 'buyable.views.boughtItem'),
|
(r'^bought/(\d+)/?$', 'buyable.views.boughtItem'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,7 +4,7 @@ from django.template import RequestContext
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
import datetime
|
import datetime
|
||||||
from models import Buyable, Purchase
|
from models import Buyable, Purchase, Order
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def showItems(request):
|
def showItems(request):
|
||||||
|
@ -36,34 +36,29 @@ def buyItem(request, itemid, buymode=""):
|
||||||
"""
|
"""
|
||||||
items = []
|
items = []
|
||||||
if buymode == "" or buymode == "with/deposit":
|
if buymode == "" or buymode == "with/deposit":
|
||||||
p = item.createPurchase(user, isDeposit=False)
|
p = item.createPurchase(isDeposit=False)
|
||||||
p.save()
|
p.save()
|
||||||
items.append(p)
|
items.append(p)
|
||||||
# TANNEK! if buymode == "with/dopsit" or buymode == "only/deposit":
|
# TANNEK! if buymode == "with/dopsit" or buymode == "only/deposit":
|
||||||
if buymode == "with/deposit" or buymode == "only/deposit":
|
if buymode == "with/deposit" or buymode == "only/deposit":
|
||||||
p = item.createPurchase(user, isDeposit=True)
|
p = item.createPurchase(isDeposit=True)
|
||||||
p.save()
|
p.save()
|
||||||
items.append(p)
|
items.append(p)
|
||||||
order = Order(user, items)
|
order = Order()
|
||||||
|
order.resetWithUser(user)
|
||||||
|
order.save() # for the id!
|
||||||
|
order.addItems(items)
|
||||||
order.save()
|
order.save()
|
||||||
return HttpResponseRedirect("/store/bought/%s/" % (order.id, deposit))
|
return HttpResponseRedirect("/store/bought/%s/" % (order.id))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def boughtItem(request, item1id, item2id=None):
|
def boughtItem(request, orderid):
|
||||||
if item1id == item2id:
|
|
||||||
item2id = None
|
|
||||||
error = None
|
error = None
|
||||||
try:
|
try:
|
||||||
item1 = Purchase.objects.get(id=item1id)
|
item = Order.objects.get(id=orderid)
|
||||||
if item2id:
|
except Order.DoesNotExist:
|
||||||
item2 = Purchase.objects.get(id=item2id)
|
error = "Die angegebene Order existiert nicht"
|
||||||
else:
|
if error == None and (item.user != request.user):
|
||||||
item2 = None
|
|
||||||
except Purchase.DoesNotExist:
|
|
||||||
item1 = None
|
item1 = None
|
||||||
item2 = None
|
|
||||||
error = "Konnte gekaufte Objekte nicht wiederfinden"
|
|
||||||
if error == None and (item1.user != request.user or (item2 != None and (item2.user != request.user))):
|
|
||||||
item1 = item2 = None
|
|
||||||
error = u"Diese Items gehören dir nicht"
|
error = u"Diese Items gehören dir nicht"
|
||||||
return render_to_response("buyables/itemBought.html", {'item1': item1, 'item2': item2, 'error': error}, RequestContext(request))
|
return render_to_response("buyables/itemBought.html", {'order': item, 'error': error}, RequestContext(request))
|
||||||
|
|
BIN
k4ever/k4ever.db
BIN
k4ever/k4ever.db
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
Loading…
Reference in New Issue