def inject_outbreak_percentage(request):
    try:
        latest_game = Game.games(started=True).latest()
    except Game.DoesNotExist:
        # Just return an arbitrary sane value
        return {'outbreak_percent': 96}

    players = Player.objects.filter(game=latest_game)
    humans = players.filter(team='H')

    nPlayers = players.count()

    if nPlayers > 0:
        percent = humans.count() * 100. / nPlayers
    else:
        percent = 100

    return {'outbreak_percent': min(96, percent)}
Esempio n. 2
0
    def get_context_data(self, *args, **kwargs):
        context = super(LandingPage, self).get_context_data(*args, **kwargs)

        if not self.request.user.is_authenticated():
            form = PrettyAuthForm()
        else:
            form = None

        context['login_form'] = form
        context['is_landing_page'] = True
        try:
            context['latest_meals'] = (Meal.objects.filter(
                eater__game=Game.games(
                    started=True).latest(), ).order_by('-time')[:20])
        except Game.DoesNotExist:
            context['latest_meals'] = []

        return context
Esempio n. 3
0
    def get_context_data(self, *args, **kwargs):
        context = super(LandingPage, self).get_context_data(*args, **kwargs)

        if not self.request.user.is_authenticated():
            form = PrettyAuthForm()
        else:
            form = None

        context['login_form'] = form
        context['is_landing_page'] = True
        try:
            context['latest_meals'] = (
                Meal.objects.filter(
                    eater__game=Game.games(started=True).latest(),
                ).order_by('-time')[:20])
        except Game.DoesNotExist:
            context['latest_meals'] = []

        return context
Esempio n. 4
0
 def wrapper(*args, **kwargs):
     if not Game.games(finished=False).exists():
         raise NoUnfinishedGames
     return view_func(*args, **kwargs)
Esempio n. 5
0
 def wrapper(*args, **kwargs):
     if not Game.games(started=True, finished=False).exists():
         raise NoActiveGame("There is no game in progress!")
     return view_func(*args, **kwargs)
Esempio n. 6
0
 def wrapper(*args, **kwargs):
     if not Game.games(finished=False).exists():
         raise NoUnfinishedGames
     return view_func(*args, **kwargs)
Esempio n. 7
0
 def wrapper(*args, **kwargs):
     if not Game.games(started=True, finished=False).exists():
         raise NoActiveGame("There is no game in progress!")
     return view_func(*args, **kwargs)
Esempio n. 8
0
 def wrapper(*args, **kwargs):
     if not Game.games(started=True, finished=False).exists():
         raise NoActiveGame
     return view_func(*args, **kwargs)