示例#1
0
 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)
示例#2
0
 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
示例#3
0
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)
示例#4
0
 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)
示例#5
0
 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)
示例#6
0
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)
示例#7
0
 def get_sections_by_course(o_course):
     sections = Section.objects.filter(course=o_course)
     return Ret(Error.OK, sections)
示例#8
0
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)
示例#9
0
 def get_meetings_by_section(o_section):
     meetings = Meeting.objects.filter(section=o_section)
     return Ret(Error.OK, body=meetings)
示例#10
0
 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)
示例#11
0
 def belong_to(self, o_course):
     if self.course == o_course:
         return Ret(Error.OK)
     return Ret(Error.SECTION_NOT_BELONG_TO_COURSE)
示例#12
0
 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)
示例#13
0
 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)
示例#14
0
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)
示例#15
0
 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)
示例#16
0
 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)
示例#17
0
 def get_selected_section_by_user(o_user):
     select_sections = UserSection.objects.filter(user=o_user)
     return Ret(Error.OK, select_sections)