Commits

David Krauth  committed 8569bfd

Incremental update

  • Participants
  • Parent commits 82b09d6

Comments (0)

Files changed (3)

     #---------------------------------------------------------------------------
     @property
     def end_time(self):
-        self.last_game.kickoff + GAME_DURATION
+        self.last_game.kickoff.end_time
 
     #---------------------------------------------------------------------------
     @property
         for game in self.nflgame_set.incomplete(home__abbr__in=completed.keys()):
             result = completed.get(game.home.abbr, None)
             if result:
-                winner = game.home if game.home.abbr == result['winner'] else game.away
-                game.winner = winner
+                winner = result['winner']
+                game.winner = (
+                    game.home if game.home.abbr == winner
+                    else game.away if game.away.abbr == winner else None
+                )
                 count += 1
 
         if count:
         
     #---------------------------------------------------------------------------
     def _set_winner(self, team):
-        if team  == self.away:
+        if team is None:
+            self.status = self.TIE_STATUS
+        elif team  == self.away:
             self.status = self.AWAY_WIN_STATUS
         elif team == self.home:
             self.status = self.HOME_WIN_STATUS
     #---------------------------------------------------------------------------
     @property
     def end_time(self):
-        return self.kickoff + GAME_DURATION
+        return self.kickoff + NFL_GAME_DURATION
         
     #---------------------------------------------------------------------------
     @property
                 if activity_status.balance > 0:
                     self.autocreate(p.user, week, p.autopick)
 
+    #---------------------------------------------------------------------------
+    def update_results(self, week=None):
+        week = week or GameWeek.objects.current_week()
+        
 
 #===============================================================================
 class WeeklyPick(models.Model):

File templates/nfl/base.html

     $(document).ready(function() {
         var score_calls = 0;
         var menus = document.getElementById('menus');
-        var original_offset_y = menus.offsetTop;
-
-        document.addEventListener('scroll', function(e) {
-            window.scrollY >= original_offset_y 
-                ? menus.classList.add('fixed')
-                : menus.classList.remove('fixed');
-        });
+        if(false) {
+            document.addEventListener('scroll', function(e) {
+                window.scrollY >= menus.offsetTop 
+                    ? menus.classList.add('fixed')
+                    : menus.classList.remove('fixed');
+            });
+        }
 
         function score_strip() {
             $.get('/api/v1/scores/', function(data) {
                 $('#scorestrip').html(data).attr('data-load', ++score_calls)
             });
-            setTimeout(score_strip, 1000 * 120 + 10)
+            setTimeout(score_strip, 1000 * 60 * 5 + 10)
         }
         score_strip();
         Picks.teams();

File views/nfl_views.py

     'http://www.nfl.com/rss/rsslanding?searchString=home'
 )
 
+SMACK_TALK_ENABLED = getattr(settings, 'NFL_SMACK_TALK', False)
 
 #-------------------------------------------------------------------------------
 def redirect_reverse(*args, **kws):
 
 
 #-------------------------------------------------------------------------------
-def _week_results(request, week):
-    picks = list(football.WeeklyPick.objects.select_related().filter(week=week))
-    data = dict(week=week, weekly_results=football.sorted_standings(picks))
-    return request_to_response(request, 'nfl/results/week.html', data)
-
-
-#-------------------------------------------------------------------------------
 def _show_weekly_picks(request, week):
     wp = football.WeeklyPick.objects.for_user_and_week(request.user, week)
     data = dict(game_week=week, picks=wp)
 #  Results
 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
-#-------------------------------------------------------------------------------
-@login_required
-def results(request):
-    gw = football.GameWeek.objects.current_week()
-    return _week_results(request, gw) if gw else redirect_reverse(
-        'nfl-playoffs-results',
-        args=(football.NFL_CURRENT_SEASON,)
-    )
-
 
 #-------------------------------------------------------------------------------
-@login_required
-def results_history(request):
-    return request_to_response(request, 'nfl/results/history.html', {})
+def _week_results(request, week, **extras):
+    picks = list(football.WeeklyPick.objects.select_related().filter(week=week))
+    data = dict(extras, week=week, weekly_results=football.sorted_standings(picks))
+    return request_to_response(request, 'nfl/results/week.html', data)
 
 
 #-------------------------------------------------------------------------------
-@login_required
-def results_by_season(request, season):
-    summaries = football.WeekSummary.objects.filter(week__season=season)
-    total_tax = summaries.aggregate(taxes=models.Sum('taxes'))['taxes']
-    data = dict(season=season, summaries=summaries, total_tax=total_tax)
-    return request_to_response(request, 'nfl/results/season.html', data)
-
-
-#-------------------------------------------------------------------------------
-@login_required
-def results_by_week(request, season, week):
-    week = get_object_or_404(football.GameWeek, season=season, week=week)
-    week.update_results()
-    
+def _smack_talk(request, week):
     if request.method == 'POST':
         form = forms.WeekResultCommentForm(request.POST)
         if form.is_valid():
             return http.HttpResponseRedirect(request.path)
     else:
         form = forms.CommentForm()
+    
+    return _week_results(request, week, form=form)
 
+
+#-------------------------------------------------------------------------------
+@login_required
+def results(request):
+    week = football.GameWeek.objects.current_week()
+    if not week:
+        return redirect_reverse(
+            'nfl-playoffs-results',
+            args=(football.NFL_CURRENT_SEASON,)
+        )
+
+    if week.in_progress:
+        week.update_results()
+    
+    if SMACK_TALK_ENABLED:
+        return _smack_talk(request, week)
+
+    return _week_results(request, week)
+
+
+#-------------------------------------------------------------------------------
+@login_required
+def results_history(request):
+    return request_to_response(request, 'nfl/results/history.html', {})
+
+
+#-------------------------------------------------------------------------------
+@login_required
+def results_by_season(request, season):
+    summaries = football.WeekSummary.objects.filter(week__season=season)
+    total_tax = summaries.aggregate(taxes=models.Sum('taxes'))['taxes']
+    data = dict(season=season, summaries=summaries, total_tax=total_tax)
+    return request_to_response(request, 'nfl/results/season.html', data)
+
+
+#-------------------------------------------------------------------------------
+@login_required
+def results_by_week(request, season, week):
+    week = get_object_or_404(football.GameWeek, season=season, week=week)
     return _week_results(request, week)
 
 
 #-------------------------------------------------------------------------------
 @login_required
 def picks(request):
-    gw = football.GameWeek.objects.current_week()
-    return _weekly_picks(request, gw) if gw else redirect_reverse(
+    week = football.GameWeek.objects.current_week()
+    return _weekly_picks(request, week) if week else redirect_reverse(
         'nfl-playoffs-picks',
         args=(football.NFL_CURRENT_SEASON,)
     )
         go_to = reverse('nfl-game-week', args=(week.season, week.week))
         if 'kickoff' in request.POST:
             football.WeeklyPick.objects.week_kickoff(week)
+            week.update_results()
             user_message(request.user, 'Week kickoff successful')
             return http.HttpResponseRedirect(go_to)