@permission_required("core.manage_shop")
def add_vouchers(request, group_id):
    """
    """
    voucher_group = VoucherGroup.objects.get(pk=group_id)
    form = VoucherForm(data=request.POST)

    msg = ""

    if form.is_valid():
        try:
            amount = int(request.POST.get("amount", 0))
        except __HOLE__:
            amount = 0

        for i in range(0, amount):
            number = lfs.voucher.utils.create_voucher_number()
            counter = 0
            while Voucher.objects.filter(number=number).exists() and counter < 100:
                number = lfs.voucher.utils.create_voucher_number()
                counter += 1

            if counter == 100:
                msg = _(u"Unable to create unique Vouchers for the options specified.")
                break

            Voucher.objects.create(
                number=number,
                group=voucher_group,
                creator=request.user,
                kind_of=request.POST.get("kind_of", 0),
                value=request.POST.get("value", 0.0),
                start_date=request.POST.get("start_date"),
                end_date=request.POST.get("end_date"),
                effective_from=request.POST.get("effective_from"),
                tax_id=request.POST.get("tax"),
                limit=request.POST.get("limit")
            )

            msg = _(u"Vouchers have been created.")

    return render_to_ajax_response(
        (("#vouchers", vouchers_tab(request, voucher_group)), ),
        msg)
dataset/ETHPy150Open diefenbach/django-lfs/lfs/manage/voucher/views.py/add_vouchers