def route_page(route_id): try: route_id = ObjectId(route_id) except : flash('invalid route_id') return redirect(url_for('home.home')) route = RouteHelper.get(route_id) route.author = UserHelper.get(route.author) route.formatted_time = get_formatted_time(route.create_ts) route.stat = RouteHelper.get_route_stat(route.id) route.cleaned_content = route.content.read().decode('utf-8') # TODO: use bleach to sanitise html route.my_rate = RouteHelper.get_user_rate(route.id) attachs = RouteHelper.get_attachs(route.id) joined = route.id in current_user.entered_routes finished = RouteHelper.is_route_finished(route.id) if not route.finished: return redirect(url_for('route.add_attach_page', route_id=route.id)) return render_template('route-detail.html', route=route, attachs=attachs, joined=joined, finished=finished)
def get_child_hot_route(category_id): """ Give a catetory, find the hotest route in its sons.""" assert isinstance(category_id, ObjectId) assert CategoryHelper.get(category_id) category = CategoryHelper.get(category_id) hot_routes = [] if category.sons: for son_cate in category.sons: son_hot_route_id = CategoryHelper._recursive_find_hot_route(son_cate) if son_hot_route_id: son_hot_route = RouteHelper.get(son_hot_route_id) son = CategoryHelper.get(son_cate) hot_routes.append({ 'category_title': son.title, 'category_id': son.id, 'route': son_hot_route, 'n_rate': RouteHelper.get_route_stat(son_hot_route.id)['n_rate'], 'date': get_formatted_time(son_hot_route.create_ts) }) return hot_routes