示例#1
0
	def test_clean_led_count_and_height_and_width_each_at_minimum(self):
		form_data = {
			'led_count': 1,
			'height': 1,
			'width': 1,
			'position': 'BL',
			'direction': 'V',
			}
		form = GridForm(data = form_data)
		self.assertTrue(form.is_valid())
示例#2
0
	def test_clean_rotation_defined_when_direction_is_spiral(self):
		form_data = {
			'led_count': 1,
			'height': 1,
			'width': 1,
			'position': 'BL',
			'direction': 'S',
			'rotation': 'C',
			}
		form = GridForm(data = form_data)
		self.assertTrue(form.is_valid())
示例#3
0
	def test_clean_rotation_not_defined_when_direction_is_spiral(self):
		form_data = {
			'led_count': 1,
			'height': 1,
			'width': 1,
			'position': 'BL',
			'direction': 'S',
			}
		form = GridForm(data = form_data)
		self.assertFalse(form.is_valid())
		self.assertEqual(
			form.errors['rotation'][0],
			"Missing information - If the grid is wired in a spiral pattern, the direction in which the spiral rotates must be specified"
			)
示例#4
0
	def test_clean_width_too_low(self):
		form_data = {
			'led_count': 1,
			'height': 1,
			'width': 0,
			'position': 'BL',
			'direction': 'H',
			}
		form = GridForm(data = form_data)
		self.assertFalse(form.is_valid())
		self.assertEqual(
			form.errors['width'][0],
			'Invalid grid width - Must be greater then 0'
			)
		self.assertEqual(
			form.errors['__all__'][0],
			'Invalid height/width - The height * width must equal the number of LEDs'
			)
示例#5
0
def grid_settings(request):
	"""View function for grid settings form"""
	
	# Ensure that shape has been set to grid
	try:
		# try and retrieve shape
		shape = Shape.objects.get(pk = 1)
		
		# test if the shape is not set to grid
		if shape.shape != 'G':
			# Redirect if the shape is not set to grid
			shape_url_names = {
				'C': "circle-settings",
				'L': "line-settings",
				'S': "square-settings",
				}
			return HttpResponseRedirect(reverse(shape_url_names[shape.shape]))
	
	except Shape.DoesNotExist:
		# The selected shape hasn't been set
		return HttpResponseRedirect(reverse('shape'))	
	
	# if this is a POST request then process the Form data
	if request.method == "POST":
		
		# Check if settings already were created. Will have PK of 1
		try:
			s = Grid.objects.get(pk = 1)
			form = GridForm(request.POST, instance = s)
			
		except Grid.DoesNotExist:
			# First time creating settings. Load blank form.
			form = GridForm(request.POST)
		
		# Check if the form is valid:
		if form.is_valid():
			form.save()
			led_strip.reload_map(shape.shape)
			return HttpResponseRedirect(reverse('home'))
	
	else:
		try:
			s = Grid.objects.get(pk = 1)
			form = GridForm(instance = s)
		except ObjectDoesNotExist:
			form = GridForm()
	
	context = {
		'form': form,
		} 
	
	return render(request, 'LEDApp/grid_settings.html', context)