From 3f9c073475628db7ae400e0df028b6b066ebf26c Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 25 Feb 2016 15:56:26 +0100 Subject: Add a get_solutions(problem_ids) API function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It returns the user’s solutions to given problems. --- server/handlers.py | 10 ++++++++++ server/user_session.py | 7 +++++++ 2 files changed, 17 insertions(+) (limited to 'server') diff --git a/server/handlers.py b/server/handlers.py index f427056..d1ad634 100644 --- a/server/handlers.py +++ b/server/handlers.py @@ -288,6 +288,15 @@ class GetAttempts(CodeqService): request.reply({'code': 0, 'data': request.session.get_attempts(language)}) +class GetSolutions(CodeqService): + def process(self, request): + problem_ids = request.data.get('problem_ids') + if problem_ids is None: + request.reply({'code': 1, 'message': 'No problem IDs specified'}) + else: + request.reply({'code': 0, 'data': request.session.get_solutions(problem_ids)}) + + class GetCurrentSolution(CodeqService): def process(self, request): js = request.data @@ -354,6 +363,7 @@ incoming_handlers = { 'signup': Signup(), 'change_password': ChangePassword(), 'get_attempts': GetAttempts(), + 'get_solutions': GetSolutions(), 'get_current_solution': GetCurrentSolution(), 'logout': Logout(), 'activity': Activity(), diff --git a/server/user_session.py b/server/user_session.py index 63d3459..af28046 100644 --- a/server/user_session.py +++ b/server/user_session.py @@ -433,6 +433,13 @@ class UserSession(object): results.extend(group_results) return results + def get_solutions(self, problem_ids): + uid = self.get_uid() + solutions = {s.problem_id: s.content for s in Solution.filter(codeq_user_id=uid) + if s.problem_id in problem_ids} + # return solutions in the same order as in [problem_pids] + return [solutions[pid] for pid in problem_ids if pid in solutions] + def send(self, json_obj): """Sends a message to the user. -- cgit v1.2.1