api2 beginning, minor changes
This commit is contained in:
parent
ad792b6747
commit
c7ad4be6e4
|
@ -17,3 +17,6 @@ Nice-to-haf:
|
||||||
|
|
||||||
Konrad:
|
Konrad:
|
||||||
Abmeldenutton rechts oder rot?
|
Abmeldenutton rechts oder rot?
|
||||||
|
- die liste der zu einkaufenden items ist doof :(
|
||||||
|
- /store/history/ ist noch kaputt + zeit unformatiert
|
||||||
|
- /transaction/ sehen die gemachten transactions noch nicht so cool aus
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
API
|
||||||
|
kaufen
|
||||||
|
produkte
|
||||||
|
auflisten
|
||||||
|
alle, nach gruppe
|
||||||
|
produktgruppen auflisten
|
||||||
|
suchen nach namen
|
||||||
|
hasDeposit falls kein attribut
|
||||||
|
beliebteste produkte (allgemein, nur vom user)
|
||||||
|
kaufen eines items (mit oder ohne deposit)
|
||||||
|
pfand zurückgeben
|
||||||
|
letzte einkäufe
|
||||||
|
|
||||||
|
|
||||||
|
transaction
|
||||||
|
auflisten zahlarten (bar, ueberweisung, ...)
|
||||||
|
einzahlen
|
||||||
|
auszahlen
|
||||||
|
letzte einzahlungen
|
||||||
|
|
||||||
|
api auth stuff
|
||||||
|
if plugin identifies by authblob
|
||||||
|
getUsersByAuthBlob (oderso)
|
||||||
|
else
|
||||||
|
authenticateUser(user, authblob)
|
||||||
|
listAuthBlobs (fuer alle user, die das plugin erlaubt haben)
|
||||||
|
canSuAsUser (noch ordentlich zu benennen)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cool wäre:
|
||||||
|
irgendwann letzte Änderung der produktliste speichern
|
||||||
|
|
||||||
|
=== REST LIKE API STARTS HERE ===
|
||||||
|
|
||||||
|
buyable/
|
||||||
|
item/
|
||||||
|
GET (=list)
|
||||||
|
""" get a specific item or a full (group) item list """
|
||||||
|
group item belonging to group
|
||||||
|
id item with id
|
||||||
|
POST (=buy)
|
||||||
|
""" buy an item"
|
||||||
|
id [REQ] buy item with id
|
||||||
|
deposit
|
||||||
|
types/
|
||||||
|
GET (=list)
|
||||||
|
""" list all types (groups) which an item can belong to """
|
||||||
|
|
||||||
|
transaction/
|
||||||
|
transact/
|
||||||
|
GET (=list)
|
||||||
|
""" list your transactions """
|
||||||
|
num list $num entries
|
||||||
|
POST (=pay)
|
||||||
|
""" actually transact money """
|
||||||
|
amount [REQ] amount to add to your account
|
||||||
|
type [REQ] type of transaction (id)
|
||||||
|
types/
|
||||||
|
GET (=list)
|
||||||
|
""" list all available transaction types"
|
||||||
|
auth/
|
||||||
|
blob/
|
||||||
|
GET (=get)
|
||||||
|
""" return authblob if allowed or auth if str given """
|
||||||
|
blob blob to get user from / auth user with, returns User or NULL
|
||||||
|
POST
|
||||||
|
""" set authblob if allowed """
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wget -q -O- --auth-no-challenge --http-user=seba -http-password=foobar23 http://devcat.someserver.de:13805/api2/buyable/item/foo
|
|
@ -0,0 +1,27 @@
|
||||||
|
from piston.handler import BaseHandler
|
||||||
|
from k4ever.buyable.models import *
|
||||||
|
from k4ever.transaction.models import *
|
||||||
|
|
||||||
|
class BuyableItemHandler(BaseHandler):
|
||||||
|
allowed_methods = ('GET', 'POST')
|
||||||
|
#fields = ('id', 'description')
|
||||||
|
model = Buyable
|
||||||
|
exclude = ('_state',)
|
||||||
|
|
||||||
|
#def read(self, request):
|
||||||
|
# return Buyable.objects.get(id=1)
|
||||||
|
|
||||||
|
class BuyableTypeHandler(BaseHandler):
|
||||||
|
allowed_methods = ('GET',)
|
||||||
|
model = BuyableType
|
||||||
|
|
||||||
|
class TransactionTransactHandler(BaseHandler):
|
||||||
|
allowed_methods = ('GET', 'POST')
|
||||||
|
model = Transaction
|
||||||
|
|
||||||
|
class TransactionTypeHandler(BaseHandler):
|
||||||
|
allowed_methods = ('GET',)
|
||||||
|
model = TransactionType
|
||||||
|
|
||||||
|
class AuthBlobHandler(BaseHandler):
|
||||||
|
pass
|
|
@ -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,26 @@
|
||||||
|
from django.conf.urls.defaults import *
|
||||||
|
from piston.resource import Resource
|
||||||
|
from piston.authentication import HttpBasicAuthentication
|
||||||
|
from api2.handlers import *
|
||||||
|
|
||||||
|
auth = HttpBasicAuthentication(realm="Freitagsrundenkassensystemapi")
|
||||||
|
ad = {'authentication': auth}
|
||||||
|
|
||||||
|
buyableItemRes = Resource(handler=BuyableItemHandler, **ad)
|
||||||
|
buyableTypeRes = Resource(handler=BuyableTypeHandler, **ad)
|
||||||
|
|
||||||
|
transactionTransactRes = Resource(handler=TransactionTransactHandler, **ad)
|
||||||
|
transactionTypeRes = Resource(handler=TransactionTypeHandler, **ad)
|
||||||
|
|
||||||
|
authBlobRes = Resource(handler=AuthBlobHandler, **ad)
|
||||||
|
|
||||||
|
urlpatterns = patterns('',
|
||||||
|
url(r'buyable/item/', buyableItemRes),
|
||||||
|
url(r'buyable/types/', buyableTypeRes),
|
||||||
|
|
||||||
|
url(r'transaction/transact/', transactionTransactRes),
|
||||||
|
url(r'transaction/types/', transactionTypeRes),
|
||||||
|
|
||||||
|
url(r'auth/blob/', authBlobRes),
|
||||||
|
)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
# Create your views here.
|
|
@ -18,6 +18,9 @@ class Buyable(models.Model):
|
||||||
deposit = models.FloatField()
|
deposit = models.FloatField()
|
||||||
description = models.TextField()
|
description = models.TextField()
|
||||||
buyableType = models.ManyToManyField(BuyableType)
|
buyableType = models.ManyToManyField(BuyableType)
|
||||||
|
|
||||||
|
def hasDeposit(self):
|
||||||
|
return self.deposit > 0
|
||||||
|
|
||||||
def createPurchase(self, isDeposit=False):
|
def createPurchase(self, isDeposit=False):
|
||||||
p = Purchase()
|
p = Purchase()
|
||||||
|
@ -31,7 +34,11 @@ class Buyable(models.Model):
|
||||||
return p
|
return p
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "%s (%s EUR/%s Pfand)" % (self.name, self.price, self.deposit)
|
item = "%s (%.2f EUR" % (self.name, self.price)
|
||||||
|
if self.hasDeposit():
|
||||||
|
item += "/%.2f Pfand" % self.deposit
|
||||||
|
item += ")"
|
||||||
|
return item
|
||||||
|
|
||||||
class Order(models.Model):
|
class Order(models.Model):
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User)
|
||||||
|
|
|
@ -2,7 +2,12 @@
|
||||||
|
|
||||||
{% block "content" %}
|
{% block "content" %}
|
||||||
{% if item %}
|
{% if item %}
|
||||||
You got the item {{ item }}.Buy <a href="/store/buy/{{ item.id }}/">it!</a> <a href="/store/buy/{{ item.id }}/with/deposit/">it+deposit!</a> <a href="/store/buy/{{ item.id }}/only/deposit/"> only deposit!</a>
|
You got the item {{ item }}.
|
||||||
|
Buy <a href="/store/buy/{{ item.id }}/">it!</a>
|
||||||
|
{% if item.hasDeposit %}
|
||||||
|
<a href="/store/buy/{{ item.id }}/with/deposit/">it+deposit!</a>
|
||||||
|
<a href="/store/buy/{{ item.id }}/only/deposit/"> only deposit!</a>
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
No item found :(
|
No item found :(
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
{% block "content" %}
|
{% block "content" %}
|
||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
<img src="{{ MEDIA_URL }}{{ item.image }}">{{ item }} <a href="/store/show/{{ item.id }}">{{ item.name }}</a>
|
<img src="{{ MEDIA_URL }}{{ item.image }}">{{ item }}
|
||||||
|
<a href="/store/show/{{ item.id }}">{{ item.name }}</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -25,6 +25,12 @@ table, caption, tbody, tfoot, thead, tr, th, td {
|
||||||
vertical-align: baseline;
|
vertical-align: baseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* added by seba because nobody else did this. */
|
||||||
|
.content {
|
||||||
|
margin: 5px;
|
||||||
|
}
|
||||||
|
/* end of addition */
|
||||||
|
|
||||||
body {
|
body {
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
}
|
}
|
||||||
|
@ -331,4 +337,4 @@ html body div#header div.search ul.ui-autocomplete li.ui-menu-item.focus {
|
||||||
|
|
||||||
.meta:first-line {
|
.meta:first-line {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ urlpatterns = patterns('',
|
||||||
# user stuff? go to main
|
# user stuff? go to main
|
||||||
(r'^$', 'main.views.startpage'),
|
(r'^$', 'main.views.startpage'),
|
||||||
(r'^api/', include('api.urls')),
|
(r'^api/', include('api.urls')),
|
||||||
|
(r'^api2/', include('api2.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