def api_edit_widget(self, widget_id, params): params = v.validate(self.edit_widget_schema, params) if params['data']: self.set_widget_content(widget_id, params['data']) if params['move']: self.move_widget(widget_id, params['move']) return True
def api_new_question(self, params): params = v.validate(self.new_question_schema, params) category_id = params.pop('category_id') question = schema.QuestionPrompt(**params) self.new_question(category_id, question) return dict(id=question.q_id, prompt=question.prompt, category_id=question.category_id)
def api_edit_question(self, question_id, params): params = v.validate(self.new_question_schema, params) with self.db.session_scope() as session: question = session.query(schema.QuestionPrompt).filter( schema.QuestionPrompt.q_id == question_id).one_or_none() if question is None: raise RequestApiException("Question not found") for key, val in params.items(): setattr(question, key, val) return dict(id=question.q_id, prompt=question.prompt, category_id=question.category_id)
def api_login_user(self, params): """ Try to log in a user with supplied parameters May branch to either Google, Facebook or password authentication """ params = v.validate(self.login_schema, params) user = None if 'gauth_token' in params: user = self.google_login(params['gauth_token']) elif 'fb_token' in params: user = self.facebook_login(params['fb_token'], params['fb_id']) if user is None: raise UserException('Failed to log in') web.login_user(user) return True
def api_edit_playlist(self, playlist_id, params): params = v.validate(self.edit_playlist_schema, params) return self.playlist_to_dict( self.edit_playlist(playlist_id, params['name'], params['tracks']))
def api_create_playlist(self, params): params = v.validate(self.new_playlist_schema, params) return self.playlist_to_dict( self.create_playlist(params['name'], params['tracks'], params['description']))
def api_new_category(self, params): params = v.validate(self.new_category_schema, params) category = self.new_category(params['title']) return dict(id=category.category_id, title=category.title, questions=[])
def api_add_widget(self, activity_id, step_id, params): params = v.validate(self.new_widget_schema, params) widget = self.add_widget(activity_id, step_id, params['type'], params['data']) return dict(type=widget.type, data=widget.data, id=widget.widget_id)
def api_new_activity(self, params): params = v.validate(self.new_activity_schema, params) return self.new_activity(params['name'])
def api_new_step(self, activity_id, params): params = v.validate(self.new_step_schema, params) return dict(id=self.new_step(activity_id, params['title']).step_no + 1)
def api_reply(self, thread_id, params): params = v.validate(self.REPLY_SCHEMA, params) user_from = web.get_current_user() user_to = self._get_message_participant(thread_id, user_from) self.send_message(user_from, user_to, params['Content']) return True
def api_message_admin(self, params): # TODO: do we get the message from the API or do we set it ourselves? is it autogenerated? params = v.validate(self.MESSAGE_ADMIN_SCHEMA, params) self.message_admin(web.get_current_user(), params['Content']) return True