Ejemplo n.º 1
0
def tag_index():
    res = db_session.query(BundleTag.tag,
                           func.count(BundleTag.bundle_id).label('count')).\
        group_by(BundleTag.tag).\
        order_by(desc('count')).\
        all()
    return render_template('tag_index.html', tag_count_list=res)
Ejemplo n.º 2
0
def bundle_detail(bundle_id, page):
    pic = Pic.query.filter(Pic.bundle_id == bundle_id).\
        filter(Pic.page == page).\
        first()

    if not pic:
        pic = Pic.query.filter(Pic.bundle_id > bundle_id).first()
        return redirect('/bundle/{0}/1'.format(pic.bundle_id))

    max_page = db_session().query(func.max(Pic.page)).\
        filter(Pic.bundle_id == bundle_id).\
        scalar() or 1

    next_page = {'bundle_id': bundle_id, 'page': int(page) + 1}
    if max_page == page:
        next_page['bundle_id'] = db_session().query(Pic.bundle_id).\
            filter(Pic.bundle_id > bundle_id).\
            limit(1).\
            scalar()
        next_page['page'] = 1

    bundle = Bundle.query.filter(Bundle.id == pic.bundle_id).first()
    tags = [t[0] for t in
            db_session.query(BundleTag.tag).
            filter(BundleTag.bundle_id == bundle_id)]
    pagination = Pagination(page, 1, max_page, request.base_url,
                            urlparse.parse_qsl(request.query_string))

    return render_template('bundle_detail.html',
                           pic=pic, bundle=bundle, tags=tags,
                           next_page=next_page,
                           pagination=pagination)
Ejemplo n.º 3
0
def tag_bundles(tag):
    bundle_ids = [
        t[0] for t in
        db_session.query(BundleTag.bundle_id).
        filter(BundleTag.tag.like(u'%{}%'.format(tag))).all()]
    count = len(bundle_ids)
    page = int(request.args.get('page', 1))

    per_page = 100
    bundles = db_session().query(Bundle).\
        filter(Bundle.id.in_(bundle_ids)).\
        order_by(desc(Bundle.rating), desc(Bundle.id)).\
        offset((page - 1) * per_page).\
        limit(per_page).\
        all()
    bundles = _fill_bundles_cover(bundles)
    pagination = Pagination(page, per_page, count, request.base_url,
                            urlparse.parse_qsl(request.query_string))

    return render_template('tag_bundles.html',
                           bundles=bundles,
                           pagination=pagination)