Commits

Ruslan Keba committed 4092a68

Event: get_latest moved to model

Comments (0)

Files changed (2)

 # -*- coding: utf-8 -*-
 
+from datetime import datetime, timedelta
+
 from django.db import models
 from django.db.models import permalink
 from django.utils.safestring import mark_safe
     def humanized_date_end(self):
         return humanized_date(self.date_end) if self.date_end else None
 
+    @staticmethod
+    def get_latest(club=None):
+        if not club:
+            club = Club.get_default()
+        # select events with date_begin>now-5days
+        from_date = datetime.now()-timedelta(days=5)
+        events = Event.objects.filter(club=club).filter(date_begin__gte=from_date).order_by('-date_begin')
 
+        if not events:
+            # otherwise just last 10 events
+            events = Event.objects.filter(club=club).order_by('-date_begin')[:10]
+
+        return events
+
+
+
+
+
 
 from models import Club, Event
 
-def _get_last_events(club):
-    # select events with date_begin>now-5days
-    from_date = datetime.now()-timedelta(days=5)
-    events = Event.objects.filter(club=club).filter(date_begin__gte=from_date).order_by('-date_begin')
-
-    if not events:
-        # otherwise just last 10 events
-        events = Event.objects.filter(club=club).order_by('-date_begin')[:10]
-
-    return events
-
-
 @cache_control(public=True)
 @cache_page(30*60)
 def event_list(request, club=None, template=None):