def register(**kwargs): if bottle.request.forms: api = JSONAPI('http://localhost:8000/') response = api.post('register', **bottle.request.forms) if response.successful(): kwargs['successful'] = True if response.clientError(): kwargs['clientError'] = response.body() elif response.serverError(): kwargs['serverError'] = str(response) return bottle.template('register', **kwargs)
def update(**kwargs): api = JSONAPI('http://localhost:8000/', *bottle.request.auth) action = bottle.request.forms.pop('action') if 'id' in bottle.request.query: if action == 'save': response = api.put('todo', bottle.request.query['id'], **bottle.request.forms) elif action == 'delete': response = api.delete('todo', bottle.request.query['id']) kwargs['changedId'] = bottle.request.query['id'] elif action == 'save': '''Create new one.''' response = api.post('todo', **bottle.request.forms) if response.successful(): kwargs['changedId'] = response.body()['id'] if response.clientError(): kwargs['clientError'] = response.body() elif response.serverError(): kwargs['serverError'] = str(response) return main(**kwargs)