1 # -*- coding: utf-8 -*-
2 from datetime import date
8 """Single person with last name and a list of first names."""
9 def __init__(self, last_name, *first_names):
10 self.last_name = last_name
11 self.first_names = first_names
14 def __eq__(self, right):
15 return self.last_name == right.last_name and self.first_names == right.first_names
18 def __unicode__(self):
19 if len(self.first_names) > 0:
20 return '%s, %s' % (self.last_name, ' '.join(self.first_names))
26 return 'Person(last_name=%r, first_names=*%r)' % (self.last_name, self.first_names)
29 def str_to_unicode(value, previous):
33 def str_to_unicode_list(value, previous):
36 previous.append(str_to_unicode(value))
40 def str_to_person(value, previous):
41 comma_count = value.count(',')
44 last_name, first_names = value, []
45 elif comma_count == 1:
46 last_name, first_names = value.split(',')
47 first_names = [name for name in first_names.split(' ') if len(name)]
49 raise ValueError("value contains more than one comma: %r" % value)
51 return Person(last_name.strip(), *first_names)
54 def str_to_date(value, previous):
56 t = time.strptime(value, '%Y-%m-%d')
58 t = time.strptime(value, '%Y')
59 return date(t[0], t[1], t[2])