当前位置: 首页>>代码示例>>Python>>正文


Python Book.put方法代码示例

本文整理汇总了Python中models.Book.put方法的典型用法代码示例。如果您正苦于以下问题:Python Book.put方法的具体用法?Python Book.put怎么用?Python Book.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Book的用法示例。


在下文中一共展示了Book.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: addBook

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [as 别名]
    def addBook(self, request):
        """create a book."""
        self._ensureAdmin()
        b_key = ndb.Key(Book, request.sbId.upper())
        if b_key.get():
            raise endpoints.ConflictException(
                'Another book with same id already exists: %s' % request.sbId)

        email = endpoints.get_current_user().email()

        book = Book (key = b_key,
            title = request.title.lower(),
            author = request.author,
            sbId = request.sbId.upper(),
            language = request.language,
            volume = request.volume,
            isbn = request.isbn,
            price = request.price,
            notes = request.notes,
            suggestedGrade = request.suggestedGrade,
            category = request.category,
            publisher = request.publisher,
            mediaType = request.mediaType,
            editionYear = request.editionYear,
            donor = request.donor,
            comments = request.comments,
            reference = request.reference,
            createdBy = email,
            createdDate = date.today()
            )
        book.put()
        return request
开发者ID:mangalambigai,项目名称:sblibrary,代码行数:34,代码来源:sblibrary.py

示例2: post

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [as 别名]
 def post(self, arg):
   book = Book(title     = self.request.get('title', None), 
               pages     = self.get_int_param('pages'),
               locations = self.get_int_param('locations'),
               page      = self.request.get('page', "Page"))
   book.put()
   self.redirect('/admin/books/%s/' % book.slug)
开发者ID:mrchucho,项目名称:infinite-summer,代码行数:9,代码来源:main.py

