From 171bc9827df84e586d7b1f29f3020235c9745b7c Mon Sep 17 00:00:00 2001 From: seba Date: Sun, 2 Oct 2011 17:58:54 +0200 Subject: [PATCH] Added current devcat status to git --- devel/TODO | 10 +++ devel/api | 5 ++ k4ever/api2/authentication.py | 68 +++++++++++++++++ k4ever/api2/handlers.py | 13 ++++ k4ever/api2/urls.py | 2 + .../buyable/templates/buyables/history.html | 5 +- .../templates/buyables/itemBought.html | 13 +++- .../buyable/templates/buyables/showItem.html | 75 ++++++++++++++----- .../buyable/templates/buyables/showItems.html | 41 ++++++++-- k4ever/media/css/style.css | 54 +++++++++++++ k4ever/settings.py | 2 +- k4ever/transaction/forms.py | 2 +- k4ever/transaction/models.py | 2 +- .../templates/transaction/overview.html | 35 ++++++--- 14 files changed, 283 insertions(+), 44 deletions(-) create mode 100644 k4ever/api2/authentication.py diff --git a/devel/TODO b/devel/TODO index 8db1c9d..97652cb 100644 --- a/devel/TODO +++ b/devel/TODO @@ -11,11 +11,21 @@ Noch zu tun: [ ] doku [ ] API(wget)-Beispiele [ ] Authblob erlaubt momentan beliebige größe - beschrängen auf 10kb o.ä. +[ ] API erlauben mehrere Items auf eine Order zu setzen (und damit auch deposit zu getränk zu kaufen) Nice-to-haf: [x] Search'n'Buy [ ] Einstellungen (email bei ueberweisung,...?) +[ ] Django Admin interface in Seite eingeliedern (Normales Kassensystemmenu drueber)) + http://www.djangobook.com/en/1.0/chapter17/ + http://www.slideshare.net/maheshshtl/the-django-admin-interface + http://www.slideshare.net/lincolnloop/customizing-the-django-admin +[ ] Pagination fuer die Einkaufshistory und ggf. fuer die Buyable sites + https://docs.djangoproject.com/en/dev/topics/pagination/ + +Open for discussion: + - default value von 10 fuer num bei api history && alte transactions? Konrad: Abmeldenutton rechts oder rot? diff --git a/devel/api b/devel/api index e3220e0..36f5d83 100644 --- a/devel/api +++ b/devel/api @@ -49,6 +49,11 @@ buyable/ 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/ diff --git a/k4ever/api2/authentication.py b/k4ever/api2/authentication.py new file mode 100644 index 0000000..f234c3d --- /dev/null +++ b/k4ever/api2/authentication.py @@ -0,0 +1,68 @@ +from django.conf import settings +from django.contrib.auth import REDIRECT_FIELD_NAME +from django.http import HttpResponse, HttpResponseRedirect +from django.utils.http import urlquote + +# taken and modified from +# https://bitbucket.org/yml/django-piston/src/dfb826a31ca8/piston/authentication.py + +class DjangoAuthentication(object): + """ + Django authentication. + """ + def __init__(self, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): + if not login_url: + login_url = settings.LOGIN_URL + self.login_url = login_url + self.redirect_field_name = redirect_field_name + self.request = None + + def is_authenticated(self, request): + """ + This method call the `is_authenticated` method of django + User in django.contrib.auth.models. + + `is_authenticated`: Will be called when checking for + authentication. It returns True if the user is authenticated + False otherwise. + """ + self.request = request + return request.user.is_authenticated() + + def challenge(self): + """ + `challenge`: In cases where `is_authenticated` returns + False, the result of this method will be returned. + This will usually be a `HttpResponse` object with + some kind of challenge headers and 401 code on it. + """ + path = urlquote(self.request.get_full_path()) + tup = self.login_url, self.redirect_field_name, path + return HttpResponseRedirect('%s?%s=%s' %tup) + +# taken from +# http://staer.github.com/2011/01/21/piston-multi-auth.html +class MultiAuthentication(object): + """ Authenticated Django-Piston against multiple types of authentication """ + + def __init__(self, auth_types): + """ Takes a list of authenication objects to try against, the default + authentication type to try is the first in the list. """ + self.auth_types = auth_types + self.selected_auth = auth_types[0] + + def is_authenticated(self, request): + """ Try each authentication type in order and use the first that succeeds """ + authenticated = False + for auth in self.auth_types: + authenticated = auth.is_authenticated(request) + if authenticated: + selected_auth = auth + break + return authenticated + + def challenge(self): + """ Return the challenge for whatever the selected auth type is (or the default + auth type which is the first in the list)""" + return self.selected_auth.challenge() + diff --git a/k4ever/api2/handlers.py b/k4ever/api2/handlers.py index 9f4f917..4b1b893 100644 --- a/k4ever/api2/handlers.py +++ b/k4ever/api2/handlers.py @@ -78,6 +78,19 @@ class BuyableTypeHandler(BaseHandler): allowed_methods = ('GET',) model = BuyableType +class HistoryHandler(BaseHandler): + allowed_methods = ('GET',) + fields = ('id', 'price', 'dateTime', ('purchase_set', (('buyable', ('id', )), 'price', 'name'))) + + @manglePluginPerms + def read(self, request): + num = getInt(request.GET, 'num', 0) + qset = Order.objects.filter(user=request.user) + if num > 0: + return qset[:num] + return qset + + class TransactionTransactHandler(BaseHandler): allowed_methods = ('GET', 'POST') model = Transaction diff --git a/k4ever/api2/urls.py b/k4ever/api2/urls.py index 40101c2..309d28b 100644 --- a/k4ever/api2/urls.py +++ b/k4ever/api2/urls.py @@ -19,6 +19,7 @@ ad = {'authentication': multiAuth} buyableItemRes = CsrfExemptResource(handler=BuyableItemHandler, **ad) buyableTypeRes = CsrfExemptResource(handler=BuyableTypeHandler, **ad) +historyRes = CsrfExemptResource(handler=HistoryHandler, **ad) transactionTransactRes = CsrfExemptResource(handler=TransactionTransactHandler, **ad) transactionTypeRes = CsrfExemptResource(handler=TransactionTypeHandler, **ad) @@ -34,6 +35,7 @@ urlpatterns = patterns('', url(r'buyable/item/?$', buyableItemRes), url(r'buyable/item/(?P\d+)/?$', buyableItemRes), url(r'buyable/types/?$', buyableTypeRes), + url(r'buyable/history/?$', historyRes), url(r'account/transactions/transact/?$', transactionTransactRes), url(r'account/transfers/transfer/?$', transactionTransactRes), diff --git a/k4ever/buyable/templates/buyables/history.html b/k4ever/buyable/templates/buyables/history.html index 7b74ebc..417f3f3 100644 --- a/k4ever/buyable/templates/buyables/history.html +++ b/k4ever/buyable/templates/buyables/history.html @@ -2,7 +2,8 @@ {% block "content" %} {% if history %} - +

