diff --git a/devel/TODO b/devel/TODO index b2cd621..4a3c7b7 100644 --- a/devel/TODO +++ b/devel/TODO @@ -17,3 +17,6 @@ Nice-to-haf: Konrad: 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 diff --git a/devel/api b/devel/api new file mode 100644 index 0000000..0d4bfe7 --- /dev/null +++ b/devel/api @@ -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 diff --git a/k4ever/api2/__init__.py b/k4ever/api2/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/k4ever/api2/handlers.py b/k4ever/api2/handlers.py new file mode 100644 index 0000000..e0e426b --- /dev/null +++ b/k4ever/api2/handlers.py @@ -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 diff --git a/k4ever/api2/models.py b/k4ever/api2/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/k4ever/api2/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/k4ever/api2/tests.py b/k4ever/api2/tests.py new file mode 100644 index 0000000..2247054 --- /dev/null +++ b/k4ever/api2/tests.py @@ -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 +"""} + diff --git a/k4ever/api2/urls.py b/k4ever/api2/urls.py new file mode 100644 index 0000000..4fed12a --- /dev/null +++ b/k4ever/api2/urls.py @@ -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), +) + diff --git a/k4ever/api2/views.py b/k4ever/api2/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/k4ever/api2/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/k4ever/buyable/models.py b/k4ever/buyable/models.py index d7f0804..09cb17d 100644 --- a/k4ever/buyable/models.py +++ b/k4ever/buyable/models.py @@ -18,6 +18,9 @@ class Buyable(models.Model): deposit = models.FloatField() description = models.TextField() buyableType = models.ManyToManyField(BuyableType) + + def hasDeposit(self): + return self.deposit > 0 def createPurchase(self, isDeposit=False): p = Purchase() @@ -31,7 +34,11 @@ class Buyable(models.Model): return p 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): user = models.ForeignKey(User) diff --git a/k4ever/buyable/templates/buyables/showItem.html b/k4ever/buyable/templates/buyables/showItem.html index 1c8036c..2958681 100644 --- a/k4ever/buyable/templates/buyables/showItem.html +++ b/k4ever/buyable/templates/buyables/showItem.html @@ -2,7 +2,12 @@ {% block "content" %} {% if item %} - You got the item {{ item }}.Buy it! it+deposit! only deposit! + You got the item {{ item }}. + Buy it! + {% if item.hasDeposit %} + it+deposit! + only deposit! + {% endif %} {% else %} No item found :( {% endif %} diff --git a/k4ever/buyable/templates/buyables/showItems.html b/k4ever/buyable/templates/buyables/showItems.html index 65b0510..e25e3e6 100644 --- a/k4ever/buyable/templates/buyables/showItems.html +++ b/k4ever/buyable/templates/buyables/showItems.html @@ -2,6 +2,7 @@ {% block "content" %} {% for item in items %} -{{ item }} {{ item.name }} + {{ item }} + {{ item.name }} {% endfor %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/k4ever/media/css/style.css b/k4ever/media/css/style.css index 221f1b3..0baa008 100644 --- a/k4ever/media/css/style.css +++ b/k4ever/media/css/style.css @@ -25,6 +25,12 @@ table, caption, tbody, tfoot, thead, tr, th, td { vertical-align: baseline; } +/* added by seba because nobody else did this. */ +.content { + margin: 5px; +} +/* end of addition */ + body { line-height: 1; } @@ -331,4 +337,4 @@ html body div#header div.search ul.ui-autocomplete li.ui-menu-item.focus { .meta:first-line { font-weight: bold; -} \ No newline at end of file +} diff --git a/k4ever/urls.py b/k4ever/urls.py index ab668b5..d2c666f 100644 --- a/k4ever/urls.py +++ b/k4ever/urls.py @@ -14,6 +14,7 @@ urlpatterns = patterns('', # user stuff? go to main (r'^$', 'main.views.startpage'), (r'^api/', include('api.urls')), + (r'^api2/', include('api2.urls')), (r'^user/', include('main.urls')), (r'^transaction/', include('transaction.urls')), (r'^store/', include('buyable.urls')),