Users and strings

6 views
Skip to first unread message

interman

unread,
Jun 16, 2008, 3:44:56 PM6/16/08
to Google App Engine
Hi,
I'm writing an app where users store their game backlog. It works just
fine when a user is working on his own stuff, but I'd like a /profile/
(.*) that simply displays all the games for that user / that user's
nickname - something he or she can link to wherever. The problem is
that I can't seem to filter the query based on the string in the url,
or any other string for that matter. If I could somehow cast the
nickname to a string, and store that along with the userproperty - but
no...

Any tips?


Cheers,
Andreas

Mahmoud

unread,
Jun 16, 2008, 4:08:03 PM6/16/08
to Google App Engine
You can split the path that is passed to the handler script this way:
path_list = self.request.path.strip('/').split('/')

If the URL is /porfile/interman
then path_list will be ['profile', 'interman']

If you have a user model that looks something like this:

class MyUser(search.SearchableModel):
user = db.UserProperty()

#The name is a string property, which means that it is indexable
and searchable.
name = db.StringProperty()

def put(self):
#Replace the dots with spaces, and capitalize the name
properly
self.name = self.user.nickname()
db.Model.put(self)

Then, you can query for a user this way:

user = MyUser.gql("WHERE name =:1", path[1])


By the way, a different way to map URLs is explained here:
http://code.google.com/appengine/docs/webapp/running.html

interman

unread,
Jun 16, 2008, 5:55:49 PM6/16/08
to Google App Engine
Awesome, I'll give this a shot tomorrow.

Thanks a lot


-Andreas

Blixt

unread,
Jun 17, 2008, 2:20:01 AM6/17/08
to Google App Engine
Another way to do it is to use the following:
# ...
class ProfilePage(webapp.RequestHandler):
def get(self, user_id):
# user_id will automagically be whatever was captured into
(.*)
pass

def main():
application = webapp.WSGIApplication([
('/profile/(.*)', ProfilePage)
])
wsgiref.handlers.CGIHandler().run(application)
# ...

Regards,
Andreas
Reply all
Reply to author
Forward
0 new messages