本文整理汇总了Python中models.Member.all方法的典型用法代码示例。如果您正苦于以下问题:Python Member.all方法的具体用法?Python Member.all怎么用?Python Member.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Member
的用法示例。
在下文中一共展示了Member.all方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testLimitOffset
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import all [as 别名]
def testLimitOffset(self):
team = Team.create(name="Houkago Tea Time")
for name in self.names:
team.members.append(first_name=name[0], last_name=name[1], part=name[2], age=name[3])
# OFFSET 2
qs = Member.all().offset(2).order_by("id")
self.assertEqual(qs[0].first_name, "Yui")
self.assertEqual(qs[1].first_name, "Tsumugi")
self.assertEqual(qs.count(), 3)
# LIMIT 1 OFFSET 2
qs = Member.all().offset(2).limit(1).order_by("id")
self.assertEqual(qs[0].first_name, "Yui")
self.assertEqual(qs.count(), 1)
示例2: get
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import all [as 别名]
def get(self, key):
edit = self.request.get('edit')
template_dict = {'key': key, 'show_form' : True,'members': Member.all(),
'edit':edit,'thing' : self.thing_descriptors.get(edit),'images':Image.all().filter('name != ', "no-name") }
if key == 'new':
template_dict['form_data'] = {
'author': Member.get_current_member().handle,
'date': unicode(datetime.date.today())}
else:
try:
if(edit=='news'):
thing = NewsArticleNew.get(Key(key))
form_data={'title':thing.title,'author':thing.author,'date':unicode(thing.date),'body':thing.body,'picture':thing.picture}
elif(edit=='talk'):
thing = TalkNew.get(Key(key))
form_data={'title':thing.title,'author':thing.author,'date':unicode(thing.date),'body':thing.body,'video':thing.video}
elif(edit=='hack'):
thing = Hack.get(Key(key))
form_data={'title':thing.title,'date':unicode(thing.date),'body':thing.body,'picture':thing.picture}
template_dict['form_data']=form_data
except BadKeyError:
template_dict['message'] = \
'Could not find %s with key %r.' % (self.thing_descriptors.get(edit), key)
template_dict['show_form'] = False
self.render_template('edit', template_dict)
示例3: get
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import all [as 别名]
def get(self):
members = list(Member.all())
if members:
members.sort(key=lambda member:(member.score, member.handle))
rank = 0
ranked_members = [(rank, members[-1])]
for i in range(len(members) - 2, -1, -1):
if members[i + 1].score != members[i].score:
rank += 1
ranked_members.append((rank, members[i]))
else:
ranked_members = []
self.render_template('members', {
'members': ranked_members
})
示例4: testManyToManyOperation
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import all [as 别名]
def testManyToManyOperation(self):
team = Team.create(name="Houkago Tea Time")
for name in self.names:
team.members.append(first_name=name[0], last_name=name[1], part=name[2], age=name[3])
song1 = Song.create(name="Utauyo!! MIRACLE")
song2 = Song.create(name="Tenshi ni Fureta yo!")
for m in Member.all(): song1.members.append(m)
for m in Member.select(age=17): song2.members.append(m)
members = song1.members
self.assertEqual(members.count(), 5)
members = song2.members
self.assertEqual(members.count(), 4)
azusa = Member.get(first_name="Azusa")
songs = azusa.songs
self.assertEqual(songs.count(), 1)
self.assertEqual(songs[0].name, "Utauyo!! MIRACLE")
示例5: post
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import all [as 别名]
def post(self, key):
post = self.request.POST
edit = self.request.get('kind')
form_data = dict((k, post.get(k, ''))
for k in ('title', 'author', 'date', 'body', 'picture','video'))
template_dict = {'form_data': form_data, 'key': key, 'show_form' : True,'members': Member.all(),
'edit':edit,'thing' : self.thing_descriptors.get(edit),'images':Image.all().filter('name != ', "no-name")}
try:
this_date = utils.parse_date(form_data['date'])
except ValueError:
template_dict['message'] = \
'Date is not in the correct format (YYYY-MM-DD).'
else:
if key == 'new':
try:
if(edit=="news"):
thing = NewsArticleNew(
title=post['title'],
author=Member.get_by_id(int(post['author'])),
date=this_date,
body=post['body']
)
elif(edit=="talk"):
thing = TalkNew(
title=post['title'],
author=Member.get_by_id(int(post['author'])),
date=this_date,
body=post['body']
)
if('video' in post):
talk.video = post['video']
elif(edit=="hack"):
thing = Hack(
title=post['title'],
date=this_date,
body=post['body']
)
if(edit=="news" or edit=="hack"):
if(self.request.get("picture")):
pictureImage = Image(
picture=images.resize(self.request.get("picture"), self.image_height, self.image_width),
name="no-name",title=" ",alt=" ")
if post['picture_title'] :
pictureImage.title=post['picture_title']
if post['picture_alt'] :
pictureImage.alt=post['picture_alt']
pictureImage.put()
thing.picture=pictureImage
elif(post['picture_alias']!="none"):
thing.picture=Image.get_by_id(int(post['picture_alias']))
thing.put()
template_dict['key']=thing.key
except datastore_errors.Error:
template_dict['message'] = \
'Could not create new %s.' % self.thing_descriptors.get(edit)
else:
template_dict['message'] = '%s created.' % self.thing_descriptors.get(edit)
template_dict['show_form'] = False
else:
try:
if(edit=="news"):
thing = NewsArticleNew.get(Key(key))
thing.title = form_data['title']
thing.author = Member.get_by_id(int(post['author']))
thing.date = this_date
thing.body = form_data['body']
elif(edit=="talk"):
thing = TalkNew.get(Key(key))
thing.title = form_data['title']
thing.date = this_date
thing.body = form_data['body']
elif(edit=="hack"):
thing = Hack.get(Key(key))
thing.title = form_data['title']
thing.date = this_date
thing.body = form_data['body']
if(self.request.get("picture")):
pictureImage = Image(picture=images.resize(self.request.get("picture"), self.image_height, self.image_width),
name="no-name",title=" ",alt=" ")
if post['picture_title'] :
pictureImage.title=post['picture_title']
if post['picture_alt'] :
pictureImage.alt=post['picture_alt']
pictureImage.put()
thing.picture = pictureImage
elif(post['picture_alias']!="none"):
thing.picture=Image.get_by_id(int(post['picture_alias']))
if 'delete_picture' in post:
thing.picture=None
except BadKeyError:
#.........这里部分代码省略.........
示例6: testCRUDObject
# 需要导入模块: from models import Member [as 别名]
# 或者: from models.Member import all [as 别名]
def testCRUDObject(self):
# Test for creating, reading, updating, deleteing
# Create team
name = "Houkago Tea Time"
team = Team.create(name=name)
self.assertEqual(str(team), "<Team '%s'>" % name)
self.assertEqual(team.id, 1)
# Create members
for idx, n in enumerate(self.names):
member = Member.create(band=team, first_name=n[0], last_name=n[1], part=n[2])
self.assertEqual(str(member), "<Member '%s'>" % n[3])
self.assertEqual(member.id, idx + 1)
# Get member with primary key
ritsu = Member.get(1)
self.assertEqual(str(ritsu), "<Member 'Ritsu Tainaka : Dr'>")
# Get team the member Ritsu belongs to is Houkago Tea Time
team = ritsu.band
self.assertEqual(str(team), "<Team 'Houkago Tea Time'>")
# Get members with iterator
for idx, m in enumerate(team.members):
self.assertEqual(str(m), "<Member '%s'>" % self.names[idx][3])
# Yui changes instrument to castanets
macaron.bake() # Commit before changes
yui = Member.get(first_name="Yui", last_name="Hirasawa")
self.assert_(yui)
yui.part = "Castanets"
self.assertEqual(yui.part, "Castanets")
yui.save()
# Re-fetch Yui
member = Member.get(3)
self.assertEqual(member.part, "Castanets")
# Delete all members
self.assertEqual(team.members.count(), 4)
team.members.select(first_name="Ritsu").delete()
self.assertEqual(team.members.count(), 3)
team.members.delete()
self.assertEqual(team.members.count(), 0)
# Test for rollback
# Cancel the changes
macaron.rollback()
team = Team.get(1)
self.assertEqual(team.members.count(), 4)
# Add another member 'Sawako' as Gt1
member = Member.create(band=team, first_name="Sawako", last_name="Yamanaka", part="Gt1")
self.assertEqual(str(member), "<Member 'Sawako Yamanaka : Gt1'>")
# Re-fetch Sawako with index
sawako = team.members[4]
self.assertEqual(str(sawako), "<Member 'Sawako Yamanaka : Gt1'>")
# But, Sawako is not a member of the team
sawako.delete()
# Add another member Azusa through reverse relation of ManyToOne
team.members.append(first_name="Azusa", last_name="Nakano", part="Gt2")
azu = Member.get(first_name="Azusa")
self.assertEqual(str(azu), "<Member 'Azusa Nakano : Gt2'>")
# Okay, Yui changes part to Gt1
yui = Member.get(first_name="Yui")
yui.part = "Gt1"
yui.save()
self.assertEqual(yui.part, "Gt1")
# At last, there are five menbers
nm = self.names[:]
nm[2] = ("Yui", "Hirasawa", "Gt1", "Yui Hirasawa : Gt1")
nm.append(("Azusa", "Nakano", "Gt2", "Azusa Nakano : Gt2"))
for idx, m in enumerate(team.members):
self.assertEqual(str(m), "<Member '%s'>" % nm[idx][3])
# Foreign key constraint works on sqlite3 >= 3.6.19
ver = macaron.sqlite_version_info
if ver >= (3, 6, 19):
# Test for ON CASCADE
team = Team.get(1)
team.id = 2
team.save()
cnt = 0
for member in Member.all():
cnt += 1
self.assertEqual(member.band_id, 2)
self.assertEqual(cnt, Member.all().count())
# Test for ON DELETE
team.delete()
cnt = 0
for member in Member.all():
self.assertEqual(member.band, None)
cnt += 1
self.assertEqual(cnt, Member.all().count())
#.........这里部分代码省略.........