Skip to content

Commit

Permalink
#99 small refactoring for getting stand sectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh4kE committed Dec 12, 2016
1 parent 7e159c0 commit 8bb3e38
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions core/views/ofm/stadium_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

This comment has been minimized.

Copy link
@StegSchreck

StegSchreck Dec 12, 2016

Member

this might cause an error, if the stand was under construction, so not used for the requested match

This comment has been minimized.

Copy link
@Sh4kE

Sh4kE Dec 12, 2016

Author Member

We need to write failing tests for such bugs...

This comment has been minimized.

Copy link
@StegSchreck

StegSchreck Dec 12, 2016

Member

done in 2b01024



@method_decorator(login_required, name='dispatch')
class StadiumStandStatisticsView(TemplateView):
Expand Down

0 comments on commit 8bb3e38

Please sign in to comment.