Exemplo n.º 1
0
    def get_son_routes(category_id):
        assert isinstance(category_id, ObjectId)
        assert CategoryHelper.get(category_id)

        category = CategoryHelper.get(category_id)

        result_list = []
        for son_route_id in category.routes:
            result_list.append(RouteHelper.get(son_route_id))

        for son_route in result_list:
            son_route.formatted_date = get_formatted_time(son_route.create_ts)
            son_route.n_comment = 0 #TODO use disqus api to get comment count
            son_route.n_rate = RateInfo.objects(route=son_route.id).count()

        return result_list
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
    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