added barcodesupport, docs and removed old apidoc

This commit is contained in:
seba 2011-10-06 02:10:16 +02:00
parent 83ac56d9e4
commit 6ee2e91338
6 changed files with 30 additions and 98 deletions

View File

@ -26,6 +26,7 @@ Nice-to-haf:
Open for discussion:
- default value von 10 fuer num bei api history && alte transactions?
- 15, besser 20:Man sucht auf ja nach etwas und will sich nicht totklicken ~~~TKroenert
Konrad:
Abmeldenutton rechts oder rot?

View File

@ -1,91 +0,0 @@
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
TODO
write loader for url-encoded POST data
write "bash" output format
=== REST LIKE API STARTS HERE ===
buyable/
item/<itemId>
GET (=list)
""" get a specific item or a full (group) item list """
group item belonging to group
POST (=buy)
""" buy an item"
deposit Set to > 0 if you want to buy with deposit (default 0)
amount amount of items to buy (default 1)
types/
GET (=list)
""" list all types (groups) which an item can belong to """
history/
GET (=list)
""" list the last orders of a user """
num number of entries
account/
transactions/ or transfers/
transact/ or transfer/ # sollte eigentlich transfer heißen imo
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"
balance/
GET (=show)
""" return current account balance """
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 """
user/
GET (=get)
""" get user by authblob string - this function works only when plugin
has unique authblobs """
authblob [REQ] authblob to sear
config/
GET (=get)
""" Display site configuration vars (as in mediaurl) """
wget -qS -O- --auth-no-challenge --http-user=seba --http-password=foobar23 http://devcat.someserver.de:13805/api2/buyable/item/foo

View File

@ -4,6 +4,7 @@ from k4ever.buyable.models import *
from k4ever.transaction.models import *
from django.contrib.auth.decorators import user_passes_test
from django.contrib.auth.models import Group
from django.core.exceptions import MultipleObjectsReturned
from decorators import *
from decimal import Decimal, InvalidOperation
from helper import *
@ -20,14 +21,29 @@ class BuyableItemHandler(BaseHandler):
def read(self, request, itemId=None):
"""Get one or multiple items.
- type: Only get items belonging to this type
- type: Only get items belonging to this type
- barcode: Return only item(s) with this barcode
Note that neither type nor barcode is used if an item id
is specified.
"""
barcode = request.GET.get('barcode', None)
if itemId == None:
if request.GET.has_key('type'):
obj = Buyable.objects.filter(buyableType__name=request.GET['type'])
obj = Buyable.objects.all()
if barcode and barcode != '':
# try to get specific object or return 404
try:
return Buyable.objects.get(barcode=barcode)
except MultipleObjectsReturned:
ret = rc.DUPLICATE_ENTRY
ret.write("\nWe found more than one entry with this barcode. Bad.\n")
return ret
except Buyable.DoesNotExist:
return rc.NOT_FOUND
else:
obj = Buyable.objects.all()
return obj
if request.GET.has_key('type'):
obj = Buyable.objects.filter(buyableType__name=request.GET['type'])
return obj
try:
return Buyable.objects.get(id=itemId)
except Buyable.DoesNotExist:

View File

@ -19,6 +19,8 @@ class Buyable(models.Model):
deposit = models.DecimalField(max_digits=8, decimal_places=2)
description = models.TextField()
buyableType = models.ManyToManyField(BuyableType)
barcode = models.CharField(max_length=100, unique=True)
def hasDeposit(self):
return self.deposit > Decimal(0)

View File

@ -4,6 +4,8 @@ API
- how to access the read/write/put/create functions
- what this api does and what not
k4evers API
Authentication
--------------
- how does authentication work
@ -18,13 +20,14 @@ to the handler or the responsible method for more documentation or code.
**buyable/**
:class:`item/[itemId]/ <api2.handlers.BuyableItemHandler>`
:func:`GET <api2.handlers.BuyableItemHandler.read>`
Get a specific item or a full/type item list.
:func:`GET <api2.handlers.BuyableItemHandler.read>`
Get a specific item or a full/type item list.
========= =======================
Parameter Description
========= =======================
type item belonging to type-group
barcode item with this barcode
========= =======================
:func:`POST <api2.handlers.BuyableItemHandler.create>`

View File

@ -12,6 +12,7 @@ Contents:
:maxdepth: 2
django/api
faq
Indices and tables
==================