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_person(value, previous):
34 comma_count = value.count(',')
37 last_name, first_names = value, []
38 elif comma_count == 1:
39 last_name, first_names = value.split(',')
40 first_names = [name for name in first_names.split(' ') if len(name)]
42 raise ValueError("value contains more than one comma: %r" % value)
44 return Person(last_name.strip(), *first_names)
47 def str_to_date(value, previous):
49 t = time.strptime(value, '%Y-%m-%d')
51 t = time.strptime(value, '%Y')
52 return date(t[0], t[1], t[2])