Hi-
I'm sure that there are several ways to do this, but I'm struggling a
little bit to get over the hump after the Python tutorial. I'm just
starting to know GAE and have been trying out a few things to see if I
really understand some of the basic hooks. For now, I'm working on an
app from scratch that is trying to ask the user to login (using the
Users service), and after login, I am attempting to use some logic
(queries + filters) to determine whether the user already belongs to
my group, or not, by querying the datastore. If they do (belong) the
user is brought to their homepage and circumvents the sign up
screens. If they don't (belong), or if they are new signees, they are
taken to a site where they can fill in forms.
For one reason or another, though, by app won't run. Each time I try
and launch the program onto a web host from the GAE application
window, the browswer reads "Oops, that link appears to be broken". I
may just be missing something fundamental. I am pasting my code. I
have had to use a number of files, and please do let me know If I am
missing something substantial. I have other files but these two are
the main two.
This is quite the problem and I can't seem to pinpoint the cause.
I am trying to automatically direct the user to different .py files in
yaml based upon URL handlers as well.
application: helloworld
version: 1
runtime: python
api_version: 1
handlers:
- url: /stylesheets
static_dir: stylesheets
- url: /UserDirect/.*
script: go2userhome.py
- url: /.*
script: helloworld.py
helloworld.py
import cgi
import datetime
import urllib
import wsgiref.handlers
import os
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
class LoginPage(webapp.RequestHandler):
def get(self):
#if users.get_current_user():
#I am quite positive that if I take out url and url_linktext
nothing would happen
#url = '/'
#url_linktext = 'Enter Your Homepage'
#self.redirect('/sign')
#else:
if users.get_current_user():
#url = users.create_logout_url(self.request.uri)
#url_linktext = 'Logout'
#greetings = 'Welcome to my site'
self.redirect('/UserDirect')
return
else:
url = users.create_login_url(self.request.uri)
url_linktext = 'Login Here'
greetings = 'Please login. '
greetings = 'Hello'
template_values = {
'greetings' : greetings,
'url': url,
'url_linktext': url_linktext
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
application = webapp.WSGIApplication([
('/', LoginPage),
], debug=True)
def main():
run_wsgi_app(application)
if __name__ == '__main__':
main()
Updating the datastore :
import cgi
import datetime
import urllib
import wsgiref.handlers
import os
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
class Users(db.Model):
"""Keeps track of all users who have signed up for this service."""
#I don't believe that required = True is necessary, should I include
it
user = db.UserProperty()
userid = db.StringProperty()
#name = db.StringProperty()
firstname = db.StringProperty()
lastname = db.StringProperty()
joindate = db.DateTimeProperty(auto_now_add=True)
#I may want to include a counter, I know it does not belong here,
but in the location where I create the user
class FindUserAcct(webapp.RequestHandler):
def get(self):
"""FindUserAcct navigates the user through account set-up or takes
them to their homepage"""
#need to determine if the user exists in the database or is new
currentUserID = users.get_current_user().user_id()
q = Users.all()
q.filter('userid =', currentUserID)
results = q.fetch()
if currentUserID in results:
#if they are an existing user, I can send them to their homepage
#I may want to make this a more unique pagename somehow?
self.redirect('/homepage')
return
else:
#if they are new, I need to send them to an information screen
to capture more information
self.redirect('/signup')
return
class CreateUserAcct(webapp.RequestHandler):
def post(self):
#create a new user account, then grab user info after they have
entered it into their form
currentUser = users.get_current_user()
currentUserID = currentUser.user_id()
newuser = Users()
newuser.user = currentUser
newuser.userid = currentUserID
newuser.firstname = self.request.get('firstname')
newuser.lastname = self.request.get('lastname')
greetings = 'Welcome to Terabuild. Please take a moment to tell
us about yourself.'
template_values = {
'greetings' : greetings,
'firstname': firstname,
'lastname' : lastname
}
path = os.path.join(os.path.dirname(__file__), 'createuser.html')
self.response.out.write(template.render(path, template_values))
newuser.put()
self.redirect('/homepage')
class UserHome():
def put(self):
greetings = 'You are successfully logged in to Terabuild.'
url = users.create_logout_url(self.request.uri)
url_linktext = 'Logout'
template_values = {
'greetings' : greetings,
'url' : url,
'url_linktext' : url_linktext
}
path = os.path.join(os.path.dirname(__file__), 'homepage.html')
self.response.out.write(template.render(path, template_values))
application = webapp.WSGIApplication([
('/', FindUserAcct),
('/signup', CreateUserAcct),
('/homepage', UserHome)
], debug=True)
def main():
run_wsgi_app(application)
if __name__ == '__main__':
main()
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
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.