예제 #1
0
def ProcessExcel(filename):
	g = FoodGroup(name='Fruits')
	g.save()
	book = open_workbook(filename)
	sheet = book.sheet_by_index(0)

	cur_group = ''
	in_group = False
	total_sum = 0

	for row_index in range(sheet.nrows):
		if (sheet.cell(row_index, 0).value == ''):
			in_group = False
			cur_group = ''
			total_sum = 0
			g = ''
		elif in_group == False:
			cur_group = sheet.cell(row_index, 0).value
			opt_value_group = int(sheet.cell(row_index,1).value)
			in_group = True
			g = FoodGroup(name=cur_group, optimal_number = opt_value_group, current_number = 0)
			g.save()
		else:
			name = sheet.cell(row_index, 0).value
			current_value = int(sheet.cell(row_index, 1).value)
			opt_value = int(sheet.cell(row_index, 2).value)
			total_sum += current_value
			i = FoodItem(name=name, foodgroup = g, optimal_number=opt_value, current_number= current_value)
			i.save()

	return 'done'
예제 #2
0
def handle_uploaded_file(f):
	book = open_workbook(file_contents=f.read())
	sheet = book.sheet_by_index(0)
	date = DateUploaded(date=timezone.now())
	date.save()

	cur_group = ''
	in_group = False
	total_sum = 0
	cur_group_Item = ''
	count = 0
	for row_index in range(sheet.nrows):
		if count == 0:
			count += 1
		elif (sheet.cell(row_index, 0).value == ''):
			update_Group_Sum(cur_group_Item, total_sum)
			in_group = False
			cur_group = ''
			total_sum = 0
			g = ''
		elif in_group == False:
			cur_group = sheet.cell(row_index, 0).value
			opt_value_group = int(sheet.cell(row_index,1).value)
			in_group = True
			cur_group_Item = FoodGroup(name=cur_group, change = 0, deficit = 0, 
			optimal_number=opt_value_group, current_number= 0, upload_date=date)
			cur_group_Item.save()
		else:
			name = sheet.cell(row_index, 0).value
			current_value = int(sheet.cell(row_index, 1).value)
			opt_value = int(sheet.cell(row_index, 2).value)
			priority = sheet.cell(row_index, 3).value
			total_sum += current_value
			update_Item(name, cur_group_Item, opt_value, current_value, priority, date)
	update_Group_Sum(cur_group, total_sum)
	process()