本文整理汇总了Python中auth.models.User.all方法的典型用法代码示例。如果您正苦于以下问题:Python User.all方法的具体用法?Python User.all怎么用?Python User.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类auth.models.User
的用法示例。
在下文中一共展示了User.all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sync_existing_without_id
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def test_sync_existing_without_id(self):
us = User(email=self.user['email'])
us.put()
self.sync()
us = User.all().filter('__key__ =', us.key()).fetch(1)[0]
eq_(us.first_name, self.user['name_first'])
eq_(us.last_name, self.user['name_last'])
eq_(us.email, self.user['email'])
eq_(us.dj_name, self.user['nick'])
eq_(us.external_id, self.user['member_id'])
eq_(us.is_superuser, False)
eq_(us.is_active, True)
eq_(us.roles, [roles.DJ])
eq_(User.all().filter('email =', self.user['email']).count(2), 1)
示例2: test_user_edit_form_change_password
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def test_user_edit_form_change_password(self):
steve = User(
email='[email protected]',
first_name='Steve',
last_name='Dolfin',
dj_name='DJ Steve',
roles=['dj'],
is_active=True,
password='123456'
)
steve.save()
resp = self.client.post('/auth/edit_user/', {
'original_email': '[email protected]', # this is the key
'email': '[email protected]',
'first_name': 'Steve',
'last_name': 'Dolfin',
'dj_name': 'DJ Seteve',
'is_active': 'checked',
'is_dj': 'checked',
# new password
'password': '1234567'
})
self.assertNoFormErrors(resp)
user = User.all().filter('email =', '[email protected]').fetch(1)[0]
# password was changed:
self.assertEqual(user.check_password('1234567'), True)
示例3: test_user_edit_form
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def test_user_edit_form(self):
steve = User(
email='[email protected]',
first_name='Steve',
last_name='Dolfin',
dj_name='DJ Steve',
roles=['dj'],
is_active=True,
password='123456' # pretend this is encrypted
)
steve.save()
resp = self.client.post('/auth/edit_user/', {
'original_email': '[email protected]', # this is the key
'email': '[email protected]',
'first_name': 'Steven',
'last_name': 'Dolfin III',
'dj_name': 'Steve Holt!',
'is_active': 'checked',
# change roles:
'is_volunteer_coordinator': 'checked'
})
self.assertNoFormErrors(resp)
user = User.all().filter('email =', '[email protected]').fetch(1)[0]
self.assertEqual(user.first_name, 'Steven')
self.assertEqual(user.last_name, 'Dolfin III')
self.assertEqual(user.dj_name, 'Steve Holt!')
self.assertEqual(user.roles, ['volunteer_coordinator'])
self.assertEqual(user.password, '123456') # should be untouched
示例4: clear_data
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def clear_data():
for pl in Playlist.all():
for track in PlaylistTrack.all().filter('playlist =', pl):
track.delete()
pl.delete()
for u in User.all():
u.delete()
示例5: test_sync_existing_with_dj_role
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def test_sync_existing_with_dj_role(self):
us = User(email=self.user['email'],
external_id=self.user['member_id'],
roles=[roles.DJ, roles.REVIEWER])
us.put()
self.sync()
us = User.all().filter('__key__ =', us.key()).fetch(1)[0]
eq_(set(us.roles), set((roles.DJ, roles.REVIEWER)))
示例6: index_users
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def index_users(request):
for user in User.all() :
_reindex(user)
user.save()
tmpl = loader.get_template('auth/main_page.html')
all_users = list(User.all().order('last_name').order('first_name'))
num_active_users = sum(u.is_active for u in all_users)
active = [u for u in all_users if u.is_active]
inactive = [u for u in all_users if not u.is_active]
ctx = RequestContext(request, {
'title': 'User Management',
'all_users': active + inactive,
'num_active_users': num_active_users,
'msg' : 'Users indexed.'
})
return http.HttpResponse(tmpl.render(ctx))
示例7: test_preserve_superuser
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def test_preserve_superuser(self):
us = User(email=self.user['email'],
external_id=self.user['member_id'],
is_superuser=True)
us.put()
self.sync()
us = User.all().filter('__key__ =', us.key()).fetch(1)[0]
eq_(us.is_superuser, True)
示例8: test_deactivate
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def test_deactivate(self):
us = User(email='[email protected]', external_id=23)
us.put()
resp = self.client.post(self.url, {'external_id': 23})
eq_(resp.status_code, 200)
us = User.all().filter('__key__ =', us.key()).fetch(1)[0]
eq_(us.is_active, False)
示例9: sync_user
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def sync_user(request):
user = request.POST.get('user')
if not user:
return http.HttpResponseBadRequest()
user = json.loads(user)
qs = User.all().filter('external_id =', user['member_id'])
users = qs.fetch(1)
dj_user = None
if len(users):
dj_user = users[0]
else:
# No previously sync'd user exists.
# Let's check by email to see if an old
# user exists with the same email.
qs = User.all().filter('email =', user['email'])
if qs.count(2) == 2:
raise LookupError('More than one user for %s; '
'aborting sync' % user['email'])
users = qs.fetch(1)
if len(users):
log.info('Linking user %s to ID %s' %
(user['email'], user['member_id']))
dj_user = users[0]
fields = {
'first_name': user['name_first'],
'last_name': user['name_last'],
'email': user['email'],
'dj_name': user['nick'],
'external_id': user['member_id'],
'is_active': True,
}
if not dj_user:
fields['roles'] = [roles.DJ]
dj_user = User(**fields)
else:
for k, v in fields.items():
setattr(dj_user, k, v)
if roles.DJ not in dj_user.roles:
dj_user.roles.append(roles.DJ)
_reindex(dj_user)
dj_user.put()
return http.HttpResponse('OK')
示例10: test_sync_new
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def test_sync_new(self):
self.sync()
us = User.all()[0]
eq_(us.first_name, self.user['name_first'])
eq_(us.last_name, self.user['name_last'])
eq_(us.email, self.user['email'])
eq_(us.dj_name, self.user['nick'])
eq_(us.external_id, self.user['member_id'])
eq_(us.is_superuser, False)
eq_(us.is_active, True)
eq_(us.roles, [roles.DJ])
assert us.index, 'User was not indexed'
示例11: authenticate
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def authenticate(self, username=None, password=None):
if not (username and password):
return False
u = User.all()\
.filter("username =", username)\
.filter("password =", hash_password(password))
try:
return u.fetch(1)[0]
except IndexError:
return None
示例12: test_create_user_with_initial_password
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def test_create_user_with_initial_password(self):
resp = self.client.post('/auth/add_user/', {
'email': '[email protected]',
'first_name': 'Bob',
'last_name': 'Jones',
'dj_name': 'Dr. Jones',
'password': "my-initial-password",
'is_dj': 'checked'
})
self.assertNoFormErrors(resp)
user = User.all().filter('email =', '[email protected]').fetch(1)[0]
# password was set:
self.assertEqual(user.check_password('my-initial-password'), True)
示例13: test_email_is_case_insensitive_on_creation
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def test_email_is_case_insensitive_on_creation(self):
resp = self.client.post('/auth/add_user/', {
'email': '[email protected]',
'first_name': 'Steve',
'last_name': 'Dolfin',
'dj_name': 'DJ Steve',
'is_dj': 'checked'
})
self.assertNoFormErrors(resp)
u = User.all().filter('last_name =', 'Dolfin').fetch(1)[0]
self.assertEqual(u.email, '[email protected]')
self.assertEqual(u.dj_name, 'DJ Steve')
self.assertEqual(u.roles, ['dj'])
self.assertEqual(u.password, None) # password prompt was emailed to user
示例14: user_search_for_autocomplete
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def user_search_for_autocomplete(request):
match_users = []
response = http.HttpResponse(mimetype="text/plain")
terms = [term for term in search.scrub(request.GET.get('q', '')).split()]
for term in terms:
query = User.all()
query.filter("is_active =", True).filter("index =", term)
users = AutoRetry(query).fetch(999)
if (len(users) > 0):
for user in users:
match_users.append(user)
break
for user in match_users :
response.write("%s|%s\n" % (user, user.key()))
if user.dj_name is not None:
response.write("%s|%s\n" % (user.dj_name, user.key()))
return response
示例15: main_page
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import all [as 别名]
def main_page(request):
tmpl = loader.get_template('auth/main_page.html')
all_users = list(User.all().order('last_name').order('first_name'))
msg = ''
"""Send password reset emails to selected users."""
if request.method == 'POST' :
if request.POST.get('SendPwdEmails') :
num_emails = 0;
for i, user in enumerate(all_users) :
if request.POST.get('checkbox_%d' % (i + 1)) :
num_emails += 1
# Assemble the URL that can be used to access the password
# reset form.
token = auth.get_password_reset_token(user)
url = 'http://%s/auth/reset_password?token=%s' % (
os.environ['HTTP_HOST'], token)
logging.warn('Sent password recovery URL: %s', url)
# Send the email message.
msg_tmpl = loader.get_template('auth/reset_password_email.txt')
msg_ctx = Context({'user': user, 'url': url})
msg_body = msg_tmpl.render(msg_ctx)
# print msg_body
email.send_to_user(
user,
subject='Please Set/Reset your CHIRP password',
body=msg_body)
if num_emails :
msg = 'Email(s) sent.'
"""Lists all users."""
num_active_users = sum(u.is_active for u in AutoRetry(all_users))
active = [u for u in AutoRetry(all_users) if u.is_active]
inactive = [u for u in AutoRetry(all_users) if not u.is_active]
ctx = RequestContext(request, {
'title': 'User Management',
'all_users': active + inactive,
'num_active_users': num_active_users,
'msg' : msg
})
return http.HttpResponse(tmpl.render(ctx))