def handle_add(self, request): program_dict = self._manager.add() program = Program() program.program_id = str(program_dict['_id']) program.name = program_dict['name'] program.xml = program_dict['xml'] return AddProgramResponse(program)
def handle_get(self, request): program_id = request.program_id program_dict = self._manager.get(program_id) program = Program() program.program_id = str(program_dict['_id']) program.name = program_dict['name'] program.xml = program_dict['xml'] return GetProgramResponse(program)
def handle_list(self, request): programs = self._manager.list() response = ListProgramsResponse() for program in programs: prog = Program() prog.program_id = str(program['_id']) prog.name = program['name'] prog.xml = program['xml'] response.programs.append(prog) return response
def handle_copy(self, request): program_id = request.program_id program_dict = self._manager.get(program_id) program_name = 'Untitled program' if 'name' in program_dict: program_name = 'Copy of ' + program_dict['name'] program_xml = '<xml></xml>' if 'xml' in program_dict: program_xml = program_dict['xml'] program_js = '' if 'js' in program_dict: program_js = program_dict['js'] language = '' if 'language' in program_dict: language = program_dict['language'] copy_dict = self._manager.add() inserted_id_str = str(copy_dict['_id']) self._manager.update(inserted_id_str, {'name': program_name, 'xml': program_xml, 'js': program_js, 'language': language}) program = Program() program.program_id = str(copy_dict['_id']) program.name = program_name program.xml = program_xml program.js = program_js program.language = language return CopyProgramResponse(program)
def handle_add(self, request): program_dict = self._manager.add() program = Program() program.program_id = str(program_dict['_id']) program.name = program_dict['name'] if 'xml' in program_dict: program.xml = program_dict['xml'] if 'js' in program_dict: program.js = program_dict['js'] if 'language' in program_dict: program.language = program_dict['language'] return AddProgramResponse(program)