本文整理汇总了Python中model.user.User.all方法的典型用法代码示例。如果您正苦于以下问题:Python User.all方法的具体用法?Python User.all怎么用?Python User.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.user.User
的用法示例。
在下文中一共展示了User.all方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import all [as 别名]
def get(self):
users = User.all().fetch(None)
emails = [user.email for user in User.all()]
current_user = util.get_user_from_session()
template_values = {'emails': emails, 'current_user': current_user.email if current_user else None}
path = 'templates/list_users.html'
self.response.out.write(template.render(path, template_values))
示例2: get
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import all [as 别名]
def get(self):
user = self.get_current_user()
kwargs = self.flat_args_dict()
# optional args
for k in ['first_name', 'last_name','image_url', 'phone','organization','email','website']:
# TODO: sanitize
if kwargs.get(k):
v = kwargs.get(k)
setattr(user, k, v)
if self.get_argument('domains',''):
from model.user import User
domains = [d.strip() for d in self.get_argument('domains').split(',')]
for d in domains:
# TODO: validate
# expensive...
logging.info('seeking matches for domain %s' % d)
domain_user = User.all().filter('domains', d).get() # there SHOULD only be one at most
if domain_user and domain_user.key().name() != user.key().name():
self.write(
'Domain "<i>%s</i>" has already been claimed by another account.<br/> Contact [email protected] if this domain belongs to you.' % d)
return
user.domains = domains
# set preferences
if self.get_argument('template',''):
user.preferences = {
'template': self.get_argument('template').lower(),
'foursquare_data': self.get_argument('foursquare_data',False),
'yelp_data': self.get_argument('yelp_data',False),
'facebook_data': self.get_argument('facebook_data',False)
}
user.put()
示例3: get_user_fb_ids
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import all [as 别名]
def get_user_fb_ids():
user_q = User.all()
for user in user_q.fetch(1000):
k = db.Key.from_path('User', user.email, 'ThirdPartyUserData', 'FB')
q = ThirdPartyUserData.all().filter('__key__ =', k)
for tpud in q.fetch(1000):
print user.name.encode('utf-8'), ',', user.email.encode('utf-8'), ',', tpud.id_.encode('utf-8')
print >> user_info_file, user.name.encode('utf-8'), ',', user.email.encode('utf-8'), ',', tpud.id_.encode('utf-8')
示例4: testUserCreate
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import all [as 别名]
def testUserCreate( self ):
self.setup_admin_user()
u = users.get_current_user()
self.isNotNone( u )
_lu = User(
user = u,
email = u.email(),
is_blog_owner = users.is_current_user_admin()
)
_lu.put()
self.assertEquals( _lu.email, u.email() )
self.assertEquals( User.all().count(), 1 )
self.assertEquals( User.all().get().user, u )
示例5: find
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import all [as 别名]
def find(self, query=None, create="true", user=None, code=None, **kwargs):
self.query, self.create, self.user = self.sanitize(query), create, user
if code:
from model.user import User
self.user = User.all().filter("short_code", code).get()
if self.create == "true":
self.create = True
else: # you must manually set create to something besides true
self.create = False
if query:
logging.info("query for FindLocation " + query)
from backend.location.update import get_loc_code
loc_code = get_loc_code(query)
# this is very imprecise! actual search is needed
loc = None
loc_results = self.search()
logging.info(loc_results)
if loc_results:
loc_doc = loc_results[0]
for f in loc_doc.fields:
logging.info(f.name)
logging.info(f.value)
loc = Location.get_by_key_name(loc_doc.fields[1].value)
if loc:
logging.info("found location %s in db" % loc.code)
if not loc and self.create:
logging.info("creating new location for %s" % query)
from backend.location.update import LocationUpdate
loc_updater = LocationUpdate()
loc = loc_updater.create_or_update(name=query, code=loc_code) # a lot of other fields...
return loc # hasn't saved
loc_query = Location.all()
if self.user and not self.user.is_admin():
loc_query = loc_query.filter("owner", self.user)
locs = loc_query.fetch(1000)
return locs
示例6: get
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import all [as 别名]
def get(self):
# Getting Users from the Db
usersModelObj = []
modelUsers = User.all()
for modelUser in modelUsers:
userModelObj = {}
userModelObj['account'] = str(modelUser.account)
userModelObj['fundsAvailable'] = modelUser.fundsAvailable if \
modelUser.group == 'Broker' else '*****'
userModelObj['group'] = modelUser.group
usersModelObj.append(userModelObj)
# Wrapping and sending
itemsWrapper = {}
itemsWrapper['items'] = usersModelObj
usersToSendJson = json.dumps(itemsWrapper)
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(usersToSendJson)
示例7: get
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import all [as 别名]
def get(self, api_version):
self.check_version(api_version)
pass_dict = self.flat_args_dict()
pass_dict.update({
'schedule': {}
})
for f in ['starts','ends','weekday_range','times']:
pass_dict['schedule'][f] = self.get_argument(f,'')
if pass_dict['schedule']['times']:
pass_dict['schedule']['times'] = eval(pass_dict['schedule']['times'])
else:
pass_dict['schedule']['times'] = []
if pass_dict.get('price') not in [None,'']: # TODO: use float instead?
pass_dict['price'] = int(pass_dict['price'].split('.')[0])
if pass_dict.get('price_rating'):
pass_dict['price_rating'] = len(pass_dict['price_rating'])
if self.get_argument('code'):
# TODO: it might be possible to do this without any User lookup, optimization
from model.user import User
pass_dict['user'] = User.all().filter('short_code', self.get_argument('code')).get()
from backend.passes import update
updater = update.PassUpdate()
updated_template = updater.create_or_update(**pass_dict)
if self.get_argument('delete',''):
db.delete(updated_template)
else:
db.put(updated_template)
# this could be deferred for extra put
from backend.passes import push
pass_pusher = push.PassPusher()
pass_pusher.create(updated_template, self.get_argument('changeMessage',''))
self.find_passes()
示例8: get
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import all [as 别名]
def get(self, api_version):
self.check_version(api_version)
loc_dict = {}
for f in [
"name",
"code",
"phone",
"yelp",
"opentable",
"website",
"neighborhood_name",
"street_address",
"region_name",
"region_code",
]:
if self.get_argument(f, ""):
loc_dict[f] = self.get_argument(f)
if loc_dict[f] == " ":
loc_dict[f] = "" # b/c this is not None it can remove a set property
if self.get_argument("code"):
# TODO: it might be possible to do this without any User lookup, optimization
from model.user import User
loc_dict["user"] = User.all().filter("short_code", self.get_argument("code")).get()
from backend.location import update
updater = update.LocationUpdate()
updated_location = updater.create_or_update(**loc_dict)
if self.get_argument("delete", ""):
db.delete(updated_location)
else:
db.put(updated_location)
self.find_locations()
示例9: find_passes
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import all [as 别名]
def find_passes(self):
query_args = { }
for f in ['query', 'order', 'create', 'passes', 'account']:
if self.get_argument(f,''):
query_args[f] = self.get_argument(f)
if self.get_argument('code',''):
# TODO: it might be possible to do this without any User lookup, optimization
from model.user import User
query_args['user'] = User.all().filter('short_code', self.get_argument('code')).get()
from backend.passes import find
self.context['passes'] = find.find_passes(**query_args)
if self.get_argument('output','') == 'html':
# this is only for account CMS
self.render("website/account/cms/pass/list.html", **self.context)
else:
response_json = {'passes': [ self.pass_dict(p) for p in self.context['passes'] ]}
if self.get_argument('sdk'):
self.ua_type()
# include personalized dialog html - could possibly be cached for identical UAs
response_json['dialog_html'] = self.render_string('resources/dialog/dialog.html', **self.context)
self.write_json(response_json)
return
示例10: get_user
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import all [as 别名]
def get_user(self, create_user=False, user_keyname=None,
password=None, old_user=None, set_user=True, admin=False, **kwargs):
"""
"""
if password:
password = password.lower().strip()
else:
raise errors.PasswordError
user = self.get_current_user()
if user:
if not user_keyname:
return user
if user.key().name().startswith('auto_gen_'):
old_user = user
else:
if (user_keyname == user.key().name()):
return user
else:
logging.error('get_or_create user got current user %s and also keyname %s' %
(user.key().name(), user_keyname))
if not user_keyname:
logging.warning('using auto-generated keyname. This may cause issues...')
#raise ValueError('user keyname is required')
user_keyname = self.get_auto_keyname()
user_keyname = user_keyname.lower()
user_entity = User.get_by_key_name(user_keyname)
if not user_entity and '@' in user_keyname:
# try querying by email
user_entity = User.all().filter('email', user_keyname).get()
if user_entity:
logging.info('retrieved user with keyname %s' % user_keyname)
if admin or (password and user_entity.password == password):
# the user has just signed in
if old_user:
self.transfer_user_data(old_user, user_entity)
if set_user:
if '@hitype.com' not in user_entity.email:
deferred.defer(send_admin_email,
subject='User Login - %s' % user_entity.email, message='User Login - %s' % user_entity.email,
user=user_entity, user_agent=gae_utils.GetUserAgent(), ip=gae_utils.IPAddress(), url=gae_utils.GetUrl())
self.set_current_user(user_entity)
return user_entity
else:
logging.info('password %s did not match user %s password %s' % (
password, user_entity.key().name(), user_entity.password))
raise errors.PasswordError
else:
# user doesn't exist
if create_user:
new_user = self.create_new_user(user_keyname, password, set_user=set_user, **kwargs)
if old_user:
self.transfer_user_data(old_user, new_user)
return new_user
else:
if '@' in user_keyname:
sub_user_entity = SubUser.all().filter('email', user_keyname).get()
if sub_user_entity:
logging.info('retrieved subuser with keyname %s' % user_keyname)
if not sub_user_entity.password:
sub_user_entity.password = password
sub_user_entity.status = 'accepted'
sub_user_entity.put()
if sub_user_entity.password == password:
# the subuser has just signed in
if set_user:
self.set_current_user(sub_user_entity.main_account)
return sub_user_entity.main_account
else:
logging.info('password %s did not match user %s password %s' % (
password, sub_user_entity.key().name(), sub_user_entity.password))
raise errors.PasswordError
raise errors.NoEntityError