当前位置: 首页>>代码示例>>Python>>正文


Python User.key方法代码示例

本文整理汇总了Python中models.user.User.key方法的典型用法代码示例。如果您正苦于以下问题:Python User.key方法的具体用法?Python User.key怎么用?Python User.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.user.User的用法示例。


在下文中一共展示了User.key方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import key [as 别名]
 def post(self):            
     user_key =self.get_secure_cookie("user_key")
     r = None
     
     user_data = {}
     info_data = {}
     
     
     userInfo = UserInfo()
     user = User()
     user.key = user_key
     user.data = user.get(user_key)
     user.data['nickname'] = self.get_argument("user_nickname",None)
     
     userInfo.key = user_key
     
     userInfo_data = userInfo.get(user_key)
     if userInfo_data:
         userInfo.data = userInfo_data
         
     userInfo.data['city']        = self.get_argument("user_city","")
     userInfo.data['url']         = self.get_argument("user_url","")
     userInfo.data['desc']        = self.get_argument("user_description","")
     
     userInfo.post()
     user.post()        
     
     self.redirect('/settings/')
开发者ID:aviatorBeijing,项目名称:ptpy,代码行数:30,代码来源:user.py

示例2: get

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import key [as 别名]
    def get(self):
        if self.request.get('userid'):
            user_info = flickr.FlickrUserInfo("", self.request.get('userid'), self.request.get('userid'), "")
        else:
            frob = self.request.get('frob')                        
            
            try:
                user_info = flickr.get_user_info(frob)
            except:
                user_info = flickr.get_user_info(frob)                
        
    
        user = User.get_by_key_name(user_info.nsid)
        
        session = Session()

        if user is None:
            user = User(key_name = user_info.nsid,
                        username = user_info.username,
                        fullname = user_info.fullname, 
                        token    = user_info.token,     
                        status   = const.UserRegistred,                      
                        last_login = datetime.datetime.now())
                     
        task = None
        
        if not user.is_saved() or user.status == const.UserUnRegistred:
            task = taskqueue.Task(url="/task/user/update_contacts", 
                                  params={'key':user.key(), 'update_favorites':True, 'initial_update': True})                           
        
        user.status = const.UserRegistred
        user.username = user_info.username
        user.fullname = user.fullname
        user.token = user_info.token
        
        if os.environ.get('SERVER_SOFTWARE') == 'Development/1.0':
            user.token = '72157623100491721-4ab7039d8e6b4615' 
        #user.token = '72157622500427269-7131c791b2204f16'
        user.last_login = datetime.datetime.now()
        
        try:
            user.put()
        except:
            user.put()
        
        if task:
            task.add("non-blocking")
        
        session["username"]   = user.username
        
        if user.fullname:
            session["fullname"]   = user.fullname
            
        session["nsid"]     = user.nsid
        session["auth_token"] = user.token
        
        session["difficulty"] = user.difficulty
        session["layout"] = user.layout        
                                                                        
        self.redirect("/dashboard")
开发者ID:buger,项目名称:flick_faver,代码行数:62,代码来源:main.py

示例3: setUp

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import key [as 别名]
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()

        google_api.httplib2.Http = MockHttp
        
        now = datetime.datetime.now()
        user = User(**dummy.user)
        user.put()
        self.user = user

        ds = DataSource(**dummy.data_source)
        ds.user = user.key()
        ds.put()
        self.data_source = ds

        dv = DataView(**dummy.data_view)
        dv.data_source = ds.key()
        dv.put()
        self.data_view = dv
开发者ID:opendatapress,项目名称:open_data_press,代码行数:23,代码来源:test_public.py

示例4: get

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import key [as 别名]
	def get(self):
		verifier = self.request.get("oauth_verifier")
		
		if verifier:
			# Get access token
			handler = auth.OAuthHandler(config.CONSUMER_KEY, config.CONSUMER_SECRET)
			handler.set_request_token(self.session.get("request_token_key"), self.session.get("request_token_secret"))
			access_token = handler.get_access_token(verifier)
			
			if access_token:
				# Get user			
				logging.info("Access token: %s" %(access_token))
				user = User.all().filter("twitter_access_token_key", access_token.key).get()
				
				if((not user) or (user and user.updated < datetime.now() - timedelta(0,86400))):
					logging.info("Connecting to the Twitter API")
					api = API(handler)
					temp_user = api.verify_credentials()
					temp_image = urlfetch.Fetch(str(temp_user.profile_image_url).replace("_normal", "")).content

					# Transform image into .PNG
					image_manager = images.Image(image_data=temp_image)
					image_manager.rotate(360)
					temp_png = image_manager.execute_transforms()
					logging.info("Encoded into .PNG")

					# Save or update image in Cloud storage
					filename = config.FOLDER + "/" + str(temp_user.id)
					gcs_file = gcs.open(filename,'w',content_type="image/png",options={"x-goog-acl":"public-read"})
					gcs_file.write(temp_png)
					gcs_file.close()
					logging.info("Image saved to Google Cloud Storage")

					# Get avatar
					blob_filename = "/gs" + filename
					blobkey = blobstore.create_gs_key(blob_filename)
					temp_avatar = str(images.get_serving_url(blobkey))
								
					if not user:
						logging.info("User did not exist")

						user = User(
							twitter_id = str(temp_user.id),
							twitter_access_token_key = str(access_token.key),
							twitter_access_token_secret = str(access_token.secret),
							username = str(temp_user.screen_name).lower(),
							name = temp_user.name,
							bio = temp_user.description,
							avatar = temp_avatar,
						)
						
					else:
						logging.info("User had to be updated")

						user.twitter_id = str(temp_user.id)
						user.twitter_access_token_key = str(access_token.key)
						user.twitter_access_token_secret = str(access_token.secret)
						user.username = str(temp_user.screen_name).lower()
						user.name = temp_user.name
						user.bio = temp_user.description
						user.avatar = temp_avatar
											
					user.put()
					logging.info("User @%s saved in datastore"%(user.username))
				
				# Save user in session
				self.session["id"] = user.key().id()
				
			else:
				logging.error("No access token from Twitter")
				print "Error"
		else:
			logging.error("No verifier")
			print "Error"
		
		# Redirect users to the page they came from or the page they're supposed to head to
		next = self.session.get("next")
		redirect = self.session.get("referer")
		if next:
			redirect = next
		self.redirect(str(redirect))
