1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 from storm.locals import *
20 from copy import copy
21
22 from base import MyStorm
23 from ranking import Rankable, RankableItem
24
26 """Base class for all runner like classes (runners, teams). This
27 class defines the interface for all objects that work with any kind
28 of runners or teams."""
29
30 name = None
31 number = None
32 official = None
33 sicards = None
34
35 -class Runner(AbstractRunner, Storm):
36 __storm_table__ = 'runner'
37
38 id = Int(primary=True)
39 number = Unicode()
40 given_name = Unicode()
41 surname = Unicode()
42 dateofbirth = Date()
43 sex = Enum(map = {'male':u'male', 'female':u'female'})
44 _nation_id = Int(name='nation')
45 nation = Reference(_nation_id, 'Country.id')
46 solvnr = Unicode()
47 startblock = Int()
48 starttime = Date()
49 _category_id = Int(name='category')
50 category = Reference(_category_id, 'Category.id')
51 _club_id = Int(name='club')
52 club = Reference(_club_id, 'Club.id')
53 address1 = Unicode()
54 address2 = Unicode()
55 zipcode = Unicode()
56 city = Unicode()
57 _address_country_id = Int(name='address_country')
58 address_country = Reference(_address_country_id, 'Country.id')
59 email = Unicode()
60 startfee = Int()
61 paid = Bool()
62 preferred_category = Unicode()
63 doping_declaration = Bool()
64 comment = Unicode()
65 _team_id = Int(name='team')
66 team = Reference(_team_id, 'Team.id')
67 sicards = ReferenceSet(id, 'SICard._runner_id')
68
69 - def __init__(self, surname=u'', given_name=u'', sicard = None, category = None, number = None,
70 dateofbirth=None, sex=None, nation=None, solvnr=None, startblock=None,
71 starttime=None, club=None, address1=None, address2=None, zipcode=None,
72 city=None, address_country=None, email=None, startfee=None, paid=None,
73 preferred_category=None, doping_declaration=None, comment=None,
74 ):
99
101 return unicode(self).encode('utf-8')
102
105
107 runs = []
108 for si in self.sicards:
109 for r in si.runs:
110 runs.append(r)
111
112 if len(runs) == 1:
113 return runs[0]
114 elif len(runs) > 1:
115
116 complete_runs = [ r for r in runs if r.complete == True ]
117 if len(complete_runs) == 1:
118
119 return complete_runs[0]
120 else:
121 raise RunnerException(u'%s runs for runner %s (%s)' % (len(runs), self, self.number))
122 else:
123 raise RunnerException(u'No run found for runner %s (%s)' % (self, self.number))
124 run = property(_get_run)
125
126 -class Team(AbstractRunner, Storm):
162
163
176
188
190 __storm_table__ = 'category'
191
192 id = Int(primary=True)
193 name = Unicode()
194 runners = ReferenceSet(id, 'Runner._category_id')
195 teams = ReferenceSet(id, 'Team._category_id')
196
199
201 return unicode(self).encode('utf-8')
202
205
210 members = property(_get_members)
211
213 __storm_table__ = 'country'
214
215 id = Int(primary=True)
216 name = Unicode()
217 code2 = Unicode()
218 code3 = Unicode()
219 runners = ReferenceSet(id, 'Runner._nation_id')
220
221 - def __init__(self, code3, code2, name=None):
225
227 return unicode(self).encode('utf-8')
228
231
232
234 __storm_table__ = 'club'
235
236 id = Int(primary=True)
237 name = Unicode()
238 runners = ReferenceSet(id, 'Runner._club_id')
239
242
244 return unicode(self).encode('utf-8')
245
248
249
252