Skip to content
Snippets Groups Projects
Commit f9032ffe authored by Benjamin Hättasch's avatar Benjamin Hättasch Committed by Nadja Geisler
Browse files

Improve event pre-population in admin views

If there is no active event, pre-select the next upcoming event in admin views
parent 0d7f7870
No related branches found
No related tags found
No related merge requests found
import datetime from datetime import timedelta
from django.utils.datetime_safe import datetime
import itertools import itertools
from django.db import models from django.db import models
...@@ -47,7 +49,12 @@ class Event(models.Model): ...@@ -47,7 +49,12 @@ class Event(models.Model):
@staticmethod @staticmethod
def get_next_active(): def get_next_active():
return Event.objects.filter(active=True).order_by('start').first() # Get first active event taking place
event = Event.objects.filter(active=True).order_by('start').first()
# No active event? Return the next event taking place
if event is None:
event = Event.objects.order_by('start').filter(start__gt=datetime.now()).first()
return event
class AKOwner(models.Model): class AKOwner(models.Model):
...@@ -313,7 +320,7 @@ class AKSlot(models.Model): ...@@ -313,7 +320,7 @@ class AKSlot(models.Model):
""" """
Retrieve end time of the AK slot Retrieve end time of the AK slot
""" """
return self.start + datetime.timedelta(hours=float(self.duration)) return self.start + timedelta(hours=float(self.duration))
@property @property
def seconds_since_last_update(self): def seconds_since_last_update(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment