Ejemplo n.º 1
0
    def create(self, ctx, form, inData):

        # So I don't mess up data
        data = {}
        data.update(inData)

        data.update(boundsFromFormFields(data['mForN']))
        data.pop('mForN')

        commonValidation(data)

        if not data['multiuse'] and not data['count']:
            raise formal.FormError( "One of 'multiuse' and 'count' must be specified" )

        if data['multiuse'] and data['count']:
            raise formal.FormError( "Only one of 'multiuse' and 'count' must be specified" )

        voucherDefinition = CategorisedVoucherDefinition(**data)
        if data['multiuse']:
            voucher = base.Voucher(code=data['code'])
            voucherDefinition.addVoucher(voucher)
        else:
            codes = base.generateCodes(data['code'], data['count'])
            for code in codes:
                voucher = base.Voucher(code=code)
                voucherDefinition.addVoucher(voucher)

        return voucherDefinition
Ejemplo n.º 2
0
    def create(self, ctx, form, data):

        if not data["multiuse"] and not data["count"]:
            raise formal.FormError("One of 'multiuse' and 'count' must be specified")

        if data["multiuse"] and data["count"]:
            raise formal.FormError("Only one of 'multiuse' and 'count' must be specified")

        if not AMOUNT_RE.match(data["amount"]):
            raise formal.FieldError("Unrecognised format", "amount")

        voucherDefinition = BasicVoucherDefinition(**data)

        if data["multiuse"]:
            voucher = base.Voucher(code=data["code"])
            voucherDefinition.addVoucher(voucher)
        else:
            codes = base.generateCodes(data["code"], data["count"])
            for code in codes:
                voucher = base.Voucher(code=code)
                voucherDefinition.addVoucher(voucher)

        return voucherDefinition