开发者ID:detcherry,项目名称:gopitch,代码行数:83,代码来源:auth.py

示例5: post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import key [as 别名]
    def post(self):
        username_error = invalid_email = invalid_password = verify_password_error = None

        #Retrieve form information from user sign up submission
        user_username = self.request.get("username")
        user_password = self.request.get("password")
        user_verify_password = self.request.get("verify")
        user_email = self.request.get("email")

        params = dict(username = user_username,
                    email = user_email)

        username = valid_name(user_username)
        password = valid_password(user_password)
        verify_password = None
        email = None

        if user_email:
            email = valid_email(user_email)
            if not email:
                params['invalid_email'] = "That's not a valid email."

        if not username:
            params['username_error'] = "That's not a valid username."
        elif (User.by_name(user_username)):
            username = None
            params['username_error'] = "User already exists !"

        if password:
            verify_password = valid_verify_password(user_password, user_verify_password)
            if not verify_password:
                params['verify_password_error'] = "Your passwords didn't match."
        else:
            params['invalid_password'] = "That wasn't a valid password."

        if username and password and verify_password and not invalid_email:
            password_hash = hash_pwd(user_username, user_password)
            user = User(username = user_username, password = password_hash, email = user_email)
            user.put()
            self.response.headers.add_header('Set-Cookie','user_id=%s; Path=/' % make_secure_value(str(user.key().id())))
            self.redirect("/blog/welcome")
        else:
            self.render("signup.html", **params)
开发者ID:harikrish00,项目名称:blogit,代码行数:45,代码来源:sign_up.py

示例6: TestDataSourceModel

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import key [as 别名]
class TestDataSourceModel(unittest.TestCase):

    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.user = User(**dummy.user)
        self.user.put()


    def tearDown(self):
        self.testbed.deactivate()


    def make_data_source(self):
        ds = DataSource(**dummy.data_source)
        ds.user = self.user.key()
        ds.put()
        return ds


    def test_data_source_properties_exist(self):
        ds = DataSource(**dummy.data_source)
        self.assertTrue('created_at'         in dir(ds))
        self.assertTrue('description'        in dir(ds))
        self.assertTrue('google_spreadsheet' in dir(ds))
        self.assertTrue('google_worksheet'   in dir(ds))
        self.assertTrue('licence'            in dir(ds))
        self.assertTrue('modified_at'        in dir(ds))
        self.assertTrue('slug'               in dir(ds))
        self.assertTrue('tags'               in dir(ds))
        self.assertTrue('tbl_stars'          in dir(ds))
        self.assertTrue('title'              in dir(ds))


    def test_data_source_instance_methods_exist(self):
        ds = DataSource(**dummy.data_source)
        self.assertTrue('to_dict' in dir(ds))


    def test_data_source_required_properties(self):
        with self.assertRaises(db.BadValueError) as cm:
            bad_params = dummy.data_source.copy()
            del bad_params['created_at']
            DataSource(**bad_params)
        self.assertTrue('created_at' in cm.exception.message)

        with self.assertRaises(db.BadValueError) as cm:
            bad_params = dummy.data_source.copy()
            del bad_params['modified_at']
            DataSource(**bad_params)
        self.assertTrue('modified_at' in cm.exception.message)

        with self.assertRaises(db.BadValueError) as cm:
            bad_params = dummy.data_source.copy()
            del bad_params['slug']
            DataSource(**bad_params)
        self.assertTrue('slug' in cm.exception.message)

        with self.assertRaises(db.BadValueError) as cm:
            bad_params = dummy.data_source.copy()
            del bad_params['google_worksheet']
            DataSource(**bad_params)
        self.assertTrue('google_worksheet' in cm.exception.message)

        with self.assertRaises(db.BadValueError) as cm:
            bad_params = dummy.data_source.copy()
            del bad_params['google_spreadsheet']
            DataSource(**bad_params)
        self.assertTrue('google_spreadsheet' in cm.exception.message)


    def test_data_source_create(self):
        ds_count_a = DataSource.all().count()
        ds = self.make_data_source()
        self.assertEqual(ds_count_a + 1, DataSource.all().count())


    def test_data_source_delete(self):
        ds = self.make_data_source()
        ds_count_a = DataSource.all().count()
        ds.delete()
        self.assertEqual(ds_count_a -1, DataSource.all().count())


    def test_data_source_method_to_dict(self):
        ds = self.make_data_source()
        data = ds.to_dict()
        self.assertTrue('created_at'         in data)
        self.assertTrue('data_views'         in data)
        self.assertTrue('description'        in data)
        self.assertTrue('google_spreadsheet' in data)
        self.assertTrue('google_worksheet'   in data)
        self.assertTrue('id'                 in data)
        self.assertTrue('licence'            in data)
        self.assertTrue('modified_at'        in data)
        self.assertTrue('slug'               in data)
        self.assertTrue('tags'               in data)
        self.assertTrue('tbl_stars'          in data)
        self.assertTrue('title'              in data)
#.........这里部分代码省略.........
开发者ID:opendatapress,项目名称:open_data_press,代码行数:103,代码来源:test_data_source.py


注:本文中的models.user.User.key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。