예제 #1
0
파일: views.py 프로젝트: puyangfoods/album
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)
예제 #2
0
파일: views.py 프로젝트: puyangfoods/album
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)
예제 #3
0
파일: views.py 프로젝트: puyangfoods/album
def bundles():
    page = int(request.args.get('page', 1))
    count = db_session().query(func.count(Bundle.id)).scalar()
    per_page = 100
    bundles = Bundle.query.\
        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))
    if page == 1:
        recent_bundles = Bundle.query.\
            filter(Bundle.created_at <= datetime.date.today()).\
            order_by(desc(Bundle.created_at)).\
            limit(6).\
            all()
    else:
        recent_bundles = []
    return render_template('bundles.html',
                           recent_bundles=recent_bundles,
                           bundles=bundles,
                           pagination=pagination)