本文整理汇总了Python中model.User.get_or_insert方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_or_insert方法的具体用法?Python User.get_or_insert怎么用?Python User.get_or_insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.get_or_insert方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_or_insert [as 别名]
def post(handler, response):
people_yaml = handler.request.get('people')
import logging
people = yaml.load(people_yaml)
for person in people:
user = User.get_or_insert(key_name=person.get('email') or person['name'])
user.name = person['name']
user.link = person.get('link')
user.private = bool(person['private'])
user.city = person['city']
user.distance = person['distance']
if 'location' in person:
match = re.match('^(.*), (.*)$', person['location'])
if match:
(lat, lon) = match.groups()
user.location = db.GeoPt(lat, lon)
user.update_location()
user.put()
for slug in person['organizing']:
event = Event.all().filter('slug =', slug).get()
if event:
user.add_event(event, bool(1))
for slug in person['attending']:
event = Event.all().filter('slug =', slug).get()
if event:
user.add_event(event)
示例2: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_or_insert [as 别名]
def get(self, user_email):
flow = createFlow(self, user_email)
credentials = StorageByKeyName(CredentialsModel, user_email, 'credentials').get()
force = self.request.get('force')
if force and force == 'true':
self.redirect(flow.step1_get_authorize_url())
return
if credentials:
user = User.get_by_key_name(user_email)
if not user or not user.is_oauth_complete:
ctxIO = ContextIO(consumer_key=settings.CONTEXTIO_OAUTH_KEY,
consumer_secret=settings.CONTEXTIO_OAUTH_SECRET)
current_account = ctxIO.post_account(email=user_email)
user = User.get_or_insert(key_name = user_email,
user_ctx_id=current_account.id,
email=user_email)
refresh_token = credentials.refresh_token
try:
if not refresh_token:
raise Exception('no refresh token')
current_account.post_source(email=user_email,
username=user_email,
server='imap.gmail.com',
provider_refresh_token=refresh_token,
provider_consumer_key=settings.APPENGINE_CONSUMER_KEY)
except Exception as e:
logging.error(str(e))
self.redirect(flow.step1_get_authorize_url())
user.is_oauth_complete = True
user.put()
self.response.out.write(r"""<html><head><script type="text/javascript">window.close();</script></head><body><div id="sbi_camera_button" class="sbi_search" style="left: 0px; top: 0px; position: absolute; width: 29px; height: 27px; border: none; margin: 0px; padding: 0px; z-index: 2147483647; display: none;"></div></body></html>""")
else:
logging.info('redirect')
self.redirect(flow.step1_get_authorize_url())
示例3: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_or_insert [as 别名]
def get(self):
http = decorator.http()
# Call the service using the authorized Http object.
request = service.files().list()
response = request.execute(http=http)
resultlist = []
for f in filter(lambda x:x['mimeType'] == 'application/pdf' and not x['labels']['trashed'],response['items']):
downloadUrl = f.get('downloadUrl')
if downloadUrl:
logging.info('Request file %s' % f['title'])
resp, content = http.request(downloadUrl)
if resp.status == 200:
logging.info('Request successful')
pdfobj = PdfFileReader(StringIO(content))
f['numpages'] = pdfobj.getNumPages()
resultlist.append(f)
else:
logging.error('An error occured %s' % resp)
else:
logging.info('No download url for file %s' % f['title'])
logging.info('User email: %s' % users.get_current_user().email())
curUser = User.get_or_insert(users.get_current_user().email(),email=users.get_current_user().email())
for f in resultlist:
Doc.get_or_insert(f['id'],parent=curUser.key(),title=f['id'],totalPages=f['numpages'],user=curUser)
template_values = {
'filelist' : resultlist
}
template = jinja_environment.get_template('home.html')
self.response.out.write(template.render(template_values))
示例4: user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_or_insert [as 别名]
def user():
user_key = request.headers.get("X-SecondLife-Owner-Key")
user_name = request.headers.get("X-SecondLife-Owner-Name")
version = request.args.get("version")
user_name_ = request.args.get("username")
if user_name != user_name_:
user_name = user_name_
if not version or version < VERSION:
send_update(user_name, user_key)
if MANDATORY:
return Response("Your Navigator is outdated, I'm sending you version %s." % VERSION, status=406)
else:
return Response("Your Navigator is outdated, I'm sending you version %s." % VERSION)
user = User.get_or_insert(user_key, name=user_name)
if not user is None:
if user.name != user_name:
user.name = user_name
user.uuid = uuid4().hex
user.put()
memcache.set(key="user-%s" % user_key, value=serialize_entities(user), time=CACHE_TIME)
return Response("Connected. Your navigator is up-to-date.")
else:
return Response("Unable to create a new user. Try rezzinga a new HUD.", status=500)
示例5: current_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_or_insert [as 别名]
def current_user(self):
"""Returns the logged-in User object."""
u = users.get_current_user()
if u:
key_name = User.key_name_from_email(u.email())
user = memcache.get(key_name)
if user:
if not user.banned:
return user
try:
# User models are keyed by user email
user = User.get_or_insert(key_name=key_name, user=u)
user.invalidate() # cache it
if not user.banned:
return user
except CapabilityDisabledError:
pass
示例6: current_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_or_insert [as 别名]
def current_user(self):
"""Returns the logged-in User object."""
user = users.get_current_user()
if user:
return User.get_or_insert(key_name=user.email())