parent
4615033732
commit
9450f3326b
@ -0,0 +1,9 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block "content" %}
|
||||||
|
{% if item %}
|
||||||
|
You got the item {{ item }}
|
||||||
|
{% else %}
|
||||||
|
No item found :(
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
@ -0,0 +1,7 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block "content" %}
|
||||||
|
{% for item in items %}
|
||||||
|
<img src="{{ MEDIA_URL }}{{ item.image }}">{{ item }} <a href="/store/show/{{ item.id }}">{{ item.name }}</a>
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
@ -0,0 +1,8 @@
|
|||||||
|
from django.conf.urls.defaults import *
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = patterns('',
|
||||||
|
(r'^$', 'buyable.views.showItems'),
|
||||||
|
(r'^show/(\d+)/$', 'buyable.views.showItem'),
|
||||||
|
(r'^buy/(\d+)/$', 'buyable.views.buyItem'),
|
||||||
|
)
|
@ -1 +1,33 @@
|
|||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
from django.shortcuts import render_to_response
|
||||||
|
from django.template import RequestContext
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.http import HttpResponseRedirect
|
||||||
|
from models import Buyable
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def showItems(request):
|
||||||
|
# FIXME: Implement pagination here
|
||||||
|
items = Buyable.objects.all()
|
||||||
|
return render_to_response("buyables/showItems.html", {'items': items}, RequestContext(request))
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def showItem(request, itemid):
|
||||||
|
try:
|
||||||
|
item = Buyable.objects.get(id=itemid)
|
||||||
|
except Buyable.DoesNotExist:
|
||||||
|
# baww, kein item mit der id :( (oder mutax trollt rum)
|
||||||
|
return HttpResponseRedirect("/buy/")
|
||||||
|
return render_to_response("buyables/showItem.html", {'item': item}, RequestContext(request))
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def buyItem(request, itemid):
|
||||||
|
try:
|
||||||
|
item = Buyable.objects.get(id=itemid)
|
||||||
|
except Buyable.DoesNotExist:
|
||||||
|
# oh no! kein item mit der id :( mutax trollt rum)
|
||||||
|
return HttpResponseRedirect("/buy/")
|
||||||
|
purchase = Purchase(user=request.user, price=item.price, isDeposit=false )
|
||||||
|
purchase.create(item)
|
||||||
|
purchase.save()
|
||||||
|
return render_to_response("buyables/itemBought.html", {'item': item}, RequestContext(request))
|
Binary file not shown.
@ -0,0 +1,5 @@
|
|||||||
|
from models import UserProfile
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
admin.site.register(UserProfile)
|
||||||
|
|
@ -0,0 +1,71 @@
|
|||||||
|
from django import forms
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
import re
|
||||||
|
|
||||||
|
#class CurrencyField(forms.IntegerField):
|
||||||
|
# default_error_message = {
|
||||||
|
# 'invalid': _(u'Enter a number.'),
|
||||||
|
# }
|
||||||
|
# def __init__(self, positive=True, *args, **kwargs):
|
||||||
|
# super(IntegerField, self).__init__(*args, **kwargs)
|
||||||
|
# self.positive = positive
|
||||||
|
# def to_python(self, value):
|
||||||
|
# value = super(IntegerField, self).to_python(value)
|
||||||
|
# if value in validators.EMPTY_VALUES:
|
||||||
|
# return None
|
||||||
|
# try:
|
||||||
|
# value = float(value.replace(",", "."))
|
||||||
|
# except:
|
||||||
|
# pass
|
||||||
|
|
||||||
|
class CurrencyInput (forms.TextInput):
|
||||||
|
def render(self, name, value, attrs=None):
|
||||||
|
if value != '':
|
||||||
|
try:
|
||||||
|
value = u"%.2f" % value
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
return super(CurrencyInput, self).render(name, value, attrs)
|
||||||
|
|
||||||
|
|
||||||
|
class CurrencyField (forms.RegexField):
|
||||||
|
widget = CurrencyInput
|
||||||
|
currencyRe = re.compile(r'^[0-9]{1,5}([,\.][0-9][0-9]?)?$')
|
||||||
|
|
||||||
|
#currencyRe = re.compile(r'^[0-9]{1,5}(.[0-9][0-9]?)?$')
|
||||||
|
# currencyRe = re.compile(r"^[0-9]")
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(CurrencyField, self).__init__(
|
||||||
|
self.currencyRe, None, None, *args, **kwargs)
|
||||||
|
|
||||||
|
#class CurrencyField(forms.FloatField):
|
||||||
|
# widget = CurrencyInput
|
||||||
|
# moneyre = re.compile(r"^[0-9]{1,5}([\.][0-9][0-9])?$")
|
||||||
|
# def __init__(self, positive=False, allowPerCent=False, *args, **kwargs):
|
||||||
|
# super(forms.FloatField, self).__init__(*args, **kwargs)
|
||||||
|
# self.positive = positive
|
||||||
|
# self.allowPerCent = allowPerCent
|
||||||
|
def to_python(self, value):
|
||||||
|
#return super(forms.FloatField, self).to_python(value)
|
||||||
|
#raise ValidationError("WTF WTF WTF %s " % value)
|
||||||
|
#value = value.replace(",", ".")
|
||||||
|
#try:
|
||||||
|
# value = super(forms.FloatField, self).to_python(value)
|
||||||
|
#except ValidationError, e:
|
||||||
|
# raise NotImplementedError("%s %s" % (e, value))
|
||||||
|
#return value
|
||||||
|
value = value.replace(",", ".")
|
||||||
|
try:
|
||||||
|
value = float(value)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
raise ValidationError("Bitte gib eine Zahl ein")
|
||||||
|
# if not self.allowPerCent:
|
||||||
|
# tmpval = 100.0*value
|
||||||
|
# if tmpval == int(tmpval):
|
||||||
|
# raise ValidationError("Deine Zahl sollte nicht mehr als zwei Nachkommastellen haben. %s %s %s" % (tmpval, int(tmpval), tmpval-int(tmpval)))
|
||||||
|
# if self.positive and self.value < 0.0:
|
||||||
|
# raise ValidationError("Bitte gib eine positive Zahl an.")
|
||||||
|
return value
|
||||||
|
def clean(self, value):
|
||||||
|
value = super(CurrencyField, self).clean(value)
|
||||||
|
return float(value)
|
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 20 KiB |
@ -1,5 +1,24 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
from models import Transaction, TransactionType
|
from models import Transaction, TransactionType
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
admin.site.register(Transaction)
|
class TransactionAdmin(admin.ModelAdmin):
|
||||||
|
actions = ['really_delete_selected']
|
||||||
|
|
||||||
|
def get_actions(self, request):
|
||||||
|
actions = super(TransactionAdmin, self).get_actions(request)
|
||||||
|
del actions['delete_selected']
|
||||||
|
return actions
|
||||||
|
# FIXME: Can we instead of replacing the whole page just
|
||||||
|
# hook the release process? Also - make this nicer
|
||||||
|
# in terms of localization/naming foo
|
||||||
|
def really_delete_selected(self, request, queryset):
|
||||||
|
for obj in queryset:
|
||||||
|
obj.delete()
|
||||||
|
num = queryset.count()
|
||||||
|
message = "%s transaction%s" % (num, (num != 1 and "s" or ""))
|
||||||
|
self.message_user(request, u"Erfolgreich %s gelöscht." % message)
|
||||||
|
really_delete_selected.short_description = u"Ausgewählte transactions löschen"
|
||||||
|
|
||||||
|
admin.site.register(Transaction, TransactionAdmin)
|
||||||
admin.site.register(TransactionType)
|
admin.site.register(TransactionType)
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
from django import forms
|
||||||
|
from models import Transaction
|
||||||
|
from main.fields import CurrencyField
|
||||||
|
|
||||||
|
class TransactionForm(forms.ModelForm):
|
||||||
|
amount = CurrencyField()
|
||||||
|
class Meta:
|
||||||
|
model = Transaction
|
||||||
|
exclude = ('user', 'dateTime', 'checked')
|
||||||
|
def clean_amount(self):
|
||||||
|
data = self.cleaned_data['amount']
|
||||||
|
return data
|
@ -1,14 +1,31 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block "content" %}
|
{% block "content" %}
|
||||||
|
{% if transacted %}
|
||||||
|
<font color="green"><b>YOU DID IT!</b></font>. You transacted money!
|
||||||
|
{% endif %}
|
||||||
|
<form method="POST" action="/transaction/">
|
||||||
|
{% csrf_token %}
|
||||||
|
<table>
|
||||||
|
{{ form.as_table }}
|
||||||
|
</table>
|
||||||
|
<input type="submit" value="Senden">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
{% for transaction in history %}
|
{% for transaction in history %}
|
||||||
{{ transaction.amount }}, got that by {{ transaction.type }}
|
{% if forloop.first and transacted %}
|
||||||
|
<b>
|
||||||
|
{% endif %}
|
||||||
|
[ {{ transaction.dateTime }} ] {{ transaction.amount|floatformat:2 }} Euronen, got that by {{ transaction.transactionType }}
|
||||||
{% if transaction.checked %}
|
{% if transaction.checked %}
|
||||||
ist eingegangen
|
ist eingegangen
|
||||||
{% else %}
|
{% else %}
|
||||||
noch nicht da
|
noch nicht da
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if forloop.first and transacted %}
|
||||||
|
</b>
|
||||||
|
{% endif %}
|
||||||
<br />
|
<br />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block "content" %}
|
||||||
|
No content here.
|
||||||
|
{% endblock %}
|
@ -1,20 +1,36 @@
|
|||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.http import HttpResponseRedirect
|
||||||
from models import Transaction, TransactionType
|
from models import Transaction, TransactionType
|
||||||
|
from forms import TransactionForm
|
||||||
|
import datetime
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def overview(request):
|
def overview(request):
|
||||||
history = Transaction.objects.filter(user=request.user).order_by("dateTime")
|
history = Transaction.objects.filter(user=request.user).order_by("-dateTime")
|
||||||
return render_to_response("transaction/overview.html", {'history': history}, RequestContext(request))
|
transacted = False
|
||||||
|
if request.method == 'POST':
|
||||||
|
transaction = Transaction(user=request.user, dateTime=datetime.datetime.now())
|
||||||
|
form = TransactionForm(request.POST, instance=transaction)
|
||||||
|
if form.is_valid():
|
||||||
|
form.save()
|
||||||
|
form = TransactionForm()
|
||||||
|
transacted = True
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
form = TransactionForm()
|
||||||
|
return render_to_response("transaction/overview.html", {'history': history, 'form': form, 'transacted': transacted}, RequestContext(request))
|
||||||
|
|
||||||
#@login_required
|
@login_required
|
||||||
#def transfer(request):
|
def transact(request):
|
||||||
# if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
#
|
return render_to_response("transaction/transfered.html", RequestContext(request))
|
||||||
# return render_to_response("transaction/transfered.html", RequestContext(request))
|
else:
|
||||||
|
return HttpResponseRedirect("/transaction/")
|
||||||
|
|
||||||
#@kassenwart_required
|
#@kassenwart_required
|
||||||
#def checkTransfers(request):
|
#def checkTransfers(request):
|
||||||
# transfers = Transaction.objects.filter(checked=False).sort("dateTime")
|
# transfers = Transaction.objects.filter(checked=False).order_by("dateTime")
|
||||||
# return render_to_response("transaction/uncheckedTransfers.html", {'transfers' : tranfers}, RequestContext(request))
|
# return render_to_response("transaction/uncheckedTransfers.html", {'transfers' : tranfers}, RequestContext(request))
|
Loading…
Reference in new issue