Adds pagination on twitter feed
This improves performance on low-end devices
This commit is contained in:
parent
f57ff4cce8
commit
56151b78c4
@ -59,8 +59,10 @@ def index():
|
|||||||
return render_template('home.html', config=config)
|
return render_template('home.html', config=config)
|
||||||
|
|
||||||
@app.route('/twitter')
|
@app.route('/twitter')
|
||||||
|
@app.route('/twitter/<page>')
|
||||||
@login_required
|
@login_required
|
||||||
def twitter():
|
def twitter(page=0):
|
||||||
|
page = int(page)
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
followingList = current_user.twitter_following_list()
|
followingList = current_user.twitter_following_list()
|
||||||
followCount = len(followingList)
|
followCount = len(followingList)
|
||||||
@ -69,12 +71,21 @@ def twitter():
|
|||||||
form = EmptyForm()
|
form = EmptyForm()
|
||||||
posts.extend(getFeed(followingList))
|
posts.extend(getFeed(followingList))
|
||||||
posts.sort(key=lambda x: x.timeStamp, reverse=True)
|
posts.sort(key=lambda x: x.timeStamp, reverse=True)
|
||||||
|
|
||||||
|
npage = page*10
|
||||||
|
tenmore = npage+10
|
||||||
|
pages = int(math.ceil(len(posts)/10))
|
||||||
|
if posts and len(posts) > tenmore:
|
||||||
|
posts = posts[npage:tenmore]
|
||||||
|
else:
|
||||||
|
posts = posts[npage:]
|
||||||
|
|
||||||
if not posts:
|
if not posts:
|
||||||
profilePic = avatarPath
|
profilePic = avatarPath
|
||||||
else:
|
else:
|
||||||
profilePic = posts[0].userProfilePic
|
profilePic = posts[0].userProfilePic
|
||||||
print("--- {} seconds fetching twitter feed---".format(time.time() - start_time))
|
print("--- {} seconds fetching twitter feed---".format(time.time() - start_time))
|
||||||
return render_template('twitter.html', title='Yotter | Twitter', posts=posts, avatar=avatarPath, profilePic = profilePic, followedCount=followCount, form=form, config=config)
|
return render_template('twitter.html', title='Yotter | Twitter', posts=posts, avatar=avatarPath, profilePic = profilePic, followedCount=followCount, form=form, config=config, pages=pages, actual_page=page)
|
||||||
|
|
||||||
@app.route('/savePost/<url>', methods=['POST'])
|
@app.route('/savePost/<url>', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -25,4 +25,19 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="text container center aligned">
|
||||||
|
<div class="ui centered pagination menu">
|
||||||
|
{%for page in range(1, pages)%}
|
||||||
|
{% if page == actual_page%}
|
||||||
|
<a href="/twitter/{{page}}" class="active item">
|
||||||
|
{{page}}
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<a href="/twitter/{{page}}" class="item">
|
||||||
|
{{page}}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Reference in New Issue
Block a user