Commit ce6d960a authored by Renán Sosa Guillen's avatar Renán Sosa Guillen

performance improvement

parent 98e3846f
...@@ -390,7 +390,7 @@ $(document).ready(function () { ...@@ -390,7 +390,7 @@ $(document).ready(function () {
}, },
dataType : 'json', dataType : 'json',
success : function (data) { success : function (data) {
productUUIDListCart = []; // productUUIDListCart = [];
data.product_list.forEach(function (product) { data.product_list.forEach(function (product) {
var temp_2 = document.querySelector('#product_cart_2'); var temp_2 = document.querySelector('#product_cart_2');
...@@ -420,4 +420,38 @@ $(document).ready(function () { ...@@ -420,4 +420,38 @@ $(document).ready(function () {
} }
} }
}); });
//compra de producto(s) que está(n) en el carrito
$('#purchased-product-form').submit(function (event) {
event.preventDefault();
var ul_element = document.getElementById('product-list-cart');
if (ul_element.firstChild) {
console.log("productUUIDListCart: ", productUUIDListCart);
var productObject = {};
productListGlobe.forEach(function (data) {
if (productUUIDListCart.indexOf(data.uuid) > -1) {
productObject[data.uuid] = data.product;
}
});
// L1C product download petition
$.ajax({
type : "POST",
url : purch_prod_url,
data : {
'csrfmiddlewaretoken' : document.getElementsByName('csrfmiddlewaretoken')[0].value,
'product_objects' : JSON.stringify(productObject)
},
dataType : 'json'
});
} else {
mssgModal({
title : "No products available!",
body : "There are no products charged in cart yet."
});
}
});
}); });
...@@ -252,10 +252,11 @@ ...@@ -252,10 +252,11 @@
osmap.geolocation(); osmap.geolocation();
osmap.addInteraction(); osmap.addInteraction();
var req_url = "{% url 'search-submit' %}"; // url for requesting polygon data var req_url = "{% url 'search-submit' %}"; // url for requesting polygon data
var prod_req_url = "{% url 'productList' %}" // url for requesting product data var prod_req_url = "{% url 'productList' %}"; // url for requesting product data
var img_req_url = "{% url 'img-rqst' %}" // url for requesting preview image var img_req_url = "{% url 'img-rqst' %}"; // url for requesting preview image
var prod_cart_url = "{% url 'cart-rqst' %}" // url for requesting product saving in cart var prod_cart_url = "{% url 'cart-rqst' %}"; // url for requesting product saving in cart
var prod_from_cartDB_url = "{% url 'from-cart-rqst' %}" // url for requesting product from cart table in DB var prod_from_cartDB_url = "{% url 'from-cart-rqst' %}"; // url for requesting product from cart table in DB
var purch_prod_url = "{% url 'purch-prod-rqst' %}";
</script> </script>
{% endblock %} {% endblock %}
...@@ -10,6 +10,7 @@ urlpatterns = [ ...@@ -10,6 +10,7 @@ urlpatterns = [
url(r'^searchsubmit/$', views.SearchSubmitView.as_view(), name='search-submit'), url(r'^searchsubmit/$', views.SearchSubmitView.as_view(), name='search-submit'),
url(r'^imgrequest/$', views.requestToImage, name='img-rqst'), url(r'^imgrequest/$', views.requestToImage, name='img-rqst'),
url(r'^cartrequest/$', views.saveInCart, name='cart-rqst'), url(r'^cartrequest/$', views.saveInCart, name='cart-rqst'),
url(r'^fromcartrqst/$', views.getFromCart, name='from-cart-rqst') url(r'^fromcartrqst/$', views.getFromCart, name='from-cart-rqst'),
url(r'^purchcartrqst/$', views.purchaseProduct, name='purch-prod-rqst')
] ]
...@@ -198,6 +198,29 @@ def getFromCart(request): ...@@ -198,6 +198,29 @@ def getFromCart(request):
return JsonResponse({'product_list': prod_list}) return JsonResponse({'product_list': prod_list})
#-------------------------------------------------------------------------------
def purchaseProduct(request):
"""
For now to purchase a product consists in verifying whether L1C products in cart already exist in DB.
"""
products = json.loads(request.POST['product_objects'])
orderedProducts = OrderedDict()
for p_uuid in products.keys():
PRODUCT_EXISTS = Product_l1c.objects.filter(uuid=p_uuid).exists()
if not PRODUCT_EXISTS:
orderedProducts[p_uuid] = products[p_uuid]
print orderedProducts
return HttpResponse(status=204)
## TODO: Implement a webservice in server for downloading those non-existing L1C products. ##
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# def purchaseProduct(request): # def purchaseProduct(request):
# """ # """
......
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