Skip to content

Commit

Permalink
Fix team record/streak view and add new records.
Browse files Browse the repository at this point in the history
  • Loading branch information
SRJ9 committed Jul 12, 2017
1 parent 3e21000 commit d30e8e4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
8 changes: 7 additions & 1 deletion driver27/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ def get_init_config():
'RECORDS': {
'RACE': {'label': _('Race'), 'filter': {}},
'POLE': {'label': _('Pole'), 'filter': {'qualifying__exact': 1}},
'POLE-OUT': {'label': _('Pole and Out'), 'filter': {'qualifying__exact': 1,
'retired': True}},
'FIRST-ROW': {'label': _('First row'), 'filter': {'qualifying__gte': 1, 'qualifying__lte': 2},
'doubles': True},
'COMEBACK-TO-TEN': {'label': _('Comeback to 10 firsts'), 'filter': {'qualifying__gte': 11,
'finish__gte': 1,
'finish__lte': 10}},
'finish__lte': 10},
'doubles': True},
'PODIUM-AFTER-11': {'label': _('Podium after qualifying 11th or more'),
'filter': {'qualifying__gte': 11, 'finish__gte': 1, 'finish__lte': 3},
'doubles': True},
'WIN': {'label': _('Win'), 'filter': {'finish__exact': 1}},
'POLE-WIN': {'code': 'POLE-WIN', 'label': _('Pole and Win'), 'filter': {'qualifying__exact': 1,
'finish__exact': 1}},
Expand Down
6 changes: 5 additions & 1 deletion driver27/templates/driver27/team/team-record-optgroup.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{% for record_code, record_label in record_codes %}
<option value="{{ record_code }}"
{% if record_code == record and rank_type == rank_group %}selected{% endif %}>{{ record_label }}</option>
{% if record_code == record %}selected{% endif %}
{% if rank_opt|lower == 'doubles' and record_code not in doubles_record_codes %}
style="background-color: lightsalmon"
{% endif %}
>{{ record_label }}</option>
{% endfor %}
2 changes: 1 addition & 1 deletion driver27/templates/driver27/team/team-record.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% block dr27_content %}
{{ block.super }}
{% load champion_filter i18n %}
<form method="POST" class="form-inline" action="{% url 'dr27-team-record-redir' %}" onchange="this.submit()">>
<form method="POST" class="form-inline" action="{% url 'dr27-team-record-redir' %}" onchange="this.submit()">
{% csrf_token %}
<div class="form-group col-md-4">
{% if competition %}
Expand Down
4 changes: 2 additions & 2 deletions driver27/urls/competition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

urlpatterns = [
url(r'^$', views.competition_view, name='dr27-competition-view'),
url(r'^rank/driver/', include('driver27.urls.competition.driver')),
url(r'^rank/team/', include('driver27.urls.competition.team')),
url(r'^driver/', include('driver27.urls.competition.driver')),
url(r'^team/', include('driver27.urls.competition.team')),
url(r'^(?P<year>\d+)/', include('driver27.urls.season')),
]
23 changes: 11 additions & 12 deletions driver27/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def team_streak_view(request, competition_slug=None, year=None, record=None, onl
context.pop('record_filter', None)
context['rank'] = rank
context['rank_opt'] = get_streak_value_for_selector(only_actives=only_actives, max_streak=max_streak)
context['rank_type'] = 'RACES'

tpl = 'driver27/team/team-record.html'
return render(request, tpl, context)

Expand All @@ -315,8 +315,7 @@ def team_record_view(request, competition_slug, year, rank_type, record=None):
rank = season_or_competition.get_team_rank(rank_type, **context.get('record_filter')) if 'record_filter' in context else None
context['rank'] = rank
context['rank_opt'] = rank_type
context['doubles_record_codes'] = get_record_label_dict(doubles=True)
# context['races'] = (rank_type in ('RACES', 'RACES-DOUBLES'))
context['doubles_record_codes'] = [double_code for double_code, double_label in get_record_label_dict(doubles=True)]
tpl = 'driver27/team/team-record.html'
return render(request, tpl, context)

Expand Down Expand Up @@ -366,27 +365,27 @@ def team_record_redirect_view(request):
record = request.POST.get('record', '')
rank_opt = request.POST.get('rank_opt')

request_args = [competition_slug, year, record]
reverse_args = [arg for arg in request_args if arg]

if competition_slug and year:
base_reverse_url = 'dr27-season'
reverse_args = [competition_slug, year, record]
elif competition_slug:
base_reverse_url = 'dr27-competition'
reverse_args = [competition_slug, record]
else:
base_reverse_url = 'dr27-global'
reverse_args = [record]

if not rank_opt:
rank_opt = 'stats'

reverse_url = \
{
'streak': reverse(base_reverse_url+'-team-streak', args=reverse_args),
'streak_top': reverse(base_reverse_url+'-team-top-streak', args=reverse_args),
'doubles': reverse(base_reverse_url+'-team-record-doubles', args=reverse_args),
'races': reverse(base_reverse_url+'-team-record-races', args=reverse_args),
'stats': reverse(base_reverse_url+'-team-record', args=reverse_args)
'streak': 'team-streak',
'streak_top': 'team-top-streak',
'doubles': 'team-record-doubles',
'races': 'team-record-races',
'stats': 'team-record'
}.get(rank_opt, None)

return redirect(reverse_url)
return redirect(reverse(base_reverse_url+'-'+reverse_url, args=reverse_args))

0 comments on commit d30e8e4

Please sign in to comment.