Exemplo n.º 1
0
	def clean(self, value):
		import re
		if not value: return value
		value = value.strip()
		# Is it in degrees? (float)
		try:
			value = float(value)
		except ValueError:
			if not re.match(r'^[+-]?\d{2}:\d{2}:\d{2}(\.\d{3})?$', value):
				raise forms.ValidationError('The DEC format is invalid.')
			else:
				# Conversion to decimal
				from terapix.lib.coordconvert import Delta
				value = Delta.sex_to_deg(value)
		return value
Exemplo n.º 2
0
	def clean(self, value):
		import re
		if not value: return value
		value = value.strip()
		# Is it in degrees? (float)
		try:
			value = float(value)
		except ValueError:
			if not re.match(r'^\d{2}:\d{2}$', value): 		# degrees:minutes
				if not re.match(r'^\d{2}$', value):			# degrees
					if not re.match(r'^:\d{2}$', value):	# minutes
						raise forms.ValidationError('The radius format is invalid.')
					else:
						value = '00' + value + ':00' # Add degrees and seconds
				else:
					value += ':00:00' # Add minutes and seconds
			else:
				value += ':00' # Add seconds
			from terapix.lib.coordconvert import Delta
			value = Delta.sex_to_deg(value)
		return value