diff --git a/devel/TODO b/devel/TODO index 60bcf13..eb70cb9 100644 --- a/devel/TODO +++ b/devel/TODO @@ -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? diff --git a/devel/api b/devel/api deleted file mode 100644 index 36f5d83..0000000 --- a/devel/api +++ /dev/null @@ -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/ - 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 diff --git a/k4ever/api2/handlers.py b/k4ever/api2/handlers.py index 50f702f..eaa497e 100644 --- a/k4ever/api2/handlers.py +++ b/k4ever/api2/handlers.py @@ -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: diff --git a/k4ever/buyable/models.py b/k4ever/buyable/models.py index 3fb5a28..959c684 100644 --- a/k4ever/buyable/models.py +++ b/k4ever/buyable/models.py @@ -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) diff --git a/k4ever/docs/django/api.rst b/k4ever/docs/django/api.rst index 4e2ee0a..72af8c0 100644 --- a/k4ever/docs/django/api.rst +++ b/k4ever/docs/django/api.rst @@ -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]/ ` - :func:`GET ` - Get a specific item or a full/type item list. + :func:`GET ` + 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 ` diff --git a/k4ever/docs/index.rst b/k4ever/docs/index.rst index 354eac4..25148f7 100644 --- a/k4ever/docs/index.rst +++ b/k4ever/docs/index.rst @@ -12,6 +12,7 @@ Contents: :maxdepth: 2 django/api + faq Indices and tables ==================