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 = [
os.path.join(BASE_DIR, "static"),
]
TEMPLATES = [

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

@ -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<pk>\d+)/$', DTYSBuyView.as_view())
)

@ -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()

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

Loading…
Cancel
Save