Commit 3111e161 authored by Patrick's avatar Patrick
Browse files

More "aggresive" cache into order form : get user and amount via ajax.

parent 584c22ba
......@@ -937,9 +937,9 @@ class PermanenceDone(Permanence):
class OfferItem(TranslatableModel):
translations = TranslatedFields(
cache_part_a = HTMLField(default="", blank=True),
cache_part_b = HTMLField(default="", blank=True),
cache_part_c = HTMLField(default="", blank=True)
cache_part_a=HTMLField(default="", blank=True),
cache_part_b=HTMLField(default="", blank=True),
cache_part_c=HTMLField(default="", blank=True)
)
permanence = models.ForeignKey(
Permanence, verbose_name=REPANIER_PERMANENCE_NAME, on_delete=models.PROTECT)
......
......@@ -80,19 +80,32 @@ def open(permanence_id, current_site_name):
else:
producer_set = Producer.objects.none()
cur_language = translation.get_language()
# try:
# for language in settings.LANGUAGES:
# translation.activate(language[0])
# if permanence.has_translation(language[0]):
# permanence.cache_part_d = render_to_string('repanier/cache_part_d.html',
# {'producer_set': producer_set, 'departementforcustomer_set': departementforcustomer_set})
# permanence.save()
# for offer_item in OfferItem.objects.filter(permanence_id=permanence_id).order_by():
# if offer_item.has_translation(language[0]):
# offer_item.cache_part_a = render_to_string('repanier/cache_part_a.html', {'offer': offer_item})
# offer_item.cache_part_b = render_to_string('repanier/cache_part_b.html', {'offer': offer_item})
# offer_item.cache_part_c = render_to_string('repanier/cache_part_c.html', {'offer': offer_item})
# offer_item.save()
# finally:
# translation.activate(cur_language)
try:
for language in settings.LANGUAGES:
translation.activate(language[0])
if permanence.has_translation(language[0]):
permanence.cache_part_d = render_to_string('repanier/cache_part_d.html',
{'producer_set': producer_set, 'departementforcustomer_set': departementforcustomer_set})
permanence.cache_part_d = render_to_string('repanier/cache_part_d.html',
{'producer_set': producer_set, 'departementforcustomer_set': departementforcustomer_set})
permanence.save()
if offer_item.has_translation(language[0]):
for offer_item in OfferItem.objects.filter(permanence_id=permanence_id).order_by():
offer_item.cache_part_a = render_to_string('repanier/cache_part_a.html', {'offer': offer_item})
offer_item.cache_part_b = render_to_string('repanier/cache_part_b.html', {'offer': offer_item})
offer_item.cache_part_c = render_to_string('repanier/cache_part_c.html', {'offer': offer_item})
offer_item.save()
for offer_item in OfferItem.objects.filter(permanence_id=permanence_id).order_by():
offer_item.cache_part_a = render_to_string('repanier/cache_part_a.html', {'offer': offer_item})
offer_item.cache_part_b = render_to_string('repanier/cache_part_b.html', {'offer': offer_item})
offer_item.cache_part_c = render_to_string('repanier/cache_part_c.html', {'offer': offer_item})
offer_item.save()
finally:
translation.activate(cur_language)
......@@ -213,15 +226,13 @@ def close(permanence_id, current_site_name):
try:
for language in settings.LANGUAGES:
translation.activate(language[0])
if permanence.has_translation(language[0]):
permanence.cache_part_d = ""
permanence.save()
permanence.cache_part_d = ""
permanence.save()
for offer_item in OfferItem.objects.filter(permanence_id=permanence_id).order_by():
if offer_item.has_translation(language[0]):
offer_item.cache_part_a = ""
offer_item.cache_part_b = ""
offer_item.cache_part_c = ""
offer_item.save()
offer_item.cache_part_a = ""
offer_item.cache_part_b = ""
offer_item.cache_part_c = ""
offer_item.save()
finally:
translation.activate(cur_language)
#
......
......@@ -275,6 +275,34 @@
});
{% endfor %}
{% endif %}
lien = '{% url 'order_name' %}';
$.ajax({
url: lien,
cache: false,
async: false,
success: function (result) {
$("#my_name").html(result);
},
error: function (result) {
$("#my_name").html("{% trans "Retry5" %}");
}
});
lien = '{% url 'basket_amount' %}?permanence=' + {{ permanence.id|stringformat:"d" }};
$.ajax({
url: lien,
cache: false,
async: false,
success: function (result) {
$("#my_basket").html(result);
$("#prepared_amount").html(result);
$("#prepared_amount_visible_xs").html(result);
},
error: function (result) {
$("#my_basket").html("{% trans "Retry 6" %}");
$("#prepared_amount").html("{% trans "Retry 6" %}");
$("#prepared_amount_visible_xs").html("{% trans "Retry 6" %}");
}
});
$("#li_my_basket").show();
$("select").mouseenter(function (event) {
var lien = "";
......
......@@ -192,11 +192,11 @@ def get_display(qty=0, order_average_weight=0, order_unit=PRODUCT_ORDER_UNIT_PC,
return qty_display, price_display, price
def get_user_order_amount(permanence, user=None):
def get_user_order_amount(permanence_id, user=None):
a_total_price_with_tax = 0
if user is not None:
customer_order_set = CustomerOrder.objects.filter(
permanence_id=permanence.id,
permanence_id=permanence_id,
customer__user=user)[:1]
if customer_order_set:
a_total_price_with_tax = customer_order_set[0].total_price_with_tax
......
......@@ -9,8 +9,11 @@ from views import PermanenceView
urlpatterns = patterns('',
url(r'^contact/$', views.contact_form, name='contact_form'),
# url(r'^order/(\w+)/$', cache_page(60*60)(OrderView.as_view()), name='order_view'),
url(r'^order/(\w+)/$', cache_page(60*60)(OrderView.as_view()), name='order_view'),
url(r'^order/(\w+)/$', login_required(cache_page(60*60)(OrderView.as_view())), name='order_view'),
# url(r'^order/(\w+)/$', login_required((OrderView.as_view())), name='order_view'),
url(r'^order-name/$', views.order_name_ajax, name='order_name'),
url(r'^basket-amount/$', views.basket_amount_ajax, name='basket_amount'),
url(r'^basket/(\w+)/$', login_required(OrderViewWithoutCache.as_view()), name='basket_view'),
url(r'^order-ajax/$', views.order_form_ajax, name='order_form_ajax'),
url(r'^ajax/order-init/$', views.ajax_order_init, name='ajax_order_init'),
......
......@@ -92,6 +92,36 @@ def product_form_ajax(request):
return HttpResponseRedirect('/')
@login_required()
@never_cache
def order_name_ajax(request):
if request.is_ajax():
if request.method == 'GET':
user = request.user
customer = Customer.objects.filter(
user_id=user.id, is_active=True, may_order=True).order_by().first()
if customer:
return HttpResponse(customer)
# Not an AJAX, GET request
return HttpResponseRedirect('/')
@login_required()
@never_cache
def basket_amount_ajax(request):
if request.is_ajax():
if request.method == 'GET':
if 'permanence' in request.GET:
p_permanence_id = request.GET['permanence']
user = request.user
customer = Customer.objects.filter(
user_id=user.id, is_active=True, may_order=True).order_by().first()
if customer:
return HttpResponse(get_user_order_amount(p_permanence_id,user=user))
# Not an AJAX, GET request
return HttpResponseRedirect('/')
@login_required()
# @never_cache
def order_form_ajax(request):
......@@ -296,6 +326,7 @@ class OrderView(ListView):
self.producer_id = 'all'
self.departementforcustomer_id = 'all'
# @method_decorator(never_cache)
def dispatch(self, request, *args, **kwargs):
if request.user.is_authenticated():
self.user = request.user
......@@ -338,8 +369,8 @@ class OrderView(ListView):
context['departementforcustomer_set'] = departementforcustomer_set
context['departementforcustomer_id'] = self.departementforcustomer_id
context['offeritem_id'] = self.offeritem_id
context['prepared_amount'] = get_user_order_amount(self.permanence,
user=self.user) # + ' &euro; <span class="glyphicon glyphicon-shopping-cart"></span>'
context['prepared_amount'] = get_user_order_amount(self.permanence.id,
user=self.user)
context['staff_order'] = Staff.objects.filter(is_reply_to_order_email=True).order_by().first()
return context
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment