本文整理汇总了Python中models.Profile.put方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.put方法的具体用法?Python Profile.put怎么用?Python Profile.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Profile
的用法示例。
在下文中一共展示了Profile.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _getProfileFromUser
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent."""
#make sure user is authenticated
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# get user_id via the helper function in utils
user_id = utils.getUserId(user)
#generate a p_key for this user using the user_id
p_key = ndb.Key(Profile, user_id)
#get the profile associated with this p_key
profile = p_key.get()
if not profile:
profile = Profile(
key = p_key,
displayName = user.nickname(),
mainEmail= user.email(),
teeShirtSize = str(TeeShirtSize.NOT_SPECIFIED),
)
profile.put() #save profile to datastore
return profile # return Profile
示例2: _getProfileFromUser
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent."""
# make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# get Profile from datastore
user_id = getUserId(user)
p_key = ndb.Key(Profile, user_id)
# get the entity from datastore by using get() on the key
profile = p_key.get()
# create a new Profile from logged in user data
if not profile:
profile = Profile(
userId=None,
key=p_key,
displayName=user.nickname(),
mainEmail=user.email(),
teeShirtSize=str(TeeShirtSize.NOT_SPECIFIED),
)
profile.put()
return profile
示例3: _getProfileFromUser
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent.""" # noqa
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# Get user id by calling getUserId(user)
user_id = getUserId(user)
# Create a new key of kind Profile from the id.
p_key = ndb.Key(Profile, user_id)
# Get the entity from datastore by using get() on the key
profile = p_key.get()
# If profile doesn't exist, we create a new one
if not profile:
profile = Profile(
key=p_key,
displayName=user.nickname(),
mainEmail=user.email(),
teeShirtSize=str(TeeShirtSize.NOT_SPECIFIED),
)
# Save the profile to datastore
profile.put()
return profile # return Profile
示例4: _getProfileFromUser
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent."""
# make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# get Profile from datastore
user_id = getUserId(user)
p_key = ndb.Key(Profile, user_id)
profile = p_key.get()
# create new Profile if not there
if not profile:
profile = Profile(
key = p_key,
displayName = user.nickname(),
mainEmail= user.email(),
teeShirtSize = str(TeeShirtSize.NOT_SPECIFIED),
)
w_id = Wishlist.allocate_ids(size=1, parent=p_key)[0]
w_key = ndb.Key(Wishlist, w_id, parent=p_key)
wishlist = Wishlist(
key = w_key,
sessionKeys = []
)
profile.put()
wishlist.put()
return profile # return Profile
示例5: _getProfileFromUser
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent."""
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# TODO 1
# step 1. copy utils.py from additions folder to this folder
# and import getUserId from it
# step 2. get user id by calling getUserId(user)
# step 3. create a new key of kind Profile from the id
user_id = utils.getUserId(user)
p_key = ndb.Key(Profile, user_id)
logging.info("do we even generate a Key?")
logging.info(pKey)
print >> sys.stderr, "Something to log."
# TODO 3
# get the entity from datastore by using get() on the key
profile = pKey.get()
if not profile:
profile = Profile(
key = p_key,
displayName = user.nickname(),
mainEmail= user.email(),
teeShirtSize = str(TeeShirtSize.NOT_SPECIFIED),
)
# TODO 2
# save the profile to datastore
profile.put()
return profile # return Profile
示例6: get
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def get(self):
oauth_token = self.request.get('oauth_token', default_value=None)
oauth_verifier = self.request.get('oauth_verifier', default_value=None)
user = users.get_current_user()
authr = AuthRequest.all().filter('owner = ', user).get()
if oauth_token and oauth_verifier and user and authr:
host = self.request.headers.get('host', 'nohost')
access_token_url = 'https://%s/_ah/OAuthGetAccessToken' % host
consumer_key = 'anonymous'
consumer_secret = 'anonymous'
consumer = oauth.Consumer(consumer_key, consumer_secret)
token = oauth.Token(oauth_token, authr.request_secret)
token.set_verifier(oauth_verifier)
client = oauth.Client(consumer, token)
if "localhost" not in host:
resp, content = client.request(access_token_url, "POST")
if resp['status'] == '200':
access_token = dict(cgi.parse_qsl(content))
profile = Profile(owner=user,
token=access_token['oauth_token'],
secret=access_token['oauth_token_secret'])
profile.put()
self.redirect("/documentation/credentials")
示例7: post
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def post(self):
form = ProfileForm(data=self.request.POST)
if form.is_valid():
user = users.get_current_user()
username = self.request.get('username')
#profile = Profile.all().filter('user !=', user).filter('username =', username).get()
profile = Profile.all().filter('username =', username).get()
if profile and profile.user != user:
errors = { 'username_exists': ['%s is already exists'] }
profile = { 'username': username }
template_vars = { 'errors': errors, 'profile': profile }
self.render_response('profile/profile_edit.html', template_vars)
else:
profile = Profile.all().filter('user =', user).get()
if profile:
profile.username = username
else:
profile = Profile(user = user,
username = username,
)
profile.put()
self.redirect('/profile')
else:
template_vars = { 'form': form }
self.render_response('profile/profile_edit.html', template_vars)
示例8: _getProfileFromUser
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent."""
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# TODO 1
# step 1. copy utils.py from additions folder to this folder
# and import getUserId from it
# step 2. get user id by calling getUserId(user)
# step 3. create a new key of kind Profile from the id
k=getUserId(user)
# TODO 3
# get the entity from datastore by using get() on the key
p_key=ndb.Key(Profile,k)
profile = p_key.get()
if not profile:
profile = Profile(
key = p_key, # TODO 1 step 4. replace with the key from step 3
displayName = user.nickname(),
mainEmail= user.email(),
teeShirtSize = str(TeeShirtSize.NOT_SPECIFIED),
)
# TODO 2
# save the profile to datastore
profile.put()
return profile # return Profile
示例9: getSessionsInWishlist
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def getSessionsInWishlist(self, request):
"""Query for all sessions in a conference that the user is interested in."""
# Get current user
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization is required')
# Get profile of user from Profile datastore
user_id = getUserId(user)
p_key = ndb.Key(Profile, user_id)
profile = p_key.get()
# Create new Profile if it does not exist already
if not profile:
profile = Profile(
key = p_key,
displayName = user.nickname(),
mainEmail= user.email(),
teeShirtSize = str(TeeShirtSize.NOT_SPECIFIED),
)
profile.put()
sess_keys = [ndb.Key(urlsafe=ses) for ses in profile.SessionsInWishlist]
sessions = ndb.get_multi(sess_keys)
# return set of SessionForm objects per Session
return SessionForms(
items=[self._copySessionToForm(sess) for sess in sessions]
)
示例10: _get_profile_from_user
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def _get_profile_from_user(self):
"""Return user Profile from datastore, creating new one if
non-existent."""
# Make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
# Try to retrieve an existing profile...
user_id = get_user_id(user)
key = ndb.Key(Profile, user_id)
profile = key.get()
# ... and if not exists, create a new Profile from logged in user data
if not profile:
profile = Profile(
userId = user_id,
key = key,
displayName = user.nickname(),
mainEmail= user.email(),
teeShirtSize = str(TeeShirtSize.NOT_SPECIFIED),
)
# Create the profile in datastore
profile.put()
return profile
示例11: profile_from_user
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def profile_from_user():
"""
Return user Profile from datastore, creating new one if non-existent.
:return: Profile model for the current endpoint user
"""
# make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException("Authorization required")
# get Profile from datastore
user_id = get_user_id(user)
p_key = ndb.Key(Profile, user_id)
profile = p_key.get()
# create new Profile if not there
if not profile:
profile = Profile(
key=p_key,
displayName=user.nickname(),
mainEmail=user.email(),
teeShirtSize=str(TeeShirtSize.NOT_SPECIFIED),
)
profile.put()
return profile # return Profile
示例12: _getProfileFromUser
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if
non-existent."""
# TODO 2
# step 1: make sure user is authed
# uncomment the following lines:
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException("Authorization required")
p_key = ndb.Key(Profile, getUserId(user))
profile = None
# step 2: create a new Profile from logged in user data
# you can use user.nickname() to get displayName
# and user.email() to get mainEmail
profile = p_key.get()
if not profile:
profile = Profile(
key=p_key,
displayName=user.nickname(),
mainEmail=user.email(),
teeShirtSize=str(TeeShirtSize.NOT_SPECIFIED),
)
profile.put()
return profile # return Profile
示例13: _getProfileFromUser
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def _getProfileFromUser(self):
"""Return user Profile from datastore, creating new one if non-existent."""
## step 1: make sure user is authed
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException("Authorization required")
user_id = getUserId(user)
# Create an instance of a Key for an id(user email) of a kind(Profile)
p_key = ndb.Key(Profile, user_id)
# Get the entity(user profile) associated with the key
profile = p_key.get()
# If the entity does not exist, create a new entity and put in datastore
if not profile:
profile = Profile(
key=p_key,
displayName=user.nickname(),
mainEmail=user.email(),
teeShirtSize=str(TeeShirtSize.NOT_SPECIFIED),
)
# put will store profile as a persistent entity in the Datastore
profile.put()
return profile
示例14: _getProfileFromUser
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def _getProfileFromUser(self):
"""Return user Profile from DataStore or create add new one if
non-existent."""
# Getting and Verifying current user
user = getUser()
# get the user_id (email)
user_id = getUserId(user)
# Creating a profile key.
p_key = ndb.Key(Profile, user_id)
# Using the profile key to get a profile Object
profile = p_key.get()
# create new Profile if not there
if not profile:
profile=Profile(
key=p_key,
displayName=user.nickname(),
mainEmail=user.email(),
teeShirtSize=str(TeeShirtSize.NOT_SPECIFIED),)
profile.put()
return profile
示例15: createProfile
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import put [as 别名]
def createProfile(key, user, tshirtSize):
profile = Profile(
key = key,
displayName = user.nickname(),
mainEmail= user.email(),
teeShirtSize = tshirtSize,
)
profile.put()
return profile