本文整理汇总了Python中webapp2_extras.appengine.auth.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: removeApprovals
def removeApprovals(article,user1=None):
page=0;limit=100
if user1:
users=[user1]
else:# if no user specified, then apply all users
users=User.all().fetch(limit,page*limit)
while users:
for user in users:
approvals=ArticleLib.getApprovals(article, user)
if approvals:
logging.info("TODO: lock the ArticleCategory records for update")
article_cats=ArticleLib.getCategories(article)
if article_cats:
for article_cat in article_cats:
if approvals.has_key(article_cat.category):
article_cat.r2=article_cat.r2-(approvals[article_cat.category].score/100)
else:
article_cat.r2=article_cat.r2-(0.01/100)
article_cat.save()
page=page+1
if not user1:
users=User.all().fetch(limit,page*limit)
return None
示例2: post
def post(self):
self.response.headers["Content-Type"] = "application/json"
email = self.request.get("email")
password = self.request.get("password")
try:
user = User.get_by_auth_password(email, password)
except:
self.response.write(resp.fail_pass())
return
if not user:
self.response.write(resp.fail_pass())
else:
token = User.create_auth_token(user.key.id())
self.response.write(
resp.success(
{
"Token": token,
"User": {
"firstname": user.firstname,
"lastname": user.lastname,
"email": user.auth_ids[0],
"id": user.key.id(),
},
}
)
)
示例3: post
def post(self):
self.response.headers['Content-Type'] = 'application/json'
firstname = self.request.get('firstname')
lastname = self.request.get('lastname')
email = self.request.get('email')
password = self.request.get('password')
work, info = User.create_user(
email,
firstname=firstname,
lastname=lastname,
password_raw=password
)
if not work:
self.response.write(resp.fail(
'email',
'Email address already exists'
))
else:
user = info
token = User.create_auth_token(user.key.id())
self.response.write(resp.success({
'Token' : token,
'User' : {
'firstname' : user.firstname,
'lastname' : user.lastname,
'email' : user.auth_ids[0],
'id' : user.key.id()
}
}))
示例4: set_emailAction
def set_emailAction(self,email):
if self.user:
current_email=self.user.getEmail()
if current_email!=email:
user=User().get_by_auth_id(self.user.username)
user.email_address=email
user.put()
model={"email":email}
return model
示例5: get
def get(self):
users = User.query().fetch()
tasklist_name = self.request.get('tasklist_name', DEFAULT_TASKLIST_NAME)
tasks_query = Task.query(ancestor=tasklist_key(tasklist_name)).order(-Task.date)
tasks = tasks_query.fetch()
self.render_template('authenticated.html', locals())
示例6: post
def post(self):
# set headers
self.response.headers.add_header('Content-Type', 'application/json')
form = LoginForm(formdata=webob.multidict.MultiDict(json.loads(self.request.body or '{}')))
form.validate()
if form.errors:
self.response.set_status(400)
self.response.write(json.dumps(form.errors))
else:
try:
User.get_by_auth_password(form.email.data, form.password.data)
self.session['user'] = form.email.data
self.response.write(json.dumps({'success': "Logged in"}))
except Exception:
self.response.set_status(400)
self.response.write(json.dumps({'error': "Login failed"}))
示例7: get_user_address
def get_user_address(self):
user = User.get_by_id(long(self.user_id)) if self.user_id != -1 else None
if user:
if user.address:
return user.address.address_from
else:
return ''
示例8: send_rfps_to_subscribers
def send_rfps_to_subscribers(self):
"""
As the function name implies, all subscribed users will receive an RFP update to their
email accounts. By comparing an RFP's parse date to a subscription's last update date,
we ensure dups aren't being sent out.
Returns a list of results based on what happened for each subscription.
"""
results = []
subs = Subscription.all()
for sub in subs:
try:
# Grab what user info, add first, last name later
user = User.query(query.FilterNode('username', '=', sub.username)).get()
# Ensure the the sub's username is associated with an actual account
# by checking if the email exists.
if user.email:
self._send_rfps_to_subscribers(sub, user.first_name, user.email, results)
else:
msg = 'No email found for username: %s and keyword: %s' % (sub.username, sub.keyword)
logging.info(msg)
results.append('Error: ' + msg)
except:
msg = 'Problem with sending RFPs for some subscription, maybe bad user object'
logging.info(msg)
results.append('Error: ' + msg)
return results
示例9: create_random_article_approvalsAction
def create_random_article_approvalsAction(self):
self.checkEnv()
all_articles=ArticleModel.all().fetch(100)
page=0
limit=100
users=[1]
while users:
logging.info("processing page "+str(page))
users=User.all().fetch(limit,page*limit)
for user in users:
logging.info("processing user: "+user.nickname)
articles=random.sample(all_articles,3)
for article in articles:
if article.user != user:
article_cats=ArticleCategoryModel.all().filter("article =",article).fetch(100)
approval_count=0
for article_cat in article_cats:
userknowledges=UserKnowledgeModel.all().filter("user =",user).filter("category =",article_cat.category).fetch(1)
article_approval=ArticleApproveModel.all().filter("user =",user).filter("category =",article_cat.category).get()
if not article_approval:
article_approval=ArticleApproveModel(user=user,article=article,category=article_cat.category,score=0.01)
if userknowledges:
article_approval.score=userknowledges[0].score
article_approval.save()
approval_count=1
if article_approval > 0:
article.numapprovals=article.numapprovals+1
article.save();
page=page+1
return DevView(DevModel())
示例10: set_vote
def set_vote(quote_id, user_id, newvote, provider):
if user_id is None:
return
if isinstance(user_id, unicode):
auth_id = '%s:%s' % (provider, user_id)
user = User.get_by_auth_id(auth_id)
else:
user = user_id
email = user.email
def txn():
quote = Post.get_by_id(quote_id)
vote = Vote.get_by_id(id=email, parent=quote.key)
if vote is None:
vote = Vote(id=email, parent=quote.key)
if vote.vote == newvote:
return
quote.votesum = quote.votesum - vote.vote + newvote
vote.vote = newvote
quote.rank = "%020d|%s" % (
long(quote.created * DAY_SCALE + quote.votesum),
quote.creation_order
)
quote.put()
vote.put()
memcache.set("vote|" + email + "|" + str(quote_id), vote.vote)
ndb.transaction(txn)
示例11: delete_orphaned_article_approvalsAction
def delete_orphaned_article_approvalsAction(self):
page=0
limit=100
records=[0]
num_deleted=0
total_records=0
while records:
records=ArticleApproveModel.all().fetch(limit,page*limit)
for record in records:
total_records=total_records+1
if not record.parent():
record.delete()
num_deleted=num_deleted+1
else:
category=CategoryModel.get(record.category.key())
if not category:
record.delete()
num_deleted=num_deleted+1
else:
user=User.get(record.user.key())
if not user:
record.delete()
num_deleted=num_deleted+1
page=page+1
return DevView(DevModel())
示例12: printUser
def printUser():
print "User List:"
print 100 * '#'
for user in User.query().fetch():
for name in user._properties:
print str(name) + ":" + str(getattr(user, name))
print 100 * '#'
示例13: add_quote
def add_quote(title1, user_id, user_anon, provider, quote1=None, url1=None, image=None, _created=None):
try:
now = datetime.datetime.now()
if isinstance(user_id, unicode):
auth_id = '%s:%s' % (provider, user_id)
user = User.get_by_auth_id(auth_id)
else:
user = user_id
unique_user = _unique_user(user)
if _created:
created = _created
else:
created = (now - datetime.datetime(2008, 10, 1)).days
q = Post(
title=title1,
quote=quote1,
created=created,
image=image,
creator_anonymous=user_anon,
creator=user.key,
creation_order=now.isoformat()[:19] + "|" + unique_user,
uri=url1
)
q.put()
add_search_index(q.key.id(), title1, quote1, url1, image, user, user_anon)
return q.key.id()
except db.Error:
return None
示例14: add_comment
def add_comment(user, user_anon, quote_id, text, provider):
try:
if user is None:
return
if isinstance(user, unicode):
auth_id = '%s:%s' % (provider, user)
user = User.get_by_auth_id(auth_id)
else:
user = user
quote = Post.get_by_id(long(quote_id))
comment = Comment(
parent=quote.key,
author_anonymous=user_anon,
author=user.key,
text=text
)
quote.comments += 1
quote.put()
comment.put()
memcache.set("comment|" + user.email + "|" + str(quote_id), comment.text)
except db.Error:
return None
示例15: get
def get(self, username, term, syllabus):
# Deal with possible trailing slash
if syllabus[-1] == '/':
syllabus = syllabus[:-1]
user = User.get_by_auth_id(username)
terms = user.terms
if terms:
for t in terms:
if t.url == term.upper():
syllabi = t.syllabi
for syl in syllabi:
if syl.info.url.lower() == syllabus.lower():
if not syl.isActive:
currentUser = None
if self.user:
currentUser = ndb.Key(User, self.user['user_id']).get()
if not currentUser or username not in currentUser.auth_ids:
self.abort(403)
self.render(t, syl)
return
# Raise HTTP 404 error for syllabi that don't exist
self.abort(404)