示例3: test_book_update_via_service_put

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [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")
开发者ID:garethr,项目名称:appengine-books,代码行数:32,代码来源:book.py

示例4: post

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [as 别名]
 def post(self):
     "Creates a new book record from a json representation"
     
     # check we have the correct authentication ket
     auth = self.request.get("auth")
     if auth != settings.AUTH:
         return self.error(401)
     
     # get the request body
     json = self.request.body
     # convert the JSON to a Python object
     representation = simplejson.loads(json)
     # create a datastore object from the JSON
     book = Book(
         title = representation['title'],
         ident = representation['ident'],
         author = representation['author'],
         image = representation['image'],
         notes = representation['notes'],
         url = representation['url']
     )
     logging.info('Add new book request')
     try:
         # save the object to the datastore
         book.put()
         # send an email about the new book
         _email_new_book(book)
     except:
         logging.error("Error occured creating new book via POST")
         self.error(500)
开发者ID:garethr,项目名称:appengine-books,代码行数:32,代码来源:main.py

示例5: post

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [as 别名]
    def post(self):
        entity_key_urlsafe = self.request.get("entity_key")
        book = None
        
        book_seller_key = self.person.key        
        # Make sure POST request is given these names
        book_image_url = self.request.get("image-url")
        book_price = float(self.request.get("price"))    
        book_isbn = self.request.get("isbn")
        book_author = self.request.get("author")
        book_title = self.request.get("title")
        book_dept = self.request.get("dept-abbrev")
        book_condition_id = int(self.request.get("condition"))
        
        if entity_key_urlsafe:
            book_key = ndb.Key(urlsafe=entity_key_urlsafe)
            book = book_key.get()
            
            # keep same seller key
            # don't need cart_key
            
            book.price = book_price
            
            if book_isbn:
                book.isbn = book_isbn
            if book_author:
                book.author = book_author
            if book_title:
                book.title = book_title
            if book_dept:
                book.dept = book_dept.lower()
            if book_condition_id:
                book.condition_id = book_condition_id

            book.image_url = book_image_url
        else:
            book = Book(parent=ROOT_BOOK_KEY, seller_key = book_seller_key, price=book_price,
                        image_url=book_image_url)
            if book_isbn:
                book.isbn = book_isbn
            if book_author:
                book.author = book_author
            if book_title:
                book.title = book_title
            if book_dept:
                book.dept = book_dept.lower()
            if book_condition_id:
                book.condition_id = book_condition_id

            # TODO: Replace above with this when all fields are given
#             book = Book(parent=ROOT_BOOK_KEY, seller_key = book_seller_key, price=book_price, 
#                         image_url=book_image_url, 
#                         isbn = book_isbn, author = book_author, title = book_title, 
#                         dept = book_dept, comments = str(book_comments).strip())
        logging.info("Adding Book: " + str(book))
        book.put()
        self.redirect(self.request.referer)
开发者ID:fanghuang,项目名称:Booksharepoint,代码行数:59,代码来源:action_handlers.py

示例6: post

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [as 别名]
    def post(self):
        book = Book()
        book.title = self.request.get('title')
        book.info_url = self.request.get('info_url')
        book.authors = self.request.get('authors')
        book.isbn_10 = self.request.get('isbn_10')
        book.isbn_13 = self.request.get('isbn_13')
        book.put()

        self.response.out.write(book.to_json('title', 'authors', 'isbn_10', 'isbn_13', 'is_deleted', 'is_active', 'is_starred'))
开发者ID:spaceone,项目名称:mils-secure,代码行数:12,代码来源:api.py

示例7: edit_book

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [as 别名]
def edit_book(request):
    if request.method == 'POST':
        form = BookForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            book = Book(title=cd['title'])
            book.put()
            return   HttpResponseRedirect('/search/?q=all')
    else:
        form = BookForm()
        logger.error ("here i am")
    return render_to_response('book_edit.html', {'form': form})
开发者ID:frauca,项目名称:samples,代码行数:14,代码来源:views.py

示例8: put

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [as 别名]
    def put(self, ident):
        "Update an existing book or create a new one"

        # check we have the correct authentication ket
        auth = self.request.get("auth")
        if auth != settings.AUTH:
            return self.error(401)

        # get the JSON from the request
        json = self.request.body
        # convert the JSON to a Python object 
        representation = simplejson.loads(json)
        # set the properties
        title = representation['title']
        ident = representation['ident']
        author = representation['author']
        image = representation['image']
        notes = representation['notes']
        url = representation['url']
        
        try:
            # retrieve the book based on its ident value
            book = Book.all().filter('ident =', ident)[0]
            book.title = title
            book.ident = ident
            book.author = author
            book.image = image
            book.notes = notes
            book.url = url
        except IndexError:
            # if we don't find a book then create one
            book = Book(
                title = title,
                ident = ident,
                author = author,
                image = image,
                notes = notes,
                url = url
            )
        logging.info("Update request for %s (%s)" % (title, ident))
        # save the object to the datastore
        try:
            # save the object to the datastore
            book.put()
            # send an email about the new book
            _email_new_book(book)            
            # we'e updated so we need to clear the cache
            memcache.delete("ws_books")
        except:
            logging.error("Error occured creating/updating \
                book %s (%s) via PUT") % (title, ident)
            self.error(500)
开发者ID:garethr,项目名称:appengine-books,代码行数:54,代码来源:main.py

示例9: test_books_with_content_returns_200

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [as 别名]
 def test_books_with_content_returns_200(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()   
     response = self.app.get('/books', expect_errors=True)        
     self.assertEquals("200 OK", response.status)
开发者ID:garethr,项目名称:appengine-books,代码行数:15,代码来源:books.py

示例10: test_book_deletion

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [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())
开发者ID:garethr,项目名称:appengine-books,代码行数:16,代码来源:book.py

示例11: test_book_deletion_via_service

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [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())
开发者ID:garethr,项目名称:appengine-books,代码行数:16,代码来源:book.py

示例12: test_books_views_return_correct_mime_type

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [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")
开发者ID:garethr,项目名称:appengine-books,代码行数:16,代码来源:books.py

示例13: test_sending_email

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [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)
开发者ID:garethr,项目名称:appengine-books,代码行数:16,代码来源:email.py

示例14: test_response_contents_from_books

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [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"')
开发者ID:garethr,项目名称:appengine-books,代码行数:17,代码来源:books.py

示例15: test_response_from_books_is_json

# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import put [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)
开发者ID:garethr,项目名称:appengine-books,代码行数:19,代码来源:books.py


注:本文中的models.Book.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。