fetch() returns a list which is empty if no entities match the query.
In your code, "result is not None" is always True.

You can rewrite it like this:

def index(request):
    token = token.find_token(user)
    if token:
        return HttpResponsePermanentRedirect('/home')
    else:
        return HttpResponsePermanentRedirect('/setup/introduction')

def find_token(user):
    return db.GqlQuery("SELECT * FROM accountToken WHERE user
= :userobj", userobj=user).get()

On Sep 21, 8:51 am, Sam G <[EMAIL PROTECTED]> wrote:
> No ideas, from anyone?
>
> Sam
>
> On Sep 18, 10:09 pm, Sam G <[EMAIL PROTECTED]> wrote:
>
> > Hello (again),
>
> > I'm running into a problem that I would think would be easy to solve.
> > I've set up a system to send a given user to an AuthSub token request
> > URL on first login. After first login, there should be a token in the
> > datastore for the user, and they can go straight to the home page when
> > they log in.
>
> > In my view code (that gets run whenever someone hits '/'):
>
> > def index(request):
> >     result = token.CheckToken(user)
> >     if result == True:
> >         return HttpResponsePermanentRedirect('/home')
> >     else:
> >         return HttpResponsePermanentRedirect('/setup/introduction')
>
> > CheckToken Function:
>
> > def CheckToken(user):
> >     token = db.GqlQuery("SELECT * FROM accountToken WHERE user
> > = :userobj", userobj=user)
> >     result = token.fetch(1,0)
> >     if result is not None:
> >         return True
> >     else:
> >         return False
>
> > Here is my model for accountToken:
>
> > class accountToken(db.Model):
> >     user = db.UserProperty(required=True)
> >     token = db.StringProperty(required=True)
> >     version = db.IntegerProperty()
> >     created = db.DateTimeProperty(auto_now_add=True)
>
> > By the way, the key_name for each accountToken instance is the user's
> > nickname().
>
> > Using the code above, when I log in as a user who definitely has a
> > token, they are redirected to the home page (like they should be).
> > However, when I log in as a user who does not have a token, they are
> > also redirected to the home page.
>
> > Ideas?
>
> > Sam
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to