Esempio n. 1
0
 def to_python(self, value):
     if value in EMPTY_VALUES:
         return u''
     value = smart_unicode(value)
     m = phone_digits_re.search(value)
     if m:
         return u'-'.join(m.groups())
     return value
Esempio n. 2
0
 def clean(self, value):
     if value in EMPTY_VALUES:
         return u''
     m = phone_digits_re.search(value)
     if m:
         print u'%s %s %s' % (m.group(1), m.group(2), m.group(3))
         return u'%s %s %s' % (m.group(1), m.group(2), m.group(3))
     raise forms.ValidationError("Phone numbers must be in 'int(3) local(1,2) number(7)' format and contain only numbers.")
Esempio n. 3
0
	def get_by_number(self, number):
		try:
			return self.get(phone_number=number)
		except:
			pass
	 	number = re.sub('(\(|\)|\s+)', '', smart_unicode(number))
		matches = phone_digits_re.search(number)
		if not matches: return None
		formatted_phone_number = '%s-%s-%s' % (matches.group(1), matches.group(2), matches.group(3))
		try:
			return self.get(phone_number=formatted_phone_number)
		except:
			return None
Esempio n. 4
0
	def __unicode__(self):
	 	number = re.sub('(\(|\)|\s+)', '', self.phone_number)
		matches = phone_digits_re.search(number)
		if not matches: return self.phone_number
		return '(%s) %s-%s' % (matches.group(1), matches.group(2), matches.group(3))