update dtys.views

remotes/origin/stepan-k
Stepan Krapivin 8 years ago
parent 0b37076dfd
commit b6a6fc47ea
  1. 60
      dtys/views.py
  2. 7
      static/js/dtys.js

@ -1,4 +1,4 @@
# from django.core.urlresolvers import reverse_lazy, reverse from django.core.cache import cache
from django.http import ( from django.http import (
Http404, Http404,
HttpResponse, HttpResponse,
@ -16,13 +16,28 @@ import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def get_change(current, previous): def latest_entry(request):
if current == previous: DTYSModel.objects.filter(
return 100.0 end_date__lte=timezone.now().date(),
try: end_time__lte=timezone.now().time()
return (abs(current - previous) / previous) * 100.0 ).update(is_stopped=True)
except ZeroDivisionError:
return 0 d = DTYSModel.objects.filter(
is_public=True,
is_stopped=False
)
# if d.count() != cache.get("dtysETAGCount"):
# cache.set("dtysETAGCount", d.count())
# cache.set("dtysETAG", "ETAG" + str(timezone.now().second))
# return cache.get("dtysETAG")
return "ETAG" + str(timezone.now().second)
@etag(latest_entry)
def dtys_modified(request):
return HttpResponse('')
class DTYSListView(ListView): class DTYSListView(ListView):
@ -59,40 +74,20 @@ class DTYSBuyView(DetailView):
# stop DTYS for this product # stop DTYS for this product
obj.stop() obj.stop()
new_product_var = obj.product
# Let's copy obj.product # Let's copy obj.product
new_product_var.pk = None obj.product.price = int(obj.price_stopped)
new_product_var.price = int(obj.price_stopped) obj.product.save()
new_product_var.save()
# Add to cart # Add to cart
cart = Cart(self.request) cart = Cart(self.request)
cart.add_item(CartItem(new_product_var, 1)) cart.add_item(CartItem(obj.product, 1))
return HttpResponseRedirect('/store/cart/') return HttpResponseRedirect('/store/cart/')
return HttpResponseRedirect('/dtys/') return HttpResponseRedirect('/dtys/')
def latest_entry(request):
d = DTYSModel.objects.filter(
is_public=True,
is_stopped=False
)
if d.count() > 0:
return "dtysETAG" + str(timezone.now().second)
return "dtysETAG"
@etag(latest_entry)
def dtys_modified(request):
return HttpResponse('')
class DTYSInfoView(View): class DTYSInfoView(View):
"""Ajax info""" """Ajax info"""
@ -114,7 +109,8 @@ class DTYSInfoView(View):
dtys_item = { dtys_item = {
'id': i.id, 'id': i.id,
'stopped': i.is_stopped 'stopped': i.is_stopped,
'stopped_price': i.price_stopped
} }
if not i.is_stopped: if not i.is_stopped:

@ -25,7 +25,7 @@ function countdownPrice(el, beginValue, decInSecond) {
} }
var delay = 1000; var delay = 1000;
var div = 3.0; var div = 2.0;
var timerId = setInterval(function(){ var timerId = setInterval(function(){
var val = parseFloat(counter.text()); var val = parseFloat(counter.text());
@ -60,8 +60,9 @@ function get_price() {
fake_add_to_cart_btn.show(); fake_add_to_cart_btn.show();
add_to_cart_btn.hide(); add_to_cart_btn.hide();
product.find('.price').text(i.stopped_price);
countdownPriceStop(product); countdownPriceStop(product);
console.log("price countdown stopped", i.id);
} else { } else {
product.removeClass("stopped"); product.removeClass("stopped");
product.find(".price").text(i.current_price); product.find(".price").text(i.current_price);
@ -81,7 +82,7 @@ function get_price() {
var Updater = function(){ var Updater = function(){
this.params = { this.params = {
period: 10000, period: 3000,
url: '', url: '',
onModified: function(data,x,modified){}, onModified: function(data,x,modified){},
bgPause: false bgPause: false

Loading…
Cancel
Save