diff --git a/batiskaf/settings.py b/batiskaf/settings.py index 081d34a..7621945 100644 --- a/batiskaf/settings.py +++ b/batiskaf/settings.py @@ -157,7 +157,6 @@ STATICFILES_FINDERS = [ STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), - ] TEMPLATES = [ diff --git a/batiskaf/templates/jinja2/dtys/index.jinja b/batiskaf/templates/jinja2/dtys/index.jinja index 62ba952..9d83261 100644 --- a/batiskaf/templates/jinja2/dtys/index.jinja +++ b/batiskaf/templates/jinja2/dtys/index.jinja @@ -23,10 +23,7 @@ {% for object in object_list %} {% include "includes/dtys_product_thumb.jinja" with context %} {% endfor %} - - - {% endblock content %} diff --git a/dtys/urls.py b/dtys/urls.py index 5803fab..25921b0 100644 --- a/dtys/urls.py +++ b/dtys/urls.py @@ -6,7 +6,7 @@ from .views import DTYSListView, DTYSInfoView, DTYSBuyView, dtys_modified urlpatterns = patterns( '', url(r'^$', DTYSListView.as_view()), - url(r'^etg/$', dtys_modified), + url(r'^updates$', dtys_modified), url(r'^info/$', DTYSInfoView.as_view()), url(r'^buy/(?P\d+)/$', DTYSBuyView.as_view()) ) diff --git a/dtys/views.py b/dtys/views.py index 12eb478..a1ff576 100644 --- a/dtys/views.py +++ b/dtys/views.py @@ -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() diff --git a/static/js/dtys.js b/static/js/dtys.js index ed4be47..b3bedfd 100644 --- a/static/js/dtys.js +++ b/static/js/dtys.js @@ -152,7 +152,7 @@ $(function(){ get_price(); upd.init({ - url: "/dtys/etg/", + url: "/dtys/updates", onModified: function(data, x, modified) { get_price(); }