Camp redirect has to account for an ongoing camp.
This commit is contained in:
parent
385e98d84f
commit
dd9ef2380a
|
@ -12,14 +12,23 @@ logger = logging.getLogger("bornhack.%s" % __name__)
|
||||||
class CampRedirectView(CampViewMixin, View):
|
class CampRedirectView(CampViewMixin, View):
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
now = timezone.now()
|
||||||
|
|
||||||
|
try:
|
||||||
|
camp = Camp.objects.get(
|
||||||
|
camp__contains=now
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.debug("Redirecting to camp '%s' for page '%s' because it is now!" % (camp.slug, kwargs['page']))
|
||||||
|
except Camp.DoesNotExist:
|
||||||
# find the closest camp in the past
|
# find the closest camp in the past
|
||||||
prevcamp = Camp.objects.filter(
|
prevcamp = Camp.objects.filter(
|
||||||
camp__endswith__lt=timezone.now()
|
camp__endswith__lt=now
|
||||||
).order_by('-camp')[0]
|
).order_by('-camp')[0]
|
||||||
|
|
||||||
# find the closest upcoming camp
|
# find the closest upcoming camp
|
||||||
nextcamp = Camp.objects.filter(
|
nextcamp = Camp.objects.filter(
|
||||||
camp__startswith__gt=timezone.now()
|
camp__startswith__gt=now
|
||||||
).order_by('camp')[0]
|
).order_by('camp')[0]
|
||||||
|
|
||||||
# find the number of days between the two camps
|
# find the number of days between the two camps
|
||||||
|
@ -38,6 +47,7 @@ class CampRedirectView(CampViewMixin, View):
|
||||||
camp = prevcamp
|
camp = prevcamp
|
||||||
|
|
||||||
logger.debug("Redirecting to camp '%s' for page '%s' because %s%% of the time between the camps passed" % (camp.slug, kwargs['page'], int(percentpassed)))
|
logger.debug("Redirecting to camp '%s' for page '%s' because %s%% of the time between the camps passed" % (camp.slug, kwargs['page'], int(percentpassed)))
|
||||||
|
|
||||||
return redirect(kwargs['page'], camp_slug=camp.slug)
|
return redirect(kwargs['page'], camp_slug=camp.slug)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue