def perma_result(_id): user = User(session['user']) document = Mongo().result_by_id(_id) course = document.ref_course problem = document.ref_problem breadcrumbs = [ Link.CoursesBtn(), Link.CourseBtn(course), Link.ProblemBtn(course, problem) ] return render_template_ext( 'view_result.njk', user=user, notifications=Mongo().load_notifications(user.id), results=[document], result=None, requestReview=False, title='Problem %s' % problem.name, breadcrumbs=Breadcrumbs.new(*breadcrumbs), js=[ '//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js', '/static/js/lib/highlightjs-line-numbers.js' ], js_no_cache=['sockets.js', 'process.js'])
def view_result(course_name, course_year, problem_id, _id=None): user = User(session['user']) if user.is_admin(): return redirect( url_for('admin_problem', course_name=course_name, course_year=course_year, problem_id=problem_id)) course = Courses().find_one(name=course_name, year=course_year, only_active=False) problem = course.problem_db[problem_id] results = list() result = None breadcrumbs = [Link.CoursesBtn(), Link.CourseBtn(course)] # TODO check access if _id: document = Mongo().result_by_id(_id) if document: # add to previous solution if already executed if document.result: results.append(document.peek()) else: result = document.peek() breadcrumbs.append(Link.ProblemBtn(course, problem)) if Env.use_database: for prev in Mongo().peek_last_n_results(20, user.id, course.id, problem.id): # push only valid result if prev.get('result') and str(prev['_id']) != str(_id): results.append(prev) if _id: for r in results: if str(r['_id']) == str(_id): r['active'] = 'active' results = sorted(results, reverse=True, key=lambda x: x.get('attempt')) return render_template_ext( 'results.njk', user=user, notifications=Mongo().read_notifications(user.id), results=results, result=result, requestReview=True, title='Problem %s' % problem.name, breadcrumbs=Breadcrumbs.new(*breadcrumbs), )
def view_course(course_name, course_year): user = User(session['user']) course = Courses().find_one(name=course_name, year=course_year, only_active=False) problems: List[Problem] = sorted(list( course.problem_db.find(disabled=(None, False))), key=problem_cat_getter) languages = Languages.db().find(disabled=(None, False)) if not user.is_admin(): problems = [p for p in problems if p.is_visible()] cat_problems = OrderedDict() for cat, items in groupby(problems, key=problem_cat_getter): cat_problems[cat] = list(items) return render_template_ext( 'view_course.njk', user=user, notifications=Mongo().load_notifications(user.id), course=course, languages=languages, has_categories=len(cat_problems) > 1, problems=problems, cat_problems=cat_problems, title=course.name, subtitle=course.year, breadcrumbs=Breadcrumbs.new(Link.CoursesBtn(), ), js_no_cache=['solution.js'])
def perma_result(_id): user = User(session['user']) document = Mongo().result_by_id(_id) course = document.ref_course problem = document.ref_problem breadcrumbs = [ Link.CoursesBtn(), Link.CourseBtn(course), Link.ProblemBtn(course, problem) ] return render_template_ext( 'results.njk', user=user, notifications=Mongo().read_notifications(user.id), results=[document], result=None, requestReview=False, title='Problem %s' % problem.name, breadcrumbs=Breadcrumbs.new(*breadcrumbs), )
def admin_problem(course_name, course_year, problem_id): user = User(session['user']) course = Courses().find_one(name=course_name, year=course_year, only_active=False) problems_ids = ','.join([x.id for x in list(course.problem_db.find())]) problem = course.problem_db[problem_id] languages = Languages.db().find(disabled=(None, False)) return render_template_ext( 'problem.njk', user=user, notifications=Mongo().read_notifications(user.id), course=course, languages=languages, problem=problem, problems_ids=problems_ids, title='Manage problem %s' % problem.name, breadcrumbs=Breadcrumbs.new(Link.CoursesBtn(), Link.CourseBtn(course)), )
def view_course(course_name, course_year): user = User(session['user']) course = Courses().find_one(name=course_name, year=course_year, only_active=False) problems = list(course.problem_db.find(disabled=(None, False))) languages = Languages.db().find(disabled=(None, False)) return render_template_ext( 'submit.njk', user=user, notifications=Mongo().read_notifications(user.id), course=course, languages=languages, problems=problems, title=course.name, subtitle=course.year, breadcrumbs=Breadcrumbs.new(Link.CoursesBtn(), ), )
def view_result(course_name, course_year, problem_id, _id=None): user = User(session['user']) if user.is_admin(): return redirect( url_for('admin_problem', course_name=course_name, course_year=course_year, problem_id=problem_id)) course = Courses().find_one(name=course_name, year=course_year, only_active=False) problem = course.problem_db[problem_id] results = list() result = None breadcrumbs = [Link.CoursesBtn(), Link.CourseBtn(course)] # TODO check access if _id: document = Mongo().result_by_id(_id) if document: # add to previous solution if already executed if document.result: results.append(document) else: result = document breadcrumbs.append(Link.ProblemBtn(course, problem)) if Env.use_database: for prev in Mongo().peek_last_n_results(10, user.id, course.id, problem.id): # push only valid result if prev.result and str(prev._id) != str(_id): results.append(prev) if _id: for r in results: if str(r._id) == str(_id): r.active = 'active' def get_attempt(obj): try: return int(obj.attempt) except: return 0 results = sorted(results, reverse=True, key=get_attempt) return render_template_ext( 'view_result.njk', user=user, notifications=Mongo().load_notifications(user.id), results=results, result=result, requestReview=True, title='Problem %s' % problem.name, breadcrumbs=Breadcrumbs.new(*breadcrumbs), js=[ '//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js', '/static/js/lib/highlightjs-line-numbers.js' ], js_no_cache=['sockets.js', 'process.js'])