Пример #1
0
def index(request):
    account = request.session.get('account', None)
    items = request.session.get('items', None)
    
    if items == None:
        items = request.session['items'] = []

    if request.method == 'POST' and request.POST['inputfield']:
        inputfield = request.POST['inputfield']
        if inputfield == 'Clear':
            items = request.session['items'] = []
            account = request.session['account'] = None
        elif inputfield == 'Accept':
            account = AccountCode.get_or_code(account)
            if hasattr(account,"account") and len(items) > 0:
                account.account.debit(sum([maybe_get_price(Barcode.get_or_code(item)) for item in items]))
                items = request.session['items'] = []
                account = request.session['account'] = None
        else: 
            if account:
                items.append(inputfield)
                request.session.modified = True
            else:
                account = request.session['account'] = inputfield
                request.session.modified = True
    
    account = AccountCode.get_or_code(account)
    if not hasattr(account,"account"):
        request.session["account"]=None
        inputlabel=u"Nimi tilille"
    elif account:
        inputlabel=u"Syötä tuote"
    else:
        inputlabel=u"Syötä tili"
    items = [Barcode.get_or_code(x) for x in items]
    data = {'account': account, 'inputlabel' : inputlabel, 'items': items[::-1], 'total' : sum([maybe_get_price(item) for item in items])}
    return render_to_response('osto/index.html',
        data,
        context_instance=RequestContext(request))
Пример #2
0
def index(request):
    items = request.session.get('items', None)

    if items == None:
        items = request.session['items'] = []

    if request.method == 'POST' and request.POST['inputfield']:
        if request.POST['inputfield'] == 'CLEAR':
            items = request.session['items'] = []
        else:
            items.append(request.POST['inputfield'])
            request.session.modified = True

    items = [Barcode.get_or_code(x) for x in items]
    data = {'items': items[::-1]}
    return render_to_response('osto/index.html',
                              data,
                              context_instance=RequestContext(request))
Пример #3
0
def index(request):
	items = request.session.get('items', None)

	if items == None:
		items = request.session['items'] = []
	
	if request.method == 'POST' and request.POST['inputfield']:
		if request.POST['inputfield'] == 'CLEAR':
			items = request.session['items'] = []
		else:
			items.append(request.POST['inputfield'])
			request.session.modified = True
	
	items = [Barcode.get_or_code(x) for x in items]
	data = {'items': items[::-1]}
	return render_to_response('osto/index.html',
		data,
		context_instance=RequestContext(request))