registrasion/views.py
def _handle_voucher(request, prefix):
    ''' Handles a voucher form in the given request. Returns the voucher
    form instance, and whether the voucher code was handled. '''

    voucher_form = forms.VoucherForm(request.POST or None, prefix=prefix)
    current_cart = CartController.for_user(request.user)

    if (voucher_form.is_valid() and
            voucher_form.cleaned_data["voucher"].strip()):

        voucher = voucher_form.cleaned_data["voucher"]
        voucher = inventory.Voucher.normalise_code(voucher)

        if len(current_cart.cart.vouchers.filter(code=voucher)) > 0:
            # This voucher has already been applied to this cart.
            # Do not apply code
            handled = False
        else:
            try:
                current_cart.apply_voucher(voucher)
            except Exception as e:
                voucher_form.add_error("voucher", e)
            handled = True
    else:
        handled = False

    return (voucher_form, handled)
def _handle_voucher(request, prefix):
    ''' Handles a voucher form in the given request. Returns the voucher
    form instance, and whether the voucher code was handled. '''

    voucher_form = forms.VoucherForm(request.POST or None, prefix=prefix)
    current_cart = CartController.for_user(request.user)

    if (voucher_form.is_valid() and
            voucher_form.cleaned_data["voucher"].strip()):

        voucher = voucher_form.cleaned_data["voucher"]
        voucher = inventory.Voucher.normalise_code(voucher)

        if len(current_cart.cart.vouchers.filter(code=voucher)) > 0:
            # This voucher has already been applied to this cart.
            # Do not apply code
            handled = False
        else:
            try:
                current_cart.apply_voucher(voucher)
            except Exception as e:
                voucher_form.add_error("voucher", e)
            handled = True
    else:
        handled = False

    return (voucher_form, handled)
def _handle_voucher ( request , prefix ) : voucher_form = forms . VoucherForm ( request . POST or None , prefix = prefix ) current_cart = CartController . for_user ( request . user ) if ( voucher_form . is_valid ( ) and voucher_form . cleaned_data [ "voucher" ] . strip ( ) ) : voucher = voucher_form . cleaned_data [ "voucher" ] voucher = inventory . Voucher . normalise_code ( voucher ) if len ( current_cart . cart . vouchers . filter ( code = voucher ) ) > 0 : # This voucher has already been applied to this cart. # Do not apply code handled = False else : try : current_cart . apply_voucher ( voucher ) except Exception as e : voucher_form . add_error ( "voucher" , e ) handled = True else : handled = False return ( voucher_form , handled )
Handles a voucher form in the given request. Returns the voucher
    form instance, and whether the voucher code was handled.
Handles a voucher form in the given request . Returns the voucher form instance and whether the voucher code was handled .