|
|
|
|
@ -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: |
|
|
|
|
|