本文整理汇总了Python中webapp2_extras.appengine.auth.models.User.all方法的典型用法代码示例。如果您正苦于以下问题:Python User.all方法的具体用法?Python User.all怎么用?Python User.all使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webapp2_extras.appengine.auth.models.User
的用法示例。
在下文中一共展示了User.all方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: removeApprovals
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import all [as 别名]
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: create_random_article_approvalsAction
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import all [as 别名]
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())
示例3: calculate_user_knowledgeAction
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import all [as 别名]
def calculate_user_knowledgeAction(self,nickname=None):
self.checkEnv()
if nickname:
user=User.all().filter("nickname =",nickname).get()
else:
user=None
KnowledgeLib.calculate_user_knowledge(user)
return DevView(DevModel())
示例4: create_random_article_commentsAction
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import all [as 别名]
def create_random_article_commentsAction(self):
import string
page=0
limit=100
articles=[1]
while articles:
#articles=ArticleModel.all().fetch(limit,page*limit)
articles=ArticleModel.all().filter("ihref =",'google-earnings-clipped-mobile-headwinds').fetch(limit,page*limit)
for article in articles:
logging.info("generating comments for article "+article.title)
existing_comments=[] # this is a lifo stack of the most recent 100 comments on the article
# every user will comment between 1 or 10 times on either the article or another users comment
upage=0
users=[1]
while users:
users=User.all().fetch(limit,upage*limit)
for user in users:
if not article.comment:
comment_text=''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(32))
#comment=Comments(parent_comment=None,text=comment_text,user=user,rank=0.0)
#comment.save()
comment=CommentsLib.saveComment(article.key().id(),comment_text,user=user)
article.comment=comment
article.save()
existing_comments.append(article.comment)
logging.info("creating parent comment "+str(comment))
numcomments=random.randint(1,10)
for c in range(1,numcomments):
# pick between commenting on the article and commenting on another users comment
target=random.randint(0,1)
if target==1:
parent=article.comment
else:
parent=random.choice(existing_comments)
#logging.info("parent=");
#logging.info(parent);
comment_text=''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(32))
comment=CommentsLib.saveComment(article.key().id(),comment_text,parent_id=parent.key().id(),user=user)
#comment=Comments(parent_comment=parent,text=comment_text,user=user,rank=0.0)
#comment.save()
existing_comments.append(comment);
if len(existing_comments) > 100:
# pop the oldest comment off the stack
existing_comments.pop(0)
logging.info("processing user page "+str(upage))
upage=upage+1
return None
logging.info("processing page "+str(page))
page=page+1
return DevView(DevModel())
示例5: delete_all_usersAction
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import all [as 别名]
def delete_all_usersAction(self):
self.checkEnv()
page=0
limit=100
records=[1]
while records:
records=User.all().fetch(limit,page*limit)
for record in records:
record.delete()
logging.info("deleted "+str(page*limit)+" records")
page=page+1
return DevView(DevModel())
示例6: create_random_user_answersAction
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import all [as 别名]
def create_random_user_answersAction(self,nickname=None):
# get list of all categories for all articles
page=0
limit=100
articlecategories=[1]
categories = {}
while articlecategories:
articlecategories=ArticleCategoryModel.all().fetch(limit, page*limit);
for articlecategory in articlecategories:
if not categories.has_key(articlecategory.category.name):
categories[articlecategory.category.name]=articlecategory.category
logging.info("page: "+str(page))
page=page+1
model=DevModel()
model.messages=["found "+str(len(categories))+" distinct categories "]
now=time.time()
total_records=0
users=[1]
upage=0
while users:
users=User.all().fetch(100,upage*limit)
upage=upage+1
for user in users:
logging.info("processing user "+user.nickname)
# for each category get 10 questions
for tag,category in categories.items():
questions=QuestionModel.all().filter("cats in",[category.key()]).fetch(10,0)
for question in questions:
if random.randint(0,1)==1:
iscorrect=True
else:
iscorrect=False
t1=now-random.randint(0,(86400*365))
updated=datetime.datetime.utcfromtimestamp(t1)
topa=datetime.datetime.utcfromtimestamp(t1-random.randint(0,86400*30))
delay=random.randint(1,360000)
useranswer=UserAnswerModel(question=question,iscorrect=iscorrect,user=user,updated=updated,topa=topa,delay=delay)
useranswer.save()
total_records=total_records+1
message="created "+str(total_records)+" answers"
model.messages.append(message)
logging.info(message)
return DevView(model)
示例7: attach_random_user_to_articlesAction
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import all [as 别名]
def attach_random_user_to_articlesAction(self):
model=DevModel()
page=0
upage=0
limit=100
records=[0]
total_records=0
while records:
records=ArticleModel.all().fetch(limit,page*limit)
users=User.all().fetch(limit,upage*limit)
if len(users)< len(records) and upage>0:
upage=0
else:
upage=upage+1
page=page+1
i=0;
for record in records:
record.user=users[i].nickname
record.save()
total_records=total_records+1
i=i+1
return DevView(model)
示例8: submit_fake_articlesAction
# 需要导入模块: from webapp2_extras.appengine.auth.models import User [as 别名]
# 或者: from webapp2_extras.appengine.auth.models.User import all [as 别名]
def submit_fake_articlesAction(self):
self.checkEnv()
import string
from datetime import timedelta
#delete all article categories
limit=500
page=0
records=[1]
while records:
records=ArticleCategoryModel.all().fetch(limit,page*limit)
for record in records:
record.delete()
page=page+1
# delete all articles
page=0
articles=[1]
while articles:
articles=ArticleModel.all().fetch(limit,page*limit)
for article in articles:
article.delete()
page=page+1
# get list of all possible categories
catmodels=CategoryModel.all().fetch(100,0)
numcats=len(catmodels)
cats=[]
for cat in catmodels:
cats.append(cat.key())
#have each user create a fake article
today=datetime.datetime.today()
limit=10
users=[1]
while users:
users=User.all().fetch(limit,page*limit)
logging.info("processing "+str(page*limit)+ " records")
page=page+1
for user in users:
article=ArticleModel(title=''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(32)),ihref=''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(32)))
article.subtitle=''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(32))
article.description=''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(64))
article.href='http://'+''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(32))
article.user=user
days=timedelta(days=random.randint(1,30))
article.updated=today-days # a random date between now and 1 month ago
article.save()
randcats=random.sample(catmodels,random.randint(1,4))
for randcat in randcats:
#article_cat=ArticleCategoryModel(article=article,category=randcat)
#article_cat=ArticleCategoryModel(article=article)
article_cat=ArticleCategoryModel(article=article,category=randcat)
article_cat.catscore=(0.0+random.randint(1,100) ) / 100.0
userknowledges=UserKnowledgeModel.all().filter("user =",user).filter("category =",randcat).fetch(100,0)
if len(userknowledges) == 1:
article_cat.usercategoryscore=userknowledges[0].score
article_cat.updated=article_cat.article.updated
article_cat.sortkey=(article_cat.catscore*100)+(userknowledges[0].score/100) #TODO: tweak this
article_cat.save()
return DevView(DevModel())