@@ -150,34 +150,55 @@ def get_record_config(record):
150
150
return None
151
151
152
152
153
- def record_view (request , competition_slug , year , record ):
153
+ def get_record_common_context (request , competition_slug , year , record = None ):
154
154
season = get_season (competition_slug , year )
155
- record_config = get_record_config ( record )
156
- rank = season . stats_rank ( ** record_config [ 'filter' ]) if record_config else None
157
- title = _ ('%(record_label)s Record, %(season)s' ) \
155
+ if record :
156
+ record_config = get_record_config ( record )
157
+ title = _ ('%(record_label)s Record, %(season)s' ) \
158
158
% {'record_label' : record_config ['label' ], 'season' : season }
159
- context = {'rank' : rank ,
159
+ else :
160
+ title = _ ('Select a %(season)s record' % {'season' : season })
161
+
162
+ context = {
160
163
'season' : season ,
161
164
'title' : title ,
162
165
'record' : record ,
163
166
'record_codes' : DR27_RECORDS_FILTER
164
167
}
165
- tpl = 'driver27/record-view.html'
168
+
169
+ return context
170
+
171
+
172
+ def driver_record_view (request , competition_slug , year , record = None ):
173
+ context = get_record_common_context (request , competition_slug , year , record )
174
+
175
+ if record :
176
+ season = context .get ('season' , None )
177
+ record_config = get_record_config (record )
178
+ rank = season .stats_rank (** record_config ['filter' ]) if record_config else None
179
+ else :
180
+ rank = None
181
+ context ['rank' ] = rank
182
+ tpl = 'driver27/driver-record.html'
166
183
return render (request , tpl , context )
167
184
168
185
169
- def record_team_view (request , competition_slug , year , record ):
170
- season = get_season (competition_slug , year )
171
- record_config = get_record_config (record )
172
- rank = season .team_stats_rank (** record_config ['filter' ]) if record_config else None
173
- title = _ ('%(record_label)s Team Record, %(season)s' ) \
174
- % {'record_label' : record_config ['label' ], 'season' : season }
175
- context = {'rank' : rank ,
176
- 'season' : season ,
177
- 'title' : title ,
178
- 'record' : record ,
179
- 'record_codes' : DR27_RECORDS_FILTER
180
- }
181
- tpl = 'driver27/record-team-view.html'
186
+ def team_record_by_race_view (request , competition_slug , year , record = None ):
187
+ return team_record_view (request , competition_slug , year , record = record , unique_by_race = True )
188
+
189
+
190
+ def team_record_view (request , competition_slug , year , record = None , unique_by_race = False ):
191
+ context = get_record_common_context (request , competition_slug , year , record )
192
+
193
+ if record :
194
+ season = context .get ('season' , None )
195
+ record_config = get_record_config (record )
196
+ rank = season .team_stats_rank (unique_by_race = unique_by_race , ** record_config ['filter' ]) \
197
+ if record_config else None
198
+ else :
199
+ rank = None
200
+ context ['rank' ] = rank
201
+ context ['by_race' ] = bool (unique_by_race )
202
+ tpl = 'driver27/team-record.html'
182
203
return render (request , tpl , context )
183
204
0 commit comments