Skip to content

Instantly share code, notes, and snippets.

@Porter97
Last active March 5, 2020 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Porter97/c5dad2d0cff82c1cc891eea603cffc37 to your computer and use it in GitHub Desktop.
Save Porter97/c5dad2d0cff82c1cc891eea603cffc37 to your computer and use it in GitHub Desktop.
#...
@main.route('/followers/<username>')
def followers(username):
user = User.query.filter_by(username=username).first()
if user is None:
flash('Invalid user.')
return redirect(url_for('.index'))
page = request.args.get('page', 1, type=int)
pagination = user.followers.paginate(
page, per_page=current_app.config['OFFBRAND_RESULTS_PER_PAGE'],
error_out=False)
follows = [{'user': item.follower, 'timestamp': item.timestamp}
for item in pagination.items]
return render_template('followers.html', user=user, title="Followers of",
endpoint='.followers', pagination=pagination,
follows=follows)
@main.route('/followed_by/<username>')
def followed_by(username):
user = User.query.filter_by(username=username).first()
if user is None:
flash('Invalid user.')
return redirect(url_for('.index'))
page = request.args.get('page', 1, type=int)
pagination = user.followed.paginate(
page, per_page=current_app.config['OFFBRAND_RESULTS_PER_PAGE'],
error_out=False)
follows = [{'user': item.followed, 'timestamp': item.timestamp}
for item in pagination.items]
return render_template('followers.html', user=user, title="Followed by",
endpoint='.followed_by', pagination=pagination,
follows=follows)
@main.route('/collection-followers/<int:id>')
@login_required
def collection_followers(id):
collection = Collection.query.filter_by(id=id).first()
if collection is None:
flash('Invalid User.')
return redirect(url_for('.index'))
page = request.args.get('page', 1, type=int)
pagination = collection.user_followers.paginate(
page,
per_page=current_app.config['OFFBRAND_RESULTS_PER_PAGE'],
error_out=False
)
follows = [{'user': item.c_follower, 'timestamp': item.timestamp}
for item in pagination.items]
return render_template('collection_followers.html',
collection=collection,
title='Followers',
endpoint='.collection_followers',
pagination=pagination,
follows=follows)
#...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment