Added short_html method to Book model and removed (no longer used) book template...
[wolnelektury.git] / lib / dcparser / converters.py
1 # -*- coding: utf-8 -*-
2 from datetime import date
3 import time
4 import re
5
6 from person import Person
7
8
9 def str_to_unicode(value):
10     return unicode(value)
11
12
13 def str_to_person(value):
14     comma_count = value.count(',')
15     
16     if comma_count == 0:
17         last_name, first_names = value, []
18     elif comma_count == 1:
19         last_name, first_names = value.split(',')
20         first_names = [name for name in first_names.split(' ') if len(name)]
21     else:
22         raise ValueError("value contains more than one comma: %r" % value)
23     
24     return Person(last_name.strip(), *first_names)
25
26
27 def str_to_date(value):
28     try:
29         t = time.strptime(value, '%Y-%m-%d')
30     except ValueError:
31         t = time.strptime(value, '%Y')
32     return date(t[0], t[1], t[2])
33
34