commitbb5081a78bAuthor: Xeniac <xeniac@posteo.at> Date: Thu Nov 23 22:02:40 2017 +0100 Added a setting where the exported excel files should be stored. Added a option to send the exported excel as mail attachment. commit854fd38740Author: Xeniac <xeniac@posteo.at> Date: Thu Nov 23 22:01:38 2017 +0100 Fixed: enumerate the Seasonrankings starting with 1 Fixed: Logging error when a value changed from/to None commit6de1ecb102Author: Christian Berg <xeniac@posteo.at> Date: Thu Nov 23 14:15:36 2017 +0100 add a latest method to query the latest x events commitbf12060c3bAuthor: Christian Berg <xeniac@posteo.at> Date: Thu Nov 23 14:15:12 2017 +0100 add a latest method to query the latest x events commit5ad628f33aAuthor: Christian Berg <xeniac@posteo.at> Date: Mon Nov 20 07:47:47 2017 +0100 Changed PlayerDanScore to only list non-legacy hanchans commit36272c60d6Author: Christian Berg <xeniac@posteo.at> Date: Mon Nov 20 07:42:44 2017 +0100 fixed import of MIN_HANCHANS_FOR_LADDER that moved to settings commitc428f6ed1fAuthor: Christian Berg <xeniac@posteo.at> Date: Mon Nov 20 07:41:04 2017 +0100 Updated docstrings for new since and until kwargs commit9276e97c36Author: Christian Berg <xeniac@posteo.at> Date: Mon Nov 20 07:33:54 2017 +0100 added a since parameter to the hanchan queries to return only hanchans since the give date and time commitfd244f10e8Author: Christian Berg <xeniac@posteo.at> Date: Sun Nov 19 16:55:10 2017 +0100 new command: resetdanranking YYYY-MM-DD, sets every dan player to 1st dan with zero dan_points at the given date. commit0a45cf1fd8Author: Christian Berg <xeniac@posteo.at> Date: Sun Nov 19 16:14:59 2017 +0100 added new fields to KyuDanRanking that allow to pick up the calculation from the last state of the KyuDanRanking. last_hanchan_date: it contains the start of the latest hanchan content for this players ranking. wins_in_row: to save the currents wins in a row Added option to calcuclate rankings until a given datetime.
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""Django ORM Managers for the event models."""
|
|
from django.db import models
|
|
from django.utils.timezone import now
|
|
|
|
|
|
class EventManager(models.Manager):
|
|
"""Django ORM Manager that adds some queryshortcuts to Event Models."""
|
|
|
|
def get_queryset(self):
|
|
"""Joins the location info to every event query."""
|
|
return super(EventManager, self).get_queryset().select_related(
|
|
'location')
|
|
|
|
def current_event(self):
|
|
"""Returns the event that is currently running."""
|
|
try:
|
|
current = self.filter(start__lte=now())
|
|
current = current.filter(end__gte=now())
|
|
return current.order_by('start', 'end')[0]
|
|
except IndexError:
|
|
return None
|
|
|
|
def next_event(self):
|
|
"""Returns the next upcoming event."""
|
|
try:
|
|
return self.filter(start__gt=now()).order_by('start', 'end')[0]
|
|
except IndexError:
|
|
return None
|
|
|
|
def archive(self):
|
|
"""Returns all past events."""
|
|
return self.filter(start__lt=now())
|
|
|
|
def latest(self, limit=None):
|
|
result = self.filter(start__lt=now()).order_by('-start', '-end')
|
|
return result[0:limit] if limit else result
|
|
|
|
def upcoming(self, limit=None):
|
|
"""Returns the next 'limit' upcoming events.
|
|
|
|
:param limit: how many upcoming events should be returned?
|
|
"""
|
|
result = self.filter(start__gt=now()).order_by('start', 'end')
|
|
return result[0:limit] if limit else result
|