本文整理汇总了Python中models.Book.all方法的典型用法代码示例。如果您正苦于以下问题:Python Book.all方法的具体用法?Python Book.all怎么用?Python Book.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Book
的用法示例。
在下文中一共展示了Book.all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_book_update_via_service_put
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def test_book_update_via_service_put(self):
self.assertEquals(0, Book.all().count())
book = Book(
title = "test",
ident = "1",
author = "author",
notes = "",
image = "http://example.com/image.gif",
url = "http://example.com"
)
book.put()
self.assertEquals(1, Book.all().count())
json = """{
"ident": "1",
"title": "test update",
"author": "author",
"notes": "",
"image": "http://example.com/image.gif",
"url": "http://example.com"
}"""
response = self.app.put('/books/1', params=json, expect_errors=True)
self.assertEquals(1, Book.all().count())
response = self.app.get('/books/1', expect_errors=True)
self.assertEquals("200 OK", response.status)
try:
json = response.json
except AttributeError:
assert(False)
self.assertEqual(json['ident'], "1")
self.assertEqual(json['title'], "test update")
示例2: test_book_deletion_via_service
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def test_book_deletion_via_service(self):
self.assertEquals(0, Book.all().count())
book = Book(
title = "test",
ident = "1",
author = "author",
notes = "",
image = "http://example.com/image.gif",
url = "http://example.com"
)
book.put()
self.assertEquals(1, Book.all().count())
response = self.app.delete('/books/%s' % book.ident, expect_errors=True)
self.assertEquals(0, Book.all().count())
示例3: test_book_deletion
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def test_book_deletion(self):
self.assertEquals(0, Book.all().count())
book = Book(
title = "test",
ident = "1",
author = "author",
notes = "",
image = "http://example.com/image.gif",
url = "http://example.com"
)
book.put()
self.assertEquals(1, Book.all().count())
book.delete()
self.assertEquals(0, Book.all().count())
示例4: test_sending_email
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def test_sending_email(self):
self.assertEquals(0, Book.all().count())
book = Book(
title = "test",
ident = "1",
author = "author",
notes = "",
image = "http://example.com/image.gif",
url = "http://example.com"
)
book.put()
self.assertEquals(1, Book.all().count())
# TODO: needs assertion
_email_new_book(book)
示例5: test_books_views_return_correct_mime_type
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def test_books_views_return_correct_mime_type(self):
self.assertEquals(0, Book.all().count())
book = Book(
title = "test",
ident = "1",
author = "author",
notes = "",
image = "http://example.com/image.gif",
url = "http://example.com"
)
book.put()
self.assertEquals(1, Book.all().count())
response = self.app.get('/books/', expect_errors=True)
self.assertEquals(response.content_type, "application/json")
示例6: test_book_addition_via_service_post
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def test_book_addition_via_service_post(self):
json = """{
"ident": "1",
"title": "test",
"author": "author",
"notes": "",
"image": "http://example.com/image.gif",
"url": "http://example.com"
}"""
self.assertEquals(0, Book.all().count())
response = self.app.post('/books', params=json, expect_errors=True)
self.assertEquals(1, Book.all().count())
response = self.app.get('/books/1', expect_errors=True)
self.assertEquals("200 OK", response.status)
示例7: test_response_contents_from_books
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def test_response_contents_from_books(self):
self.assertEquals(0, Book.all().count())
book = Book(
title = "test",
ident = "1",
author = "author",
notes = "",
image = "http://example.com/image.gif",
url = "http://example.com"
)
book.put()
self.assertEquals(1, Book.all().count())
response = self.app.get('/books/', expect_errors=True)
response.mustcontain('"ident": "1"')
response.mustcontain('"title": "test"')
示例8: DeleteClass
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def DeleteClass(self, *args):
from google.appengine.ext import db
from models import Task, Class, Book, Chapter
from google.appengine.api import users
user = users.get_current_user()
classname = args[0].replace('%20', ' ')
#Deleting all Tasks for this Module
q = Task.all().filter('user ==',user).filter('classname ==',classname)
results = q.fetch(10)
for result in results:
result.delete()
#Deleting all the Scripts and Chapters from this Module
qq = Book.all().filter('user ==',user).filter('classname ==',classname)
books = qq.fetch(10)
for book in books:
qqq = Chapter.all().filter('book ==', book.title).filter('user ==',user)
for chapter in qqq:
chapter.delete()
book.delete()
#Deleting the Module itself
qqqq = Class.all().filter('user ==',user).filter('name ==',classname)
results = qqqq.fetch(10)
for result in results:
result.delete()
return self.RefreshClasses()
示例9: delete
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def delete(self, ident):
"Delete the book from the datastore"
# check we have the correct authentication ket
auth = self.request.get("auth")
if auth != settings.AUTH:
return self.error(401)
try:
# retrieve the book based on its ident value
book = Book.all().filter('ident =', ident)[0]
except IndexError:
# if we don't find a book then throw a Not Found error
return self.error(404)
logging.info("Update request for %s (%s)" % (book.title, ident))
try:
# delete the book
book.delete()
# we'e updated so we need to clear the cache
memcache.delete("ws_books")
except:
logging.error("Error occured deleting %s (%s)"
% (book.title, ident))
self.error(500)
示例10: get
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def get(self, ident):
"Show the JSON representation of the book"
# check we have the correct authentication ket
auth = self.request.get("auth")
if auth != settings.AUTH:
return self.error(401)
try:
# retrieve the book based on its ident value
book = Book.all().filter('ident =', ident)[0]
except IndexError:
# if we don't find a book then throw a Not Found error
return self.error(404)
# create the datastructure we will convert to JSON
book_for_output = {
"title": book.title,
"ident": book.ident,
"author": book.author,
"image": book.image,
"notes": book.notes,
"url": book.url,
"key": str(book.key())
}
# create the JSON object
json = simplejson.dumps(book_for_output, sort_keys=False, indent=4)
# serve the response with the correct content type
self.response.headers['Content-Type'] = 'application/json'
logging.info("Request for %s (%s)" % (book.title, book.ident))
# write the json to the response
self.response.out.write(json)
示例11: get
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def get(self, book_slug = None):
if not book_slug:
books = Book.all()
self.render_template(self.BOOKS_TEMPLATE,{'books': books})
else:
book = self.get_object_by_key_or_404(Book, book_slug)
self.render_template(self.BOOK_TEMPLATE,{'book': book})
示例12: search
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def search(request):
if 'q' in request.GET and request.GET['q']:
q = request.GET['q']
books = Book.all()
return render_to_response('search_results.html',
{'books': books, 'query': q})
else:
return HttpResponse('Please submit a search term.')
示例13: get
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def get(self):
books = Book.all();
template_values = {
'books' : books,
}
path = os.path.join(os.path.dirname(__file__)+"/templates", 'list.html')
self.response.out.write(template.render(path, template_values))
示例14: test_response_from_books_is_json
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def test_response_from_books_is_json(self):
self.assertEquals(0, Book.all().count())
book = Book(
title = "test",
ident = "1",
author = "author",
notes = "",
image = "http://example.com/image.gif",
url = "http://example.com"
)
book.put()
self.assertEquals(1, Book.all().count())
response = self.app.get('/books/', expect_errors=True)
try:
response.json # simplejons
except AttributeError:
assert(False)
示例15: test_response_contents_json_from_book
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import all [as 别名]
def test_response_contents_json_from_book(self):
self.assertEquals(0, Book.all().count())
book = Book(
title = "test",
ident = "1",
author = "author",
notes = "",
image = "http://example.com/image.gif",
url = "http://example.com"
)
book.put()
self.assertEquals(1, Book.all().count())
response = self.app.get('/books/%s' % book.ident, expect_errors=True)
try:
json = response.json
except AttributeError:
assert(False)
self.assertEqual(json['ident'], "1")
self.assertEqual(json['title'], "test")