From 8bb3e384663a295f82150fc94d02c854ad80175d Mon Sep 17 00:00:00 2001 From: Michael Wittig Date: Mon, 12 Dec 2016 09:41:32 +0100 Subject: [PATCH] #99 small refactoring for getting stand sectors --- core/views/ofm/stadium_views.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/core/views/ofm/stadium_views.py b/core/views/ofm/stadium_views.py index 1185c11..dcbffe0 100644 --- a/core/views/ofm/stadium_views.py +++ b/core/views/ofm/stadium_views.py @@ -150,21 +150,16 @@ def _get_stadium_statistics_in_json(stadium_stat): class StadiumDetailView(DetailView): context_object_name = 'stadium_stat' template_name = 'core/ofm/stadium_detail.html' - queryset = MatchStadiumStatistics.objects.all() + model = MatchStadiumStatistics def get_context_data(self, **kwargs): context = super(StadiumDetailView, self).get_context_data(**kwargs) if self.get_object(): - north_stand = StadiumStandStatistics.objects.filter(stadium_statistics=self.get_object(), sector='N') - south_stand = StadiumStandStatistics.objects.filter(stadium_statistics=self.get_object(), sector='S') - west_stand = StadiumStandStatistics.objects.filter(stadium_statistics=self.get_object(), sector='W') - east_stand = StadiumStandStatistics.objects.filter(stadium_statistics=self.get_object(), sector='O') - - context['north_stand'] = north_stand[0] if north_stand.count() > 0 else None - context['south_stand'] = south_stand[0] if south_stand.count() > 0 else None - context['west_stand'] = west_stand[0] if west_stand.count() > 0 else None - context['east_stand'] = east_stand[0] if east_stand.count() > 0 else None + context['north_stand'] = self._get_stand_sector('N') + context['south_stand'] = self._get_stand_sector('S') + context['west_stand'] = self._get_stand_sector('W') + context['east_stand'] = self._get_stand_sector('O') return context @@ -173,6 +168,9 @@ def get_object(self, **kwargs): matches = Match.objects.filter(user=self.request.user, stadium_statistics=stadium_stat) return stadium_stat if matches.count() > 0 else None + def _get_stand_sector(self, sector): + return StadiumStandStatistics.objects.get(stadium_statistics=self.get_object(), sector=sector) + @method_decorator(login_required, name='dispatch') class StadiumStandStatisticsView(TemplateView):