Пример #1
0
 def current_user(self):
     if not hasattr(self, "_current_user"):
         self._current_user = None
         cookie = facebook.get_user_from_cookie(
             self.request.cookies, FACEBOOK_APP_ID, FACEBOOK_APP_SECRET)
         if cookie:
             # Store a local instance of the user data so we don't need
             # a round-trip to Facebook on every request
             user = WlUser.get_by_key_name(cookie["uid"])
             if not user:
                 graph = facebook.GraphAPI(cookie["access_token"])
                 profile = graph.get_object("me")
                 user = WlUser(key_name=str(profile["id"]),
                             id=str(profile["id"]),
                             name=profile["name"],
                             profile_url=profile["link"],
                             access_token=cookie["access_token"])
                 user.put()
             elif user.access_token != cookie["access_token"]:
                 user.access_token = cookie["access_token"]
                 user.put()
             self._current_user = user
             
             
     return self._current_user
Пример #2
0
    def get(self):
        
        self.response.headers['Content-Type'] = 'text/html'
        self.response.out.write("<title>rdemo</title>")
        self.response.out.write("<pre>")        
        p = Person(phone_number='1-206-555-9234',
                   address='123 First Ave., Seattle, WA, 98101',
                   first_name='Alfred',
                   last_name='Smith',
                   mobile_number='1-206-555-0117')
        p.put()
        
        c = Company(phone_number='1-503-555-9123',
                    address='P.O. Box 98765, Salem, OR, 97301',
                    name='Data Solutions, LLC',
                    fax_number='1-503-555-6622', flg_deleted=False)
        c.put()
        
        for contact in Contact.all():
            # Returns both p and c.
            # ...
            if not contact.flg_deleted: self.response.out.write("Contact: %s; %s \n" % (contact.address, contact.name))
            else: self.response.out.write("...deleted Contact...\n")
        
        for person in Person.all():
            # Returns only p.
            # ...
            if not person.flg_deleted: self.response.out.write("Person: %s; %s\n" % (person.address, person.name))     

             
        for x in Contact.all(): x.flg_deleted = True;x.put()
                    
        #for u in WlUser.all():
        #    u.delete()
        uc = WlUser.all()
        #print uc.count()
        if uc.count() < 1:
            u = WlUser(key_name='roger', id='roger', profile_url='http://', access_token='a', name="Roger")
            u.put()
        r = WlUser.get_by_key_name("roger")
        self.response.out.write("<a href='http://google.com'>google</a><br />")
        self.response.out.write('Hello world! %s ' % r.name)