def vouchers_new(): form = NewVoucherForm(flask.request.form) choices = [] if current_user.has_role('gateway-admin'): choices = [[ current_user.gateway_id, '%s - %s' % (current_user.gateway.network.title, current_user.gateway.title) ]] else: if current_user.has_role('network-admin'): networks = Network.query.filter_by(id=current_user.network_id).all() else: networks = Network.query.all() for network in networks: for gateway in network.gateways: choices.append([ gateway.id, '%s - %s' % (network.title, gateway.title) ]) form.gateway_id.choices = choices if form.validate_on_submit(): voucher = Voucher() form.populate_obj(voucher) if current_user.has_role('gateway-admin'): voucher.gateway_id = current_user.gateway_id db.session.add(voucher) db.session.commit() return flask.redirect(flask.url_for('.vouchers_new', id=voucher.id)) return flask.render_template('vouchers/new.html', form=form)
def vouchers_new(): form = NewVoucherForm(flask.request.form) choices = [] if current_user.has_role('gateway-admin'): choices = [[ current_user.gateway_id, '%s - %s' % (current_user.gateway.network.title, current_user.gateway.title) ]] else: if current_user.has_role('network-admin'): networks = Network.query.filter_by(id=current_user.network_id).all() else: networks = Network.query.all() for network in networks: for gateway in network.gateways: choices.append([ gateway.id, '%s - %s' % (network.title, gateway.title) ]) form.gateway_id.choices = choices if form.validate_on_submit(): voucher = Voucher() form.populate_obj(voucher) if current_user.has_role('gateway-admin'): voucher.gateway_id = current_user.gateway_id db.session.add(voucher) db.session.commit() return flask.redirect(flask.url_for('.vouchers_new', code=voucher.code)) return flask.render_template('vouchers/new.html', form=form)
def create_voucher(gateway, minutes=60, id=None, quiet=True): voucher = Voucher() # Allow explicit setting of ID (for tests) if id is not None: voucher.id = id voucher.gateway_id = gateway voucher.minutes = minutes db.session.add(voucher) db.session.commit() if not quiet: print 'Voucher created: %s' % voucher.id
def create_voucher(gateway, minutes=60, code=None, quiet=True): voucher = Voucher() # Allow explicit setting of code (for tests) if code is not None: voucher.code = code voucher.gateway_id = gateway voucher.minutes = minutes db.session.add(voucher) db.session.commit() if not quiet: print 'Voucher created: %s:%s' % (voucher.id, voucher.code)