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 (
Http404,
HttpResponse,
@ -16,13 +16,28 @@ import logging
log = logging.getLogger(__name__)
def get_change(current, previous):
if current == previous:
return 100.0
try:
return (abs(current - previous) / previous) * 100.0
except ZeroDivisionError:
return 0
def latest_entry(request):
DTYSModel.objects.filter(
end_date__lte=timezone.now().date(),
end_time__lte=timezone.now().time()
).update(is_stopped=True)
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):
@ -59,40 +74,20 @@ class DTYSBuyView(DetailView):
# stop DTYS for this product
obj.stop()
new_product_var = obj.product
# Let's copy obj.product
new_product_var.pk = None
new_product_var.price = int(obj.price_stopped)
new_product_var.save()
obj.product.price = int(obj.price_stopped)
obj.product.save()
# Add to cart
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('/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):
"""Ajax info"""
@ -114,7 +109,8 @@ class DTYSInfoView(View):
dtys_item = {
'id': i.id,
'stopped': i.is_stopped
'stopped': i.is_stopped,
'stopped_price': i.price_stopped
}
if not i.is_stopped:

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

Loading…
Cancel
Save