示例#1
0
def photo_list(request):
    page_str = request.GET.get('page', '')
    page = page_str.isdigit() and int(page_str) or 1

    num_photos = DBSession.query(
        func.count(Photo.id)
    ).filter(
        Photo.published == True  # noqa
    ).first()[0]
    last_page = (num_photos + 8) // 9
    if page > last_page:
        raise HTTPNotFound()

    photos = DBSession.query(
        Photo
    ).filter(
        Photo.published == True  # noqa
    ).order_by(
        Photo.created_at.desc()
    ).limit(
        9
    ).offset(
        (page - 1) * 9
    ).all()
    return dict(photos=photos,
                current_page=page,
                last_page=last_page)
示例#2
0
文件: views.py 项目: yosida95/photos
def photo_list(request):
    page_str = request.GET.get('page', '')
    page = page_str.isdigit() and int(page_str) or 1

    num_photos = DBSession.query(func.count(
        Photo.id)).filter(Photo.published == True  # noqa
                          ).first()[0]
    last_page = (num_photos + 8) // 9
    if page > last_page:
        raise HTTPNotFound()

    photos = DBSession.query(Photo).filter(
        Photo.published == True  # noqa
    ).order_by(Photo.created_at.desc()).limit(9).offset((page - 1) * 9).all()
    return dict(photos=photos, current_page=page, last_page=last_page)
示例#3
0
文件: views.py 项目: yosida95/photos
def photo_factory(request):
    photo_id = request.matchdict['id']
    photo = DBSession.query(Photo).filter(Photo.id == photo_id).first()
    if photo is None:
        raise HTTPNotFound()

    return photo
示例#4
0
def photo_factory(request):
    photo_id = request.matchdict['id']
    photo = DBSession.query(
        Photo
    ).filter(
        Photo.id == photo_id
    ).first()
    if photo is None:
        raise HTTPNotFound()

    return photo