def command_edit_post(id): command = Command.get(id=id) data = request.forms if ' ' in data['command']: danger(_("Spaces are not allowed in commands.")) # TODO Redirect to the edit page return { 'apis': get_apis(), 'data': data, } with db.atomic(): command.command = data['command'] command.save() command.clear_actions() for i in range(int(data['actions_number'])): # Each action has actionX prepended to its inputs namespace = 'action{0}'.format(i) module, method = data['{0}_action_type'.format(namespace)].split('|') parameters = { key[len(namespace):]: value for key, value in data.items() if key.startswith(namespace) and not key.endswith('_action_type') } action = Action.create(module=module, method=method, parameters=json.dumps(parameters)) CommandAction.create(command=command, action=action, order=i) success(_("Command edited.")) return redirect(app.get_url('commands:list'))
def command_delete(id): if Command.get(id=id).delete_instance(): CommandAction.delete().where(CommandAction.command == id).execute() success(_("Command deleted.")) else: danger(_("Error while deleting command.")) return redirect(app.get_url('commands:list'))
def shop_add_item(): name = request.forms['name'] price = int(request.forms['price']) active = bool(request.forms.get('active', False)) try: ShopItem.create(name=name, price=price, active=active) success(_("Item created successfully")) except: danger(_("Error while creating item.")) return redirect(app.get_url('shop:items'))
def strawpoll_create(): """ View to create a new post """ if 'chart' in request.forms.keys(): url = app.get_url('strawpoll:stream_detail', id=request.forms['poll_id']) return redirect("{0}?chart={1}".format(url, request.forms['chart'])) url = API_URL data = { 'title': request.forms['title'], 'options': request.forms['options'].replace('\r', '').split('\n'), 'multi': bool(request.forms.get('multi', False)), # 'dupcheck': 'disabled', } r = requests.post(url, data=json.dumps(data)) if r.ok: data = r.json() poll = Strawpoll.create(id=data['id'], title=data['title']) if 'send_on_irc' in request.forms.keys(): message = "{0} {1}".format(poll.title, poll.get_url()) app.irc_send(action="message", parameters=message) success(_('Poll created successfully.')) else: danger(_('Error while creating poll: {0}'.format(r.json().get('errorMessage', 'Unknown')))) return redirect(app.get_url('strawpoll:list'))
def test_configuration_post(self): from utils.config import Configuration self.app.post(app.get_url('configuration'), { 'username': '******', 'oauth': 'OAUTH', 'channel': 'CHANNEL', 'lang': 'en_US', }) config = Configuration.get() self.assertEqual(config.username, 'USERNAME') self.assertEqual(config.oauth, 'OAUTH') self.assertEqual(config.channel, 'CHANNEL')
def commands_add_post(): data = request.forms with db.atomic(): command = Command.create(command=data['command']) for i in range(int(data['actions_number'])): # Each action has actionX prepended to its inputs namespace = 'action{0}'.format(i) module, method = data['{0}_action_type'.format(namespace)].split('|') parameters = { key[len(namespace):]: value for key, value in data.items() if key.startswith(namespace) and not key.endswith('_action_type') } action = Action.create(module=module, method=method, parameters=json.dumps(parameters)) CommandAction.create(command=command, action=action, order=i) success(_("Command created.")) return redirect(app.get_url('commands:list'))
def bet_add_bet(): question = request.forms['question'] options = request.forms['options'] initial_pot = int(request.forms['initial-pot']) try: min_amount = int(request.forms['min-amount']) except ValueError: min_amount = None try: max_amount = int(request.forms['max-amount']) except ValueError: max_amount = None try: bet = Bet.create(question=question, options=options, initial_pot=initial_pot, min_amount=min_amount, max_amount=max_amount) app.irc_send(action="message", parameters="New bet! {0}".format(bet.question)) for index, option in enumerate(bet.get_options(), start=1): app.irc_send(action="message", parameters="{0}. {1}".format(index, option)) success(_("Bet created successfully")) except Exception as e: danger(_("Error while creating bet: {0}.").format(e)) return redirect(app.get_url('bet:list'))
def index_view(): return redirect(app.get_url('dashboard'))