First I want to state that I asked a similar question before, however I would like to give this question more direction. As a noob to python, app engine and especially jquery, this is turning out to be quite a daunting task. I was wondering if someone could please point me in the right direction (perhaps a way to do this in app engine itself), and maybe even be so kind as to outline what I should do here.
The following is the code that gets posts in my profile page:
What I have now is a Query object:
posts = db.GqlQuery("select * from Profile_Comments WHERE name_of_profile =:1 order by date_created desc", profile_id)
And a for loop in my jinja template that gets the posts:
{% for post_tmp in posts %}
{{post_tmp.post.replace('\r\n', '<br>') | safe }}
{% endfor %}
Thank you very very much! And sorry for the pseudo re-post!
Edit – Entire Profile Handler (the template is posted above… its a simple for loop):
class Profile(MainHandler):
def get(self, profile_id):
u = User.by_name(profile_id.lower())
if not u:
self.redirect('/')
if self.user and profile_id:
current_user = self.user.name
name1 = ''
friend_name = ''
team_imagee = ''
key = ''
monthss = ''
yearss = ''
dayss = ''
countryss = ''
team_imagee2 = ''
imgs2 = ''
imgs = ''
key2 = ''
name22 = ''
name2 = ''
handless = ''
msgg = ''
imgs = db.GqlQuery("select * from Profile_Images WHERE name =:1", profile_id)
imgs2 = db.GqlQuery("select * from Profile_Images WHERE name =:1", current_user)
team_name = db.GqlQuery("select * from Teams WHERE name =:1", profile_id)
team_images = db.GqlQuery("select * from Teamimg WHERE user =:1", profile_id)
team_images2 = db.GqlQuery("select * from Teamimg WHERE user =:1", current_user)
friends = db.GqlQuery("select * from Friends WHERE name =:1 order by added_date desc limit 10", profile_id)
posts = db.GqlQuery("select * from Profile_Comments WHERE name_of_profile =:1 order by date_created desc", profile_id)
name2 = db.GqlQuery("select * from User WHERE name =:1", profile_id)
month = db.GqlQuery("select * from User WHERE name =:1", profile_id)
day = db.GqlQuery("select * from User WHERE name =:1", profile_id)
year = db.GqlQuery("select * from User WHERE name =:1", profile_id)
country = db.GqlQuery("select * from User WHERE name =:1", profile_id)
handle = db.GqlQuery("select * from Handle WHERE name =:1", profile_id)
rating = db.GqlQuery("select * from Rating WHERE name_of_profile =:1", profile_id)
profile_msg = db.GqlQuery("select * from Profile_Msg WHERE name =:1", profile_id)
for handles in handle:
handless = handles.handle_name
for months in month:
monthss = months.month
for countrys in country:
countryss = countrys.country
for days in day:
dayss = days.day
for years in year:
yearss = years.year
for clan in team_name:
name1 = clan.team_name_anycase
for clan in team_name:
name2 = clan.team_name
for image in team_images:
team_imagee = image.key()
for image2 in team_images2:
team_imagee2 = image2.key()
for img in imgs:
key = img.key()
for img2 in imgs2:
key2 = img2.key()
for msg in profile_msg:
msgg = msg.msg
self.render('profile.html', msg = msgg, team_name2 = name2, handle_var = handless, imgs = imgs, team_img2 = team_imagee2, profile_image_posted = key2, posts = posts, profile_id = profile_id, country_var = countryss, day_var = dayss, year_var = yearss, month_var = monthss, current_user = current_user, friends = friends, team_img = team_imagee, team_name = name1, profile_image = key, username = self.user.name, email = self.user.email, firstname = self.user.first_name, last_name = self.user.last_name, country = self.user.country)
else:
self.redirect('/register')
def post(self, profile_id):
if self.user and profile_id:
current_user = self.user.name
name1 = ''
friend_name = ''
team_imagee = ''
key = ''
monthss = ''
yearss = ''
dayss = ''
countryss = ''
team_imagee2 = ''
imgs2 = ''
imgs = ''
key2 = ''
name22 = ''
name2 = ''
handless = ''
msgg = ''
imgs = db.GqlQuery("select * from Profile_Images WHERE name =:1", profile_id)
imgs2 = db.GqlQuery("select * from Profile_Images WHERE name =:1", current_user)
team_name = db.GqlQuery("select * from Teams WHERE name =:1", profile_id)
team_images = db.GqlQuery("select * from Teamimg WHERE user =:1", profile_id)
team_images2 = db.GqlQuery("select * from Teamimg WHERE user =:1", current_user)
friends = db.GqlQuery("select * from Friends WHERE name =:1 order by added_date desc limit 10", profile_id)
posts = db.GqlQuery("select * from Profile_Comments WHERE name_of_profile =:1 order by date_created desc", profile_id)
name2 = db.GqlQuery("select * from User WHERE name =:1", profile_id)
month = db.GqlQuery("select * from User WHERE name =:1", profile_id)
day = db.GqlQuery("select * from User WHERE name =:1", profile_id)
year = db.GqlQuery("select * from User WHERE name =:1", profile_id)
country = db.GqlQuery("select * from User WHERE name =:1", profile_id)
handle = db.GqlQuery("select * from Handle WHERE name =:1", profile_id)
for handles in handle:
handless = handles.handle_name
for months in month:
monthss = months.month
for countrys in country:
countryss = countrys.country
for days in day:
dayss = days.day
for years in year:
yearss = years.year
for clan in team_name:
name1 = clan.team_name_anycase
for clan in team_name:
name2 = clan.team_name
for image in team_images:
team_imagee = image.key()
for image2 in team_images2:
team_imagee2 = image2.key()
for img in imgs:
key = img.key()
for img2 in imgs2:
key2 = img2.key()
profile_submit_comment=''
post_check = self.request.get('profile_submit_comment')
if self.request.get('delete'):
the_post = self.request.get('delete')
q = Profile_Comments.get_by_id(int(the_post), parent=None)
db.delete(q)
error = "Comment successfully deleted."
self.render('profile.html', handle_var = handless, team_name2 = name2, error = error, imgs = imgs, team_img2 = team_imagee2, profile_image_posted = key2, posts = posts, profile_id = profile_id, country_var = countryss, day_var = dayss, year_var = yearss, month_var = monthss, current_user = current_user, friends = friends, team_img = team_imagee, team_name = name1, profile_image = key, username = self.user.name, email = self.user.email, firstname = self.user.first_name, last_name = self.user.last_name, country = self.user.country)
# if self.request.get('edit'):
# the_post = self.request.get('edit')
# q = Profile_Comments.get_by_id(int(the_post), parent=None)
# db.delete(q)
# self.redirect('/profile/%s' %profile_id)
elif not post_check:
error = "You cannot submit empty posts."
self.render('profile.html', team_name2 = name2, error = error, imgs = imgs, team_img2 = team_imagee2, profile_image_posted = key2, posts = posts, profile_id = profile_id, country_var = countryss, day_var = dayss, year_var = yearss, month_var = monthss, current_user = current_user, friends = friends, team_img = team_imagee, team_name = name1, profile_image = key, username = self.user.name, email = self.user.email, firstname = self.user.first_name, last_name = self.user.last_name, country = self.user.country)
elif self.request.get("profile_submit_comment") != '':
profile_comments = Profile_Comments (name_of_submitted = self.user.name, name_of_profile = profile_id)
commentupl = self.request.get("profile_submit_comment")
profile_comments.post = (commentupl)
profile_comments.put()
self.redirect('/profile/%s' %profile_id)
One of the main reasons why ‘Infinite Scrolling’ is used is to reduce the amount of data the needs to be sent initially when a page is loaded. I may be wrong but it looks like you have a single Gqlquery that loads all of a users posts. This doesn’t really make much sense with the infinite scroll concept. If all of the posts are queried when the page is loaded there would be minimal, if any, benefit from not displaying them all initially.
Anyways, I would consider using a jQuery plugin such as Infinite Scroll for this. Here’s the basic concept.
First load the page and print whatever has been returned from the GqlQuery.
Next use javascript to select the
<div id="posts">element.Then, load another set of posts (page 2) into an off-DOM
<div>.Finally, when someone has reached the bottom of the page, append the
<div id="posts">element that you selected with the next set of posts (insert them below the final post in the<div id="posts">element).