Merge branch 'master' of someserver.de:k4ever
This commit is contained in:
commit
dec55d9561
|
@ -0,0 +1,3 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
|
@ -0,0 +1,23 @@
|
||||||
|
"""
|
||||||
|
This file demonstrates two different styles of tests (one doctest and one
|
||||||
|
unittest). These will both pass when you run "manage.py test".
|
||||||
|
|
||||||
|
Replace these with more appropriate tests for your application.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
class SimpleTest(TestCase):
|
||||||
|
def test_basic_addition(self):
|
||||||
|
"""
|
||||||
|
Tests that 1 + 1 always equals 2.
|
||||||
|
"""
|
||||||
|
self.failUnlessEqual(1 + 1, 2)
|
||||||
|
|
||||||
|
__test__ = {"doctest": """
|
||||||
|
Another way to test that 1 + 1 is equal to 2.
|
||||||
|
|
||||||
|
>>> 1 + 1 == 2
|
||||||
|
True
|
||||||
|
"""}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
from django.conf.urls.defaults import *
|
||||||
|
|
||||||
|
#/api/
|
||||||
|
urlpatterns = patterns('',
|
||||||
|
(r'^store/$', 'api.views.showItems'),
|
||||||
|
(r'^store/show/(\d+)/$', 'api.views.showItem'),
|
||||||
|
(r'^store/buy/(\d+)/(|with/deposit|only/deposit)/?$', 'api.views.buyItem'),
|
||||||
|
(r'^store/history/?$', 'api.views.history'),
|
||||||
|
)
|
|
@ -0,0 +1,72 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.http import HttpResponse
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from buyable.models import Buyable, Purchase, Order
|
||||||
|
from django.core import serializers
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def showItems(request):
|
||||||
|
# FIXME: Implement pagination here
|
||||||
|
items = Buyable.objects.all()
|
||||||
|
|
||||||
|
#return json-container
|
||||||
|
container = serializers.serialize('json', items)
|
||||||
|
return HttpResponse(container,'application/javascript')
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def showItem(request, itemid):
|
||||||
|
try:
|
||||||
|
item = Buyable.objects.get(id=itemid)
|
||||||
|
except Buyable.DoesNotExist:
|
||||||
|
# baww, kein item mit der id :( (oder mutax trollt rum)
|
||||||
|
return HttpResponse(status=400)
|
||||||
|
|
||||||
|
#return json-container
|
||||||
|
container = serializers.serialize('json', [item])
|
||||||
|
return HttpResponse(container,'application/javascript')
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def buyItem(request, itemid, buymode=""):
|
||||||
|
user = request.user
|
||||||
|
try:
|
||||||
|
item = Buyable.objects.get(id=itemid)
|
||||||
|
except Buyable.DoesNotExist:
|
||||||
|
# oh no! kein item mit der id :( mutax trollt rum)
|
||||||
|
return HttpResponseRedirect("/store/buy/")
|
||||||
|
""" tristate variable buymode:
|
||||||
|
"" only item
|
||||||
|
"with/deposit" item and deposit
|
||||||
|
"only/deposit" only deposit
|
||||||
|
"""
|
||||||
|
order = Order()
|
||||||
|
order.create(user)
|
||||||
|
order.save() # for the id!
|
||||||
|
if buymode == "" or buymode == "with/deposit":
|
||||||
|
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 = Purchase.create(order, item, isDeposit=True)
|
||||||
|
p.order = order
|
||||||
|
p.save()
|
||||||
|
order.updatePrice(commit=True)
|
||||||
|
order.save()
|
||||||
|
|
||||||
|
#return json-container
|
||||||
|
#container = serializers.serialize('json', items)
|
||||||
|
#return HttpResponse(container,'application/javascript')
|
||||||
|
return HttpResponse(status=200)
|
||||||
|
#return HttpResponseRedirect("/store/bought/%s/" % (order.id))
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def history(request):
|
||||||
|
hist = Order.objects.filter(user=request.user.id).order_by("-dateTime")
|
||||||
|
#return json-container
|
||||||
|
container = serializers.serialize('json', [hist])
|
||||||
|
return HttpResponse(container,'application/javascript')
|
||||||
|
|
BIN
k4ever/k4ever.db
BIN
k4ever/k4ever.db
Binary file not shown.
|
@ -1,8 +1,19 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block "content" %}
|
{% block "content" %}
|
||||||
|
{% if allMost %}
|
||||||
|
Am beliebtesten ist: <br /> <br />
|
||||||
|
{% for buyable in allMost %}
|
||||||
|
{{ buyable.buyable__name }} ( {{ buyable.num_buys }} mal) <br />
|
||||||
|
{% endfor %}
|
||||||
|
<br />
|
||||||
|
{% else %}
|
||||||
|
{{ error }}
|
||||||
|
Noch niemand hat was gekauft?
|
||||||
|
{% endif %}
|
||||||
|
<hr>
|
||||||
{% if usersMost %}
|
{% if usersMost %}
|
||||||
Am oeftesten hatten alle: <br /> <br />
|
Am oeftesten hattest du: <br /> <br />
|
||||||
{% for buyable in usersMost %}
|
{% for buyable in usersMost %}
|
||||||
{{ buyable.buyable__name }} ( {{ buyable.num_buys }} mal) <br />
|
{{ buyable.buyable__name }} ( {{ buyable.num_buys }} mal) <br />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -11,4 +22,15 @@
|
||||||
{{ error }}
|
{{ error }}
|
||||||
Nix gekauft?
|
Nix gekauft?
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<hr>
|
||||||
|
{% if usersLast %}
|
||||||
|
Als letztes hattest du: <br /> <br />
|
||||||
|
{% for buyable in usersLast %}
|
||||||
|
{{ buyable.buyable__name }} <br />
|
||||||
|
{% endfor %}
|
||||||
|
<br />
|
||||||
|
{% else %}
|
||||||
|
{{ error }}
|
||||||
|
Noch nix gekauft?
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -7,8 +7,13 @@ from buyable.models import Purchase, Buyable
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def startpage(request):
|
def startpage(request):
|
||||||
usersMost = Purchase.objects.values('buyable__name').annotate(num_buys=Count('buyable')).order_by('-num_buys')
|
''' Diese Funktion wird wahrscheinlich viel Last erzeugen, da
|
||||||
return render_to_response("main/startpage.html", {'usersMost': usersMost}, RequestContext(request))
|
sie ueber mehrere Tabellen joined,filtered und wieder reduced.
|
||||||
|
'''
|
||||||
|
allMost = Purchase.objects.filter(isDeposit=False).values('buyable__name').annotate(num_buys=Count('buyable')).order_by('-num_buys')
|
||||||
|
usersMost = Purchase.objects.filter(isDeposit=False).values('buyable__name').filter(order__user=request.user.id).annotate(num_buys=Count('buyable')).order_by('-num_buys')
|
||||||
|
usersLast = Purchase.objects.filter(isDeposit=False).values('buyable__name').filter(order__user=request.user.id).order_by('-order__dateTime')
|
||||||
|
return render_to_response("main/startpage.html", {'allMost' : allMost,'usersMost': usersMost, 'usersLast' : usersLast}, RequestContext(request))
|
||||||
|
|
||||||
def register(request):
|
def register(request):
|
||||||
return render_to_response("registration/register.html", RequestContext(request))
|
return render_to_response("registration/register.html", RequestContext(request))
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 7.3 KiB |
|
@ -13,6 +13,7 @@ urlpatterns = patterns('',
|
||||||
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
||||||
# user stuff? go to main
|
# user stuff? go to main
|
||||||
(r'^$', 'main.views.startpage'),
|
(r'^$', 'main.views.startpage'),
|
||||||
|
(r'^api/', include('api.urls')),
|
||||||
(r'^user/', include('main.urls')),
|
(r'^user/', include('main.urls')),
|
||||||
(r'^transaction/', include('transaction.urls')),
|
(r'^transaction/', include('transaction.urls')),
|
||||||
(r'^store/', include('buyable.urls')),
|
(r'^store/', include('buyable.urls')),
|
||||||
|
|
Loading…
Reference in New Issue