本文整理汇总了Python中models.User.all方法的典型用法代码示例。如果您正苦于以下问题:Python User.all方法的具体用法?Python User.all怎么用?Python User.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def get(self):
user = users.get_current_user()
if user:
subscriptions = CompanySubscription.all()
logoutUrl = users.create_logout_url("/")
appUser = User.all()\
.filter('openid =', user.federated_identity()).get()
if appUser == None:
appUser = User.all()\
.filter('email =', user.email()).get()
if appUser:
sub = appUser.subscription
appUsers = User.all().filter('subscription = ', sub)
template_values = { 'appUser' : appUser, \
'companyName' : sub.name, \
'edition' : sub.edition, \
'appUsers' : appUsers, \
'logoutUrl' : logoutUrl }
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
else:
# Send the user to AppDirect to purchase the app
self.redirect(appDirectLink)
else:
# Log this user in
self.redirect(users.create_login_url("https://www.appdirect.com/openid/id"))
示例2: test_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def test_user(self):
self.assertEqual(0, User.all().count())
self.assertEqual(None, User.get_current_user())
user = User.get_or_insert_current_user(self.handler)
self.assertEqual(self.current_user_id, user.key().name())
self.assert_entities_equal([User(key_name=self.current_user_id)], User.all())
示例3: get_by_username
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def get_by_username(self, username, keys_only=False):
if username == "" or username is None:
return None
username = username.lower()
if keys_only:
return User.all(keys_only=True).filter("username = ", username).get()
return User.all().filter("username = ", username).get()
示例4: get
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def get(self):
if len(self.request.params) == 0:
users_json = helpers.build_list_json(User.all())
# Set the response content type and dump the json
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(simplejson.dumps(users_json))
else:
users_json = []
if len(self.request.params) == 2:
user = self.request.params['loginName']
password = self.request.params['password']
q = db.GqlQuery("SELECT * FROM User WHERE loginName = %s" % user)
result = q.fetch(2)
if len(result) == 0:
users_json = []
else:
# This is really crappy, it works for now, but I'm not proud of it...
if len(password.strip().replace("\'","")) == 0 or password == None:
password = "'None'"
if "'%s'" % result[0].password == password or (len(result[0].password) == 0 and password == "'None'"):
result[0].authToken = helpers.generateAuthToken()
result[0].put()
users_json = helpers.build_list_json(User.all())
else:
users_json = []
else:
users_json = []
# Set the response content type and dump the json
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(simplejson.dumps(users_json))
示例5: setUp
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
# should all return None, because this is simply creating data and is all meant to be correct
self.assertIsNone(User.register(None, '[email protected]', 'pwd', 'pwd', 'teacher', 't'))
self.assertIsNone(User.register(None, '[email protected]', 'pwd', 'pwd', 'teachertwo', 'ttwo'))
self.assertIsNone(User.register(None, '[email protected]', 'pwd', 'pwd', 'student', 's'))
self.teacher = User.all().filter('email =', '[email protected]').get()
self.teacher2 = User.all().filter('email =', '[email protected]').get()
self.student = User.all().filter('email =', '[email protected]' ).get()
self.assertIsNotNone(self.teacher)
self.assertIsNone(self.teacher.make_teacher())
self.assertIsNotNone(self.teacher2)
self.assertIsNone(self.teacher2.make_teacher())
self.assertIsNone(Course.create(self.teacher, 'public', ''))
self.public = Course.all().filter('name =', 'Public').get()
self.assertIsNotNone(self.public)
self.assertIsNone(Course.create(self.teacher, 'private', 'on'))
self.private = Course.all().filter('name =', 'Private').get()
self.assertIsNotNone(self.private)
示例6: testUser
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def testUser(self):
User(user=self.current_user).put()
self.assertEqual(1, User.all().count(10))
User(user=self.current_user, locale='en', theme='classic').put()
self.assertEqual(2, User.all().count(10))
with self.assertRaises(datastore_errors.BadValueError):
User().put()
self.assertEqual(2, User.all().count(10))
示例7: get
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def get(self):
# inequality issues
User.all().filter('last_name !=', 'fry').filter('date_created <', datetime.now())
User.all().filter('last_name !=', 'fry').order('-date_created')
# things you'd expect to exist
User.all().filter('last_name =', 'fry').exists()
User.all().average('age')
# i don't understand why this works this way
User.all().fetch(limit=10, offset=1000000) # Takes forever.
示例8: render
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def render(self, users, title='', style=''):
if isinstance(users, list):
users = User.all({'username': {"$in": users}})
return self.render_string('modules/users-thumbs',
users=users,
title=title,
style=style)
示例9: get
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def get(self, username):
user = User.all().filter('name =', username).get()
if user is None:
self.render('templates/user.html', {'error': 'User %s does not exist.' % username})
return
self.render('templates/user.html', {'user': user})
示例10: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def post(self):
session = get_current_session()
email = helper.sanitizeHtml(self.request.get('email'))
if len(email) > 1:
users = User.all().filter("email =", email).fetch(1)
if len(users) == 1:
if session.is_active():
session.terminate()
user = users[0]
Ticket.deactivate_others(user)
ticket = Ticket(user=user,code=Ticket.create_code(user.password + user.nickname + str(random.random())))
ticket.put()
code = ticket.code
host = self.request.url.replace(self.request.path,'',1)
sender = "Santiago Zavala - Fogata.co <[email protected]>"
logging.info("sender = " + sender )
mail.send_mail(sender=sender,
to=user.nickname + "<"+user.email+">",
subject="Liga para restablecer password",
html=template.render('templates/mail/forgotten-password-email.html', locals()),
body=template.render('templates/mail/forgotten-password-email-plain.html', locals()))
session['forgotten_password_ok'] = "Se ha enviado un correo electrónico a tu bandeja de entrada con las instrucciones"
else:
session['forgotten_password_error'] = "El correo electronico <strong>"+ email +"</strong> no existe en nuestra base de datos"
else:
session['forgotten_password_error'] = "Debes especificar tu correo electrónico"
self.redirect('/olvide-el-password')
示例11: get
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def get(self):
new_user = User(username='Aswad', email='[email protected]', identifier='Google')
#new_user.put()
new_person = Person(
first_name = 'Aswad',
last_name = 'Rangnekar',
#user = new_user
)
#new_person.put()
#new_phone1 = PersonPhone(number='9960815827', person=new_person).put()
#new_phone2 = PersonPhone(number='26652590', person=new_person).put()
#getting total, approved and deleted users
TOTAL_USER = User.all()
APPROVED_USER = db.GqlQuery("SELECT * FROM User WHERE is_active=True AND is_deleted = False")
DELETED_USER = db.GqlQuery("SELECT * FROM User WHERE is_active=False AND is_deleted = True")
self.render('adminusers.html',
user_count= TOTAL_USER.count(),
approved_user_count= APPROVED_USER.count(),
deleted_user_count= DELETED_USER.count(),
total_user = TOTAL_USER,
approved_user = APPROVED_USER,
deleted_user = DELETED_USER,
mils_year_list= MILS_YEAR_LIST,
gender_choices = GENDER_CHOICES,
t_shirt_sizes = T_SHIRT_SIZES_TUPLE_MAP,
page_name='users',
login_url='/login',
)
示例12: session_from_facebook
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def session_from_facebook():
"""
uses the facebook session cookie to create a site specific session.
it will also fetch profile information from facebook and add
the user to the datastore if it does not exist yet
"""
import facebook
# get facebook user id and token from facebook cookie
fb_user = facebook.get_user_from_cookie(request.cookies,
app.config['FACEBOOK_APPLICATION_ID'],
app.config['FACEBOOK_APPLICATION_SECRET'])
if fb_user:
# check whether the user is already in the datastoreg
user = User.all().filter('facebook_id =', str(fb_user['uid'])).get()
if user is None:
# if not we fetch his profile information via the facebook graph api
graph = facebook.GraphAPI(fb_user["access_token"])
profile = graph.get_object("me")
# now we can put the user in the datastore
user = User(key_name=generate_key(),
facebook_id=str(profile['id']),
facebook_token=request.values.get('access_token'),
email=profile['email'],
name=profile['name'])
user.save()
# last but not least we add the user's key to the session cookie
session['user_key'] = user.key().name()
return "ok"
示例13: post
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def post(self):
### Session verification code ###
session = get_current_session()
try:
if not session['key'] or session['key'] == '':
self.redirect('/?exception=NoSession')
except KeyError:
self.redirect('/?exception=NoSession')
#################################
receipient = self.request.get('receipient')
title = self.request.get('title')
body = self.request.get('body')
for receipients in User.all().filter("nick =", receipient).run(limit=1):
receipient_key = str(receipients.key())
try:
newmessage = Message()
newmessage.receipient = receipient_key
newmessage.sender = session['key']
newmessage.title = title
newmessage.body = body
newmessage.status = 0
newmessage.put()
self.redirect('/messages')
except UnboundLocalError:
self.redirect('/messages?exception=ReceipientNotFound')
except AttributeError:
self.redirect('/messages?exception=SenderNotFound')
示例14: get
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def get(self, user):
page = helper.sanitizeHtml(self.request.get('pagina'))
target_user_str= helper.sanitizeHtml(helper.parse_post_id(user))
perPage = 20
page = int(page) if page else 1
realPage = page - 1
if realPage > 0:
prevPage = realPage
session = get_current_session()
if session.has_key('user'):
user = session['user']
target_user = User.all().filter('lowercase_nickname =', target_user_str).fetch(1)
if len(target_user) > 0:
posts = Post.all().filter('user =',target_user[0]).order('-created').fetch(perPage,perPage * realPage)
if (page * perPage) < Post.all().filter('user =',target_user[0]).order('-created').count():
nextPage = page + 1
prefetch.prefetch_posts_list(posts)
i = perPage * realPage + 1
for post in posts:
post.number = i
i = i + 1
if helper.is_json(self.request.url):
posts_json = [p.to_json() for p in posts]
if(self.request.get('callback')):
self.response.headers['Content-Type'] = "application/javascript"
self.response.out.write(self.request.get('callback')+'('+simplejson.dumps({'posts':posts_json})+');')
else:
self.response.headers['Content-Type'] = "application/json"
self.response.out.write(simplejson.dumps({'posts':posts_json}))
else:
self.response.out.write(template.render('templates/main.html', locals()))
else:
self.redirect('/')
示例15: data
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import all [as 别名]
def data(**kwargs):
'''Makes sure that certain pieces of information are always sent to
the template engine along with the information supplied by the
different handlers.
'''
data = {
'site': web.ctx.homedomain,
'user': {},
}
data.update(kwargs)
user = users.get_current_user()
if user:
data['log_in_out'] = users.create_logout_url('/')
data['logged_in'] = True
data['user']['id'] = user.user_id()
try:
nickname = mget(key=user.user_id(), namespace='usernames')
if nickname is None:
q = User.all().filter('id', user.user_id()).fetch(1)
nickname = q[0].nickname
if not mset(key=user.user_id(), value=nickname, time=10, namespace='usernames'):
logging.error('Could not set memcache value!')
data['user']['nickname'] = nickname
except:
data['user']['nickname'] = user.nickname()
try:
data['gravatar'] = get_gravatar(get_user(user_id=data['user_id'] or 'us').user.email())
except KeyError:
data['gravatar'] = get_gravatar('us')
else:
data['log_in_out'] = users.create_login_url('/')
data['gravatar'] = get_gravatar('[email protected]')
return data