Пример #1
0
def index():
    form = PostForm()

    if (form.validate_on_submit()):
        body = form.post.data
        post = Post(body=body, author=current_user)

        db.session.add(post)
        db.session.commit()

        flash('Your post is now online')
        return redirect(url_for('index'))

    page = request.args.get('page', 1, type=int)
    posts = current_user.get_followed_posts().paginate(
        page, app.config["POSTS_PER_PAGE"], False)

    if (posts.has_next): next_url = url_for('index', page=posts.next_num)
    else: next_url = None

    if (posts.has_prev): prev_url = url_for('index', page=posts.prev_num)
    else: prev_url = None

    return render_template('index.html',
                           title='Home Page',
                           posts=posts.items,
                           form=form,
                           next_url=next_url,
                           prev_url=prev_url)
Пример #2
0
def index():
    form = PostForm()
    if form.validate_on_submit():
        language = guess_language(form.post.data)
        if language == 'UNKNOWN' or len(language) > 5:
            language = ''
        post = Post(body=form.post.data,
                    author=current_user,
                    language=language)
        db.session.add(post)
        db.session.commit()
        flash(_('Your post is now live!'))
        return redirect(url_for('main.index'))
    page = request.args.get('page', 1, type=int)
    posts = current_user.get_followed_posts().paginate(
        page, current_app.config['POSTS_PER_PAGE'], False)
    next_url = url_for('main.index',
                       page=posts.next_num) if posts.has_next else None
    prev_url = url_for('main.index',
                       page=posts.prev_num) if posts.has_prev else None
    return render_template('index.html',
                           form=form,
                           posts=posts.items,
                           next_url=next_url,
                           prev_url=prev_url)
Пример #3
0
def followed_posts(page, ):
    posts = current_user.get_followed_posts().paginate(
        page,
        current_app.config["POSTS_PER_PAGE"],
        True,
    )
    return posts
Пример #4
0
def get_followed_posts(count, last_uuid):
    timestamp = None
    if last_uuid:
        p = Post.query.filter_by(uuid=last_uuid).first()
        if p is None:
            return page_not_found('last_uuid không hợp lệ')
        timestamp = p.created
    posts = current_user.get_followed_posts(count, timestamp)
    return jsonify({'posts': [p.todict() for p in posts]})
Пример #5
0
def index():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(body=form.body.data,
                    title=form.title.data,
                    user_id=current_user.id)
        db.session.add(post)
        db.session.commit()
        flash('您已成功发表动态', 'success')
        return redirect(url_for('index'))
    posts = current_user.get_followed_posts()
    return render_template('index.html', title="Home", posts=posts, form=form)
Пример #6
0
def index():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(body=form.post.data, author=current_user)
        db.session.add(post)
        db.session.commit()
        flash(_('Your post is live now!'), 'info')
        return redirect(url_for('index'))
    page = request.args.get('page', 1, type=int)
    posts = current_user.get_followed_posts().paginate(
        page, app.config['POST_PER_PAGE'], False)
    next_url = url_for('index',
                       page=posts.next_num) if posts.has_next else None
    prev_url = url_for('index',
                       page=posts.prev_num) if posts.has_prev else None
    app.logger.info('message')
    return render_template('index.html',
                           posts=posts.items,
                           form=form,
                           next_url=next_url,
                           prev_url=prev_url)
Пример #7
0
def index():
	form = PostForm()
	if form.validate_on_submit():
		tags = form.tags.data.split(',')
		post = Post(body=form.post.data, user_id=current_user.id)
		post.edit_tags(*tags)
		db.session.add(post)
		db.session.commit()
		flash('Post success')
		return redirect(url_for('main.index'))
	title = 'index'
	page_num = request.args.get('page_num',1,type=int)
	posts_paginate = current_user.get_followed_posts().paginate(page_num, current_app.config['POSTS_PER_PAGE'], False)
	posts = posts_paginate.items
	pagination = {
		'first_page' : url_for('main.index'),
		'last_page' : url_for('main.index',page_num=posts_paginate.pages),
		'next_page' : url_for('main.index',page_num=posts_paginate.next_num),
		'prev_page' : url_for('main.index',page_num=posts_paginate.prev_num),
		'has_next' : posts_paginate.has_next,
		'has_prev' : posts_paginate.has_prev,
		'pages':posts_paginate.pages
	}
	return render_template('index.html', form = form, title=title, posts = posts, pagination = pagination, datetime=datetime.utcnow() )
Пример #8
0
def home():
    if request.method == 'GET':
        if not current_user.is_authenticated:
            return redirect(url_for('register'))
        return render_template("home.html",
                               title="Instaclone",
                               get_file_url=get_file_url)

    if request.method == 'POST':
        start = int(request.form.get('start') or 1)
        # get posts
        posts = current_user.get_followed_posts().paginate(start, 2,
                                                           False).items

        result = []
        for post in posts:
            # print(post.pid)

            comments = []
            for comment in post.get_comments(limit=2):
                comments.append({
                    'cid': comment.cid,
                    'content': comment.content,
                    'post_id': comment.post_id,
                    'author': {
                        'uid':
                        comment.author.uid,
                        'username':
                        comment.author.username,
                        'image_file':
                        get_file_url('profile_pics/' +
                                     comment.author.image_file),
                        'user_url':
                        url_for('get_user', username=comment.author.username)
                    }
                })

            result.append({
                'pid': post.pid,
                'content': post.content,
                'media': get_file_url('media/' + post.media),
                'date_posted': post.date_posted,
                'post_url': url_for('get_post', post_id=post.pid),
                'liked': post.user_liked(current_user),
                'like_count': post.get_likes_count(),
                'timeago': post.get_timeago(),
                'author': {
                    'uid':
                    post.author.uid,
                    'username':
                    post.author.username,
                    'image_file':
                    get_file_url('profile_pics/' + post.author.image_file),
                    'user_url':
                    url_for('get_user', username=post.author.username)
                },
                'comment_count': post.comments_count(),
                'comments': comments
            })
        status = True
        return jsonify(result=result, success=status)
Пример #9
0
def posts_curated():
    posts = current_user.get_followed_posts()
    return render_template('posts/curatedPosts.html', posts=posts)