X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/6e0b282242bf227d1dba35b2748b7cadb48741db..ad39c2501159fa52e980c95af3e735e36b459c15:/apps/waiter/views.py?ds=inline diff --git a/apps/waiter/views.py b/apps/waiter/views.py index 81cd3b49d..0892ca91b 100644 --- a/apps/waiter/views.py +++ b/apps/waiter/views.py @@ -1,12 +1,26 @@ +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# from os.path import join from waiter.models import WaitedFile from waiter.settings import WAITER_URL -from django.shortcuts import get_object_or_404, render, redirect +from django.shortcuts import render, get_object_or_404 +from django.http import HttpResponse +from django.views.decorators.cache import never_cache + +@never_cache def wait(request, path): if WaitedFile.exists(path): file_url = join(WAITER_URL, path) else: - waiting_for = get_object_or_404(WaitedFile, path=path) - # TODO: check if not stale, inform the user and send some mail if so. - return render(request, "waiter/wait.html", locals()) + file_url = "" + waiting = get_object_or_404(WaitedFile, path=path) + if waiting.is_stale(): + waiting = None + + if request.is_ajax(): + return HttpResponse(file_url) + else: + return render(request, "waiter/wait.html", locals())