def get_sorted_problems(lesson): problems = [load_problem(problem) for problem in lesson.problems.all()] problems_with_order = [ (problem, problem['db_object'].probleminlesson_set.get(lesson=lesson).order) for problem in problems ] problems_with_order.sort(key=lambda x: x[1]) return [problem for problem, order in problems_with_order]
def render(self, context): problem_urlname = context[self.problem_ref]['urlname'] problem = load_problem(Problem.objects.get(urlname=problem_urlname)) user = context['request'].user if user.is_authenticated(): statuses = [submission.get_status_display() for submission in Submission.objects.filter(user=user, problem=problem['db_object'])] else: statuses = [] if 'ok' in statuses: css_class = 'okProblemLink' elif 'error' in statuses: css_class = 'errorProblemLink' else: css_class = 'unsubmittedProblemLink' return '<span class="{0}">{1}</span>'.format(css_class, problem['name'])
def render(self, context): problem_urlname = context[self.problem_ref]['urlname'] problem = load_problem(Problem.objects.get(urlname=problem_urlname)) user = context['request'].user if user.is_authenticated(): user_solutions = [submission for submission in Submission.objects.filter(user=user, problem=problem['db_object']).order_by('time') if submission.get_status_display() == 'ok'] else: user_solutions = [] ideal_solutions = [submission for submission in Submission.objects.filter(user=ideal_user, problem=problem['db_object']).order_by('-time') if submission.get_status_display() == 'ok'] if user_solutions and ideal_solutions: return ''' <table border="1" class="userAndIdealSolutions"> <tr> <td class="header">Ваше решение</td> <td class="header">Эталонное решение</td> </tr> <tr> <td class="body"> {user_solution} </td> <td class="body"> {ideal_solution} </td> </tr> </table> <br> '''.format(**dict(user_solution=_render_code_to_html(user_solutions[0].code, input_data=problem['tests'][0], context=context, executable=True, blockquote=False), ideal_solution=_render_code_to_html(ideal_solutions[0].code, input_data=problem['tests'][0], context=context, executable=True, blockquote=False), **globals())) else: return ''
def get_sorted_problems(lesson): problems = [load_problem(problem) for problem in lesson.problems.all()] problems_with_order = [(problem, problem['db_object'].probleminlesson_set.get(lesson=lesson).order) for problem in problems] problems_with_order.sort(key=lambda x: x[1]) return [problem for problem, order in problems_with_order]