def post(self):
		book_type = self.request.get('type')
		if book_type is None:
			logging.info('None')
			self.redirect('/bookdetails')
		else:
			logging.info('Book type: %s', book_type)

		type_name = Type.query(Type.name == book_type).get()
		if type_name is None:
			logging.info('None')
			self.redirect('/bookdetails')
		else:
			logging.info('Type %s',book_type)

		book_details = Product()

		if self.request.get('img'):
			book_details.image = db.Blob (images.resize(self.request.get('img'), 350, 450))

		book_details.bookId = self.request.get('bookcode')
		book_details.title = self.request.get('title')
		book_details.category = type_name.key
		book_details.author = self.request.get('author')
		book_details.price = self.request.get('price')
		book_details.descrip = self.request.get('editor1')
		book_details.put()

		logging.info('Added book with: %s', book_details.bookId)
		self.redirect('/bookdetails')
Esempio n. 2
0
 def create_product(name, barcode, category):
     """ Create a product in datastore """
     query = Product.all()
     query.filter("barcode =", barcode)
     ret = query.get()
     if ret is None:
         ret = Product()
         ret.barcode = barcode
         ret.set_name(name)
         ret.category = category
         ret.put()
         AdminWorkerHandler.update_search_table(ret)
     return ret