I am new to GAE, have read tutorial and followed the guestbook example to
apply to my app. I've tried to communicate on Stackoverflow, but due to
negative rating, I cannot ask my question there. Please help here.
I have responses that display on page when site visitor submits form.
Submitted form values are stored in Datastore. Responses and Datastore all
work great except when a visitor goes to my page, the previous response is
already displayed because the query seems to execute when the page
loads...but I need response to display *only* immediately after form
submit, and not carry over to subsequent page visits. Is this achieved
through editing the query, session, headers? If so please lead me to the
solution.
messages = db.GqlQuery("SELECT * "
> "FROM Visitor " #Visitor is Datastore
> entity; properties are name, mood, date.
> "ORDER BY date DESC LIMIT 1")
> for message in messages:
> if message.name and message.mood == "": #give warning if user
> doesn't fill out form; of course this too is displaying on page load, but I
> need it to display only if user doesn't fill out form. help? v v
> self.response.out.write("<body><html>")
> self.response.out.write("<div class='textright'>Type your
> first name and select mood.</div>")
> self.response.out.write("</body></html>")
> elif message.mood == "bad" and message.name != "":
> self.response.out.write("<body><html>")
> self.response.out.write("<div class='textright'>Stay the
> course %s...# more if/elifs responses follow based on mood value; these are
> the "responses" that I need to display only right after form submit, not
> when page loads with new visitor, etc.
>
> self.response.out.write("""<html><body>
> <form action="/process" method="post">
> <p>First Name: <input type="text" name="name"/></p>
> <p><input type="radio" name="mood" value="good">Good</p>
> <p><input type="radio" name="mood" value="bad">Bad</p>
> <p><input type="radio" name="mood" value="fair">Fair</p>
> <p><input type="submit" value="Process"/></p>
> </form>
> </body></html> """)
>
> class Process(webapp2.RequestHandler):
> def post(self):
> name = self.request.get("name")
> mood = self.request.get("mood")
> message = Visitor(name=name, mood=mood) #Visitor is entity (from
> class Visitor db.Model)
> if users.get_current_user(): #tried
> this but probably not necessary; no log-in required.
> message.name = users.get_current_user()
> message.mood = self.request.get("mood")
> message.put()
>
> self.redirect("/")
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-appengine/-/Yjpjw1fbNoUJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.