improve dtys etag updates

master
Stepan Krapivin 8 years ago
parent 1b00dd3df7
commit 16608ac882
  1. 1
      batiskaf/settings.py
  2. 3
      batiskaf/templates/jinja2/dtys/index.jinja
  3. 2
      dtys/urls.py
  4. 33
      dtys/views.py
  5. 2
      static/js/dtys.js

@ -157,7 +157,6 @@ STATICFILES_FINDERS = [
STATICFILES_DIRS = [ STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"), os.path.join(BASE_DIR, "static"),
] ]
TEMPLATES = [ TEMPLATES = [

@ -23,10 +23,7 @@
{% for object in object_list %} {% for object in object_list %}
{% include "includes/dtys_product_thumb.jinja" with context %} {% include "includes/dtys_product_thumb.jinja" with context %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
</div> </div>
{% endblock content %} {% endblock content %}

@ -6,7 +6,7 @@ from .views import DTYSListView, DTYSInfoView, DTYSBuyView, dtys_modified
urlpatterns = patterns( urlpatterns = patterns(
'', '',
url(r'^$', DTYSListView.as_view()), url(r'^$', DTYSListView.as_view()),
url(r'^etg/$', dtys_modified), url(r'^updates$', dtys_modified),
url(r'^info/$', DTYSInfoView.as_view()), url(r'^info/$', DTYSInfoView.as_view()),
url(r'^buy/(?P<pk>\d+)/$', DTYSBuyView.as_view()) url(r'^buy/(?P<pk>\d+)/$', DTYSBuyView.as_view())
) )

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

@ -152,7 +152,7 @@ $(function(){
get_price(); get_price();
upd.init({ upd.init({
url: "/dtys/etg/", url: "/dtys/updates",
onModified: function(data, x, modified) { onModified: function(data, x, modified) {
get_price(); get_price();
} }

Loading…
Cancel
Save