|
|
|
|
@ -1,3 +1,5 @@ |
|
|
|
|
import os |
|
|
|
|
|
|
|
|
|
from django.conf import settings |
|
|
|
|
from django.http import ( |
|
|
|
|
Http404, |
|
|
|
|
@ -5,6 +7,7 @@ from django.http import ( |
|
|
|
|
HttpResponseRedirect, |
|
|
|
|
JsonResponse, |
|
|
|
|
) |
|
|
|
|
from django.core.cache import cache |
|
|
|
|
from django.utils import timezone |
|
|
|
|
from django.views.decorators.http import etag |
|
|
|
|
from django.views.generic import View, ListView, DetailView |
|
|
|
|
@ -16,6 +19,20 @@ import logging |
|
|
|
|
log = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DTYS_UPDATE_FILE = os.path.join(settings.MEDIA_ROOT, "dtys_update") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_dtys_etag(): |
|
|
|
|
fhandle = open(DTYS_UPDATE_FILE, 'a') |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
os.utime(DTYS_UPDATE_FILE, None) |
|
|
|
|
except FileNotFoundError: |
|
|
|
|
open(DTYS_UPDATE_FILE, 'a').close() |
|
|
|
|
finally: |
|
|
|
|
fhandle.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def latest_entry(request): |
|
|
|
|
DTYSModel.objects.filter( |
|
|
|
|
end_date__lte=timezone.now().date(), |
|
|
|
|
@ -27,12 +44,16 @@ def latest_entry(request): |
|
|
|
|
is_stopped=False |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
# if d.count() != cache.get("dtysETAGCount"): |
|
|
|
|
# cache.set("dtysETAGCount", d.count()) |
|
|
|
|
# cache.set("dtysETAG", "ETAG" + str(timezone.now().second)) |
|
|
|
|
if d.count() != cache.get("dtysETAGCount"): |
|
|
|
|
cache.set("dtysETAGCount", d.count()) |
|
|
|
|
update_dtys_etag() |
|
|
|
|
|
|
|
|
|
if not os.path.exists(DTYS_UPDATE_FILE): |
|
|
|
|
update_dtys_etag() |
|
|
|
|
|
|
|
|
|
# return cache.get("dtysETAG") |
|
|
|
|
return "ETAG" + str(timezone.now().second) |
|
|
|
|
modified = str(os.path.getmtime(DTYS_UPDATE_FILE)) |
|
|
|
|
|
|
|
|
|
return modified |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@etag(latest_entry) |
|
|
|
|
@ -87,6 +108,8 @@ class DTYSBuyView(DetailView): |
|
|
|
|
from store.models import ProductVariation |
|
|
|
|
from .tasks import return_dtys |
|
|
|
|
|
|
|
|
|
update_dtys_etag() |
|
|
|
|
|
|
|
|
|
# stop DTYS for this product |
|
|
|
|
obj.stop() |
|
|
|
|
|
|
|
|
|
|