def get_algo_list(): algo_list = [] for o_algo in Algorithm.objects.all(): algo_list.append(o_algo.to_dict()) return Ret(Error.OK, algo_list)
def create(cls, ip, port): try: o_algo_server = cls(ip=ip, port=port) except: return Ret(Error.ERROR_CREATE_ALGO_SERVER) return o_algo_server
def run(ip, port, study_id): print(ip, port, study_id) channel = grpc.insecure_channel('%s:%s' % (ip, port)) stub = suggestion_pb2_grpc.SuggestionStub(channel) response = stub.GetSuggestion(suggestion_pb2.Study(study_id=study_id)) return Ret(Error.OK, response.message)
def get_algo_by_id(id): try: o_algo = Algorithm.objects.get(pk=id) except: return Ret(Error.NOT_FOUND_ALGO) return Ret(Error.OK, o_algo)
def get_user_by_id(user_id): try: o_user = User.objects.get(pk=user_id) except: return Ret(Error.NOT_FOUND_USER) return Ret(Error.OK, o_user)
def create_algo(ip, port, algo_name, algo_path): channel = grpc.insecure_channel('%s:%s' % (ip, port)) stub = suggestion_pb2_grpc.SuggestionStub(channel) response = stub.CreateAlgorithm( suggestion_pb2.Algorithm(algo_name=algo_name, algo_path=algo_path)) return Ret(Error.OK, response.message)
def get_sections_by_course(o_course): sections = Section.objects.filter(course=o_course) return Ret(Error.OK, sections)
def get_user_from_session(request): user_id = load_session(request, 'user', once_delete=False) if user_id is None: return Ret(Error.REQUIRE_LOGIN) return User.get_user_by_id(user_id)
def get_meetings_by_section(o_section): meetings = Meeting.objects.filter(section=o_section) return Ret(Error.OK, body=meetings)
def get_section_by_id(section_id): try: o_section = Section.objects.get(id=section_id) except Section.DoesNotExist: return Ret(Error.SECTION_NOT_EXIST) return Ret(Error.OK, body=o_section)
def belong_to(self, o_course): if self.course == o_course: return Ret(Error.OK) return Ret(Error.SECTION_NOT_BELONG_TO_COURSE)
def get_user_by_id(user_id): try: o_user = User.objects.get(id=user_id) except User.DoesNotExist: return Ret(Error.USER_NOT_EXIST) return Ret(Error.OK, o_user)
def get_user_by_username(username): try: o_user = User.objects.get(username=username) except User.DoesNotExist: return Ret(Error.USER_NOT_EXIST) return Ret(Error.OK, o_user)
def run(ip, port, data, trail_id): channel = grpc.insecure_channel('%s:%s' % (ip, port)) stub = trail_pb2_grpc.TrailStub(channel) response = stub.RunTrail(trail_pb2.Data(data=data, trail_id=trail_id)) return Ret(Error.OK, response.message)
def get_user_by_username(username): try: o_user = User.objects.get(username=username) except: return Ret(Error.NOT_FOUND_USER) return Ret(Error.OK, o_user)
def get_user_todo_by_id(user_todo_id): try: o_user_todo = UserTodo.objects.get(id=user_todo_id) except UserTodo.DoesNotExist: return Ret(Error.USER_TODO_NOT_EXIST) return Ret(Error.OK, body=o_user_todo)
def get_selected_section_by_user(o_user): select_sections = UserSection.objects.filter(user=o_user) return Ret(Error.OK, select_sections)