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) isfollowed = isfollow(user_id, current_user.id) return render_template('profile.html', user=user, images=paginate.items, has_next=paginate.has_next, isfollowed = isfollowed)
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) print(paginate) img_lists = {'has_next': paginate.has_next} images = [] for img in paginate.items: comments = [] for i in range(0, min(2, len(img.comments))): comment = img.comments[i] comments.append({ 'username': comment.user.username, 'user_id': comment.user_id, 'content': comment.content }) imgvo = { 'id': img.id, 'url': img.url, 'comment_count': len(img.comments), 'user_id': img.user_id, 'user_name': img.user.username, 'head_url': img.user.head_url, 'created_date': str(img.create_date), 'comments': comments } images.append(imgvo) img_lists['images'] = images return json.dumps(img_lists)
def index(): paginate = Image.query.order_by(db.desc(Image.id)).paginate( page=1, per_page=3, error_out=False) # print(images) return render_template("index.html", images=paginate.items, has_next=paginate.has_next)
def index_images(page, perpage): paginate = Image.query.order_by(db.desc(Image.id)).paginate( page=page, per_page=perpage, 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.comment))): comment = image.comment[i] comments.append({ 'username': comment.user.username, 'user_id': comment.user_id, 'content': comment.content }) imvo = { 'user_id': image.user_id, 'url': image.url, 'comment': comment, 'comment_count': len(image.comment), 'id': image.id, 'head_url': image.user.head_url, 'created_date': str(image.created_date) } images.append(imvo) map['images'] = images return json.dumps(map)
def TimeLine(): id = current_user.id followings = getfollowing(id) foll = [] for f in followings: foll.append(int(f)) foll.append(id) images = Image.query.filter(Image.user_id.in_(foll)).order_by(db.desc(Image.id)).limit(10).all() return render_template('feed.html',images=images)
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)
def index(): images = Image.query.order_by(db.desc(Image.id)).limit(10).all() return render_template('index.html', images=images)
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)
def Discover(): images = Image.query.order_by(db.desc(Image.id)).limit(10).all() return render_template('feed.html',images=images)