Ejemplo n.º 1
0
    def get_context_data(self, **context):
        user = getattr(self.request, 'user', None)
        context['user'] = user
        if not user:
            context['no_user'] = True
            return context
        try:
            player = user.player
        except (AttributeError, ObjectDoesNotExist):
            context['no_player'] = True
            return context
        if user.is_anonymous():
            context['is_anonymous'] = True
            return context

        current = Campaign.current_campaigns()
        past = Campaign.past_campaigns()
        upcoming = Campaign.upcoming_campaigns()
        context['campaign_lists'] = [
            {'campaigns': self.campaign_infos(player, current),
             'title': u'Current Campaign'},
            {'campaigns': self.campaign_infos(player, upcoming),
             'title': u'Upcoming Campaigns'},
            {'campaigns': self.campaign_infos(player, past),
             'title': u'Past Campaigns'}]

        return context
Ejemplo n.º 2
0
 def test_current_campaigns(self):
     now = timezone.now()
     self._create_campaign(u'Campaign in the past',
                           start=(now - timedelta(days=20)),
                           end=(now - timedelta(days=10)))
     self._create_campaign(u'Campaign started, not yet ended',
                           start=now - timedelta(days=5),
                           end=None)
     # campaign not started yet
     self._create_campaign(u'Campaign not yet started',
                           start=now + timedelta(days=20),
                           end=None)
     current_campaigns = Campaign.current_campaigns()
     self.assertEqual(len(current_campaigns), 1)
     self.assertEqual(current_campaigns[0].title,
                      u'Campaign started, not yet ended')