Exemplo n.º 1
0
	def create_coffee(coffee):
		# skip duplicates
		if Coffee.objects.filter(name=coffee.name).count() > 0:
			messages.warning(req, 'Skipped "%s" since a coffee with that name already exists' % coffee.name)
			return

		c = Coffee()
		c.name = coffee.name
		c.description = coffee.description
		c.one_pound_price = coffee.one_pound_price
		c.two_pound_price = coffee.two_pound_price
		c.five_pound_price = coffee.five_pound_price
		c.set_image(coffee.image_data)

		c.save()
Exemplo n.º 2
0
def make_coffee(row):
	'''makes a coffee object from the db row'''

	OnePoundPrices = {'$12.95': 8.75, '$13.95': 9.75, '$14.95': 9.50, '$14.45': 9.50}
	TwoPoundPrices = {'$24.15': 8.50*2, '$24.95': 8.50*2, '$24.75': 8.50*2, '$28.20': 8.50*2, '$25.70': 8.50*2, '$26.70': 8.50*2}
	FivePoundPrices = {'$59.15': 8.25*5, '$59.00': 8.25*5, '$70.50': 9.25*5, '$60.35': 9.25*5, '$63.35': 9.25*5, '$63.65': 9.25*5}

	c = Coffee()
	c.name = row[0]
	c.description = row[1]
	c.one_pound_price = OnePoundPrices[row[2]]
	c.two_pound_price = TwoPoundPrices[row[3]]
	c.five_pound_price = FivePoundPrices[row[4]]
	c.prices = {1: c.one_pound_price, 2: c.two_pound_price, 5: c.five_pound_price }
	c.image_data = row[5]

	return c