Skip to content

Commit

Permalink
Locale ES and translations.
Browse files Browse the repository at this point in the history
  • Loading branch information
SRJ9 committed Nov 15, 2016
1 parent cb2298a commit e2fd6d6
Show file tree
Hide file tree
Showing 18 changed files with 688 additions and 147 deletions.
37 changes: 25 additions & 12 deletions driver27/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.conf.urls import url
from django.shortcuts import render
from django.db.models.fields import BLANK_CHOICE_DASH
from django.utils.translation import ugettext as _

from django.core.urlresolvers import reverse

Expand All @@ -23,7 +24,8 @@ def print_competitions(self, obj):
return ', '.join("%s" % competition for competition in obj.competitions.all())
else:
return None
print_competitions.short_description = 'competitions'
print_competitions.short_description = _('competitions')


class CompetitionFilterInline(admin.TabularInline):
def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
Expand All @@ -36,42 +38,50 @@ def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
kwargs['queryset'] = Seat.objects.filter(contender__competition__exact=request._obj_.competition)
return super(CompetitionFilterInline, self).formfield_for_foreignkey(db_field, request, **kwargs)


class CommonRaceAdmin(object):
def print_results_link(self, obj):
if obj.pk:
results_url = reverse("admin:driver27_race_results", args=[obj.pk])
return '<a href="%s">%s</a>' % (results_url, 'Results')
return '<a href="%s">%s</a>' % (results_url, _('Results'))
else:
return None
print_results_link.allow_tags = True
print_results_link.short_description = 'link'
print_results_link.short_description = _('link')


class RaceInline(CommonRaceAdmin, CompetitionFilterInline):
model = Race
extra = 1
readonly_fields = ('print_results_link', )


class SeatInline(CompetitionFilterInline):
model = Seat
extra = 3


class SeatSeasonInline(CompetitionFilterInline):
model = Seat.seasons.through
extra = 3
ordering = ('seat',)


class ContenderInline(admin.TabularInline):
model = Contender
extra = 1


class TeamSeasonInline(CompetitionFilterInline):
model = TeamSeason
extra = 1


class TeamInline(admin.TabularInline):
model = Team
extra = 1


class DriverAdmin(RelatedCompetitionAdmin, TabbedModelAdmin):
list_display = ('__unicode__', 'country', 'print_competitions')
list_filter = ('competitions__name',)
Expand All @@ -88,9 +98,11 @@ class DriverAdmin(RelatedCompetitionAdmin, TabbedModelAdmin):
('Competitions', tab_competitions)
]


class TeamAdmin(RelatedCompetitionAdmin, admin.ModelAdmin):
list_display = ('__unicode__', 'country', 'print_competitions')


class CompetitionAdmin(TabbedModelAdmin):
model = Competition
list_display = ('name', 'full_name')
Expand All @@ -107,12 +119,15 @@ class CompetitionAdmin(TabbedModelAdmin):
('Drivers', tab_drivers)
]


class CircuitAdmin(admin.ModelAdmin):
list_display = ('name', 'city', 'country', 'opened_in')


class GrandPrixAdmin(RelatedCompetitionAdmin, admin.ModelAdmin):
list_display = ('name', 'country', 'default_circuit', 'print_competitions')


class SeasonAdminForm(forms.ModelForm):

def __init__(self, *args, **kwargs):
Expand All @@ -125,6 +140,7 @@ class Meta:
model = Season
fields = ('year', 'competition', 'rounds', 'punctuation')


class SeasonAdmin(TabbedModelAdmin):
form = SeasonAdminForm
tab_overview = (
Expand All @@ -136,9 +152,6 @@ class SeasonAdmin(TabbedModelAdmin):
TeamSeasonInline,
)
tab_drivers = (
# (None, {
# 'fields': ('team_contenders',)
# }),
SeatSeasonInline,
)
tab_races = (
Expand Down Expand Up @@ -176,15 +189,16 @@ def print_seat(self, seat):

def print_pole(self, obj):
return self.print_seat(obj.pole)
print_pole.short_description = 'Pole'
print_pole.short_description = _('Pole')

def print_winner(self, obj):
return self.print_seat(obj.winner)
print_winner.short_description = 'Winner'
print_winner.short_description = _('Winner')

def print_fastest(self, obj):
return self.print_seat(obj.fastest)
print_fastest.short_description = 'Fastest'
print_fastest.short_description = _('Fastest')


def clean_qualifying(self, qualifying):
try:
Expand Down Expand Up @@ -230,7 +244,6 @@ def edit_result_entries(self, request, entries, race, action='update'):
**dict_to_save
)


def add_result_entries(self, request, entries, race):
self.edit_result_entries(request, entries, race, action='add')

Expand Down Expand Up @@ -270,7 +283,6 @@ def order_entries(self, entries, seats_len):
entries = sorted(entries, key=lambda x: -x['season_points'])
return entries


def results(self, request, race_id):
race = self.model.objects.get(pk=race_id)
title = 'Results in %s' % race
Expand Down Expand Up @@ -334,6 +346,7 @@ def results(self, request, race_id):
tpl = 'driver27/admin/results.html'
return render(request, tpl, context)


class ContenderAdmin(TabbedModelAdmin):
list_display = ('__unicode__', 'competition', 'teams_verbose', 'print_current')
list_filter = ('competition',)
Expand All @@ -356,7 +369,7 @@ def print_current(self, obj):
contender__competition=obj.competition,
current=True)
return filter_current[0].team if filter_current.count() else None
print_current.short_description = 'current team'
print_current.short_description = _('current team')

def get_form(self, request, obj=None, **kwargs):
# just save obj reference for future processing in Inline
Expand Down
Loading

0 comments on commit e2fd6d6

Please sign in to comment.