示例#1
0
def image(image_id):
    image = Image.query.get(image_id)
    if image == None:
        return redirect('/')
    comments = Comment.query.filter_by(image_id=image_id).order_by(
        db.desc(Comment.id)).limit(20).all()
    return render_template('pageDetail.html', image=image, comments=comments)
示例#2
0
def index_images(page, per_page):
    paginate = Image.query.order_by(db.desc(Image.id)).paginate(
        page=page, per_page=per_page, error_out=False)
    map = {'has_next': paginate.has_next}
    images = []
    for image in paginate.items:
        comments = []
        for i in range(0, min(2, len(image.comments))):
            comment = image.comments[i]
            comments.append({
                'username': comment.user.username,
                'user_id': comment.user_id,
                'content': comment.content
            })
        imgvo = {
            'id': image.id,
            'url': image.url,
            'comment_count': len(image.comments),
            'user_id': image.user_id,
            'head_url': image.user.head_url,
            'created_date': str(image.created_date),
            'comments': comments
        }
        images.append(imgvo)

    map['images'] = images
    return json.dumps(map)
示例#3
0
def profile(user_id):
    user = User.query.get(user_id)
    if user == None:
        return redirect('/')
    paginate = Image.query.filter_by(user_id=user_id).order_by(
        db.desc(Image.id)).paginate(page=1, per_page=3, error_out=False)
    return render_template('profile.html',
                           user=user,
                           images=paginate.items,
                           has_next=paginate.has_next)
示例#4
0
def user_images(user_id, page, per_page):
    paginate = Image.query.filter_by(user_id=user_id).order_by(
        db.desc(Image.id)).paginate(page=page,
                                    per_page=per_page,
                                    error_out=False)
    map = {'has_next': paginate.has_next}
    images = []
    for image in paginate.items:
        imgvo = {
            'id': image.id,
            'url': image.url,
            'comment_count': len(image.comments)
        }
        images.append(imgvo)

    map['images'] = images
    return json.dumps(map)
示例#5
0
def index():
    images = Image.query.order_by(db.desc(Image.id)).limit(10).all()
    return render_template('index.html', images=images)