Frühere Einkäufe von {{ user }}

+
@@ -34,6 +35,6 @@
Buchung
{% else %} {{ error }} - Alle alle die Orders :( + Es scheint so, als hättest du bisher noch nichts gekauft, {{ user }}. {% endif %} {% endblock %} diff --git a/k4ever/buyable/templates/buyables/itemBought.html b/k4ever/buyable/templates/buyables/itemBought.html index 280b0e9..0b138c0 100644 --- a/k4ever/buyable/templates/buyables/itemBought.html +++ b/k4ever/buyable/templates/buyables/itemBought.html @@ -1,13 +1,20 @@ {% extends "base.html" %} {% block "content" %} +

{% if not error %} - You got the order {{ order }} +

Danke für deinen Einkauf, {{ order.user }}.

+ Du hast soeben {% for item in order.purchase_set.all %} {{ item }} - {% endfor %} + {% endfor %} zum Gesamtpreis von {{ order.price|floatformat:2 }}€ gekauft.

+

+ Noch mehr einkaufen! {% else %} {{ error }} - Junge junge junge +

Es ist ein Fehler aufgetreten.

+

+

Zurück zum Einkauf {% endif %} +

{% endblock %} diff --git a/k4ever/buyable/templates/buyables/showItem.html b/k4ever/buyable/templates/buyables/showItem.html index 5a5a282..67774d7 100644 --- a/k4ever/buyable/templates/buyables/showItem.html +++ b/k4ever/buyable/templates/buyables/showItem.html @@ -1,28 +1,69 @@ {% extends "base.html" %} {% block "content" %} +

Zur Liste aller Items

{% if item %} - +
- + - - + - - - - - - - -
+ + + + + + + + + + + + + + + +
+
{{ item.name }}
+ +
+ Kategorie{{ item.buyableType.all.count|pluralize:"n"}}: + {% for type in item.buyableType.all %} + {{ type }}
+ {% endfor %} +
+ Preis: + + {{ item.price|floatformat:2 }} € {% if item.hasDeposit %}(+ Pfand {{ item.deposit|floatformat:2 }} €) {% endif %} +
+ "{{ item.description }}" +
+
Zugehörig zu:{% for type in item.buyableType.all %} - {{ type }} - {% endfor %} + + + + + + +
+ {% if item.hasDeposit %} + Kaufen - {{ item.price|floatformat:2 }} €
+ {{ item.deposit|floatformat:2 }} € Pfand
+ {% else %} +   + {% endif %} +
+ Kaufen - {{ item.price|floatformat:2 }} €
{% if item.hasDeposit %} (Ohne Pfand){% endif %}
+
+ {% if item.hasDeposit %} + Kaufen
nur {{ item.deposit|floatformat:2 }} € Pfand
+ {% else %} +   + {% endif %} +
+
Kauf {{ 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 65eed81..7c34b30 100644 --- a/k4ever/buyable/templates/buyables/showItems.html +++ b/k4ever/buyable/templates/buyables/showItems.html @@ -1,11 +1,37 @@ {% extends "base.html" %} {% block "content" %} -{% for item in items %} -
- -
{{ item }} -
Buy it! +
+ + {% for item in items %} + + + + + + + + {% comment %} + Buy it! {% if item.hasDeposit %} it+deposit! only deposit! @@ -14,6 +40,7 @@ {% for type in item.buyableType.all %} {{ type }} {% endfor %} ) - -{% endfor %} + {% endcomment %} + {% endfor %} +
+ + + {{ item.name }}
+ Details +
+ Kaufen für {{ item.price|floatformat:2 }} €
{% if item.hasDeposit %} (Ohne Pfand){% endif %}
+
+ {% if item.hasDeposit %} + Kaufen für {{ item.price|floatformat:2 }} €
+ {{ item.deposit|floatformat:2 }} € Pfand
+ {% else %} +   + {% endif %} +
+ {% if item.hasDeposit %} + Kaufen
nur {{ item.deposit|floatformat:2 }} € Pfand
+ {% else %} +   + {% endif %} +
{% endblock %} diff --git a/k4ever/media/css/style.css b/k4ever/media/css/style.css index 0baa008..18aaad9 100644 --- a/k4ever/media/css/style.css +++ b/k4ever/media/css/style.css @@ -338,3 +338,57 @@ html body div#header div.search ul.ui-autocomplete li.ui-menu-item.focus { .meta:first-line { font-weight: bold; } + +/* TABLE */ +/* Edited by Theri */ +table.showitem { + border:1px solid #DFDFDF; + border-collapse: separate; + border-spacing: 5pt; +} + +table.showitem td { + vertical-align: middle; +} + +table.showitem th { + vertical-align: middle; + text-align:center; +} + +table.details { + border-width: 0px; + margin-top: 25px; +} + +table.details th { + vertical-align: middle; + text-align: center; +} + +table.details td { + vertical-align: middle; + text-align: center; +} + +.content a { + color: #3398CC; + text-decoration: none; +} + +.content a.button { + text-align: center; + display: block; + margin-top: 7px; + padding: 0 10px; +} + +.content a:hover { + background: #3398CC; + color: white; +} + +.content h1 { + font: 20px "lucida grande", tahoma, verdana, arial, sans-serif; + text-align: center; +} diff --git a/k4ever/settings.py b/k4ever/settings.py index b02f66a..0640914 100644 --- a/k4ever/settings.py +++ b/k4ever/settings.py @@ -74,7 +74,7 @@ LOGIN_REDIRECT_URL = '/' AUTHENTICATION_BACKENDS = ( # 'main.backend.CustomLDAPBackend', - 'django_auth_ldap.backend.LDAPBackend', +# 'django_auth_ldap.backend.LDAPBackend', 'django.contrib.auth.backends.ModelBackend', ) diff --git a/k4ever/transaction/forms.py b/k4ever/transaction/forms.py index 86c5365..1bf71fe 100644 --- a/k4ever/transaction/forms.py +++ b/k4ever/transaction/forms.py @@ -3,7 +3,7 @@ from models import Transaction from main.fields import CurrencyField class TransactionForm(forms.ModelForm): - amount = CurrencyField() + amount = CurrencyField(label='Betrag') class Meta: model = Transaction exclude = ('user', 'dateTime', 'checked') diff --git a/k4ever/transaction/models.py b/k4ever/transaction/models.py index 276a11b..3916c0e 100644 --- a/k4ever/transaction/models.py +++ b/k4ever/transaction/models.py @@ -10,7 +10,7 @@ class TransactionType(models.Model): class Transaction(models.Model): user = models.ForeignKey(User) - transactionType = models.ForeignKey(TransactionType) + transactionType = models.ForeignKey(TransactionType, verbose_name='Typ') dateTime = models.DateTimeField() amount = models.DecimalField(max_digits=8, decimal_places=2) checked = models.BooleanField(default=False) diff --git a/k4ever/transaction/templates/transaction/overview.html b/k4ever/transaction/templates/transaction/overview.html index 408f405..742f6f5 100644 --- a/k4ever/transaction/templates/transaction/overview.html +++ b/k4ever/transaction/templates/transaction/overview.html @@ -3,33 +3,44 @@ {% block "content" %} {% if transacted %} {% if error %} - ARGHZ. U broakzt t3h formul4r! +

Es ist beim Aufladen ein Fehler aufgetreten.

{% else %} - YOU DID IT!. You transacted money! +

Du hast Geld aufgeladen.

{% endif %} {% endif %} -
- {% csrf_token %} - - {{ form.as_table }} -
- -
- +

Konto aufladen

+ nsactionType: + Amount
+ {% csrf_token %} + + {{ form.as_table }} + + + + +
+   + + +
+
+
+

Vergangene Transaktionen:

{% for transaction in history %} {% if forloop.first and transacted %} {% endif %} - [ {{ transaction.dateTime }} ] {{ transaction.amount|floatformat:2 }} Euronen durch: {{ transaction.transactionType }} + [ {{ transaction.dateTime }} ] {{ transaction.amount|floatformat:2 }} € durch {{ transaction.transactionType }} {% if not transaction.transactionType.needsCheck or transaction.checked %} eingegangen {% else %} - aber noch nicht bestaetigt + aber noch nicht bestätigt {% endif %} {% if forloop.first and transacted %} {% endif %}
{% endfor %} +
{% endblock %}