Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GeoInt_SIDT
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoInt_SIDT
Commits
b77d7f55
Commit
b77d7f55
authored
Aug 03, 2018
by
Renán Sosa Guillen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cart management
parent
73cce675
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
153 additions
and
20 deletions
+153
-20
dataRetrieval.js
catalog/static/js/dataRetrieval.js
+42
-3
base_top.html
catalog/templates/base_top.html
+14
-11
map.html
catalog/templates/map.html
+5
-3
urls.py
catalog/urls.py
+3
-1
views.py
catalog/views.py
+89
-2
No files found.
catalog/static/js/dataRetrieval.js
View file @
b77d7f55
...
@@ -151,7 +151,7 @@ $(document).ready(function () {
...
@@ -151,7 +151,7 @@ $(document).ready(function () {
var
typingInterval
=
800
;
//milliseconds
var
typingInterval
=
800
;
//milliseconds
var
productListPrev
=
[];
var
productListPrev
=
[];
var
productListGlobe
=
[];
var
productListGlobe
=
[];
var
productListCart
=
{}
;
// this array represent DB where products will be stored
var
productListCart
=
[]
;
// this array represent DB where products will be stored
// On keyup, start the contdown
// On keyup, start the contdown
$
(
'#ajax-input'
).
on
(
'input'
,
function
()
{
$
(
'#ajax-input'
).
on
(
'input'
,
function
()
{
...
@@ -261,6 +261,7 @@ $(document).ready(function () {
...
@@ -261,6 +261,7 @@ $(document).ready(function () {
// agrega producto al carrito
$
(
'#product-to-cart-form'
).
submit
(
function
(
event
)
{
$
(
'#product-to-cart-form'
).
submit
(
function
(
event
)
{
var
submit_data
=
$
(
'#product-to-cart-form'
).
serialize
();
var
submit_data
=
$
(
'#product-to-cart-form'
).
serialize
();
...
@@ -274,12 +275,13 @@ $(document).ready(function () {
...
@@ -274,12 +275,13 @@ $(document).ready(function () {
var
submit_data_array
=
submit_data
.
split
(
"&product_selected="
);
var
submit_data_array
=
submit_data
.
split
(
"&product_selected="
);
PRODUCT_COUNTER
+=
1
;
// this variable counts the number of products in shopping cart
PRODUCT_COUNTER
+=
1
;
// this variable counts the number of products in shopping cart
PRODUCT_COUNTER_STR
=
PRODUCT_COUNTER
.
toString
();
var
temp_1
=
document
.
querySelector
(
'#product_cart_1'
);
var
temp_1
=
document
.
querySelector
(
'#product_cart_1'
);
var
prod_id
=
temp_1
.
content
.
querySelectorAll
(
'ul'
)[
1
].
id
+
"-"
+
PRODUCT_COUNTER
.
toString
()
;
var
prod_id
=
temp_1
.
content
.
querySelectorAll
(
'ul'
)[
1
].
id
+
"-"
+
PRODUCT_COUNTER
_STR
;
// filling template
// filling template
temp_1
.
content
.
querySelector
(
'span'
).
textContent
=
"Product "
+
PRODUCT_COUNTER
.
toString
()
;
temp_1
.
content
.
querySelector
(
'span'
).
textContent
=
"Product "
+
PRODUCT_COUNTER
_STR
;
temp_1
.
content
.
querySelectorAll
(
'ul'
)[
1
].
id
=
prod_id
;
temp_1
.
content
.
querySelectorAll
(
'ul'
)[
1
].
id
=
prod_id
;
var
clone_1
=
document
.
importNode
(
temp_1
.
content
,
true
);
var
clone_1
=
document
.
importNode
(
temp_1
.
content
,
true
);
...
@@ -292,6 +294,8 @@ $(document).ready(function () {
...
@@ -292,6 +294,8 @@ $(document).ready(function () {
if
(
submit_data_array
.
indexOf
(
data
.
id
)
>
-
1
)
{
if
(
submit_data_array
.
indexOf
(
data
.
id
)
>
-
1
)
{
console
.
log
(
"DATA sí esta: "
,
data
.
id
);
console
.
log
(
"DATA sí esta: "
,
data
.
id
);
console
.
log
(
"SS: "
,
data
.
product
.
size
);
console
.
log
(
"SS: "
,
data
.
product
.
size
);
productListCart
.
push
(
data
.
product
);
// productListCart.push(data.id);
erase_product_list_globe_by_id
(
data
.
id
);
erase_product_list_globe_by_id
(
data
.
id
);
var
temp_2
=
document
.
querySelector
(
'#product_cart_2'
);
var
temp_2
=
document
.
querySelector
(
'#product_cart_2'
);
...
@@ -308,7 +312,42 @@ $(document).ready(function () {
...
@@ -308,7 +312,42 @@ $(document).ready(function () {
var
clone_2
=
document
.
importNode
(
temp_2
.
content
,
true
);
var
clone_2
=
document
.
importNode
(
temp_2
.
content
,
true
);
document
.
querySelector
(
'#'
+
prod_id
).
appendChild
(
clone_2
);
document
.
querySelector
(
'#'
+
prod_id
).
appendChild
(
clone_2
);
// guardado de producto en carrito
//variable prod_cart_url en map.html
// $.ajax({
// type : 'POST',
// url : prod_cart_url,
// data : {
// 'csrfmiddlewaretoken' : document.getElementsByName('csrfmiddlewaretoken')[0].value,
// 'product' : JSON.stringify(data.product),
// 'product_num' : PRODUCT_COUNTER_STR
// },
// dataType : 'json'
// });
}
}
});
});
});
});
// genera la compra del producto
$
(
'#purchased-product-form'
).
submit
(
function
(
event
)
{
var
submit_data
=
$
(
'#purchased-product-form'
).
serialize
();
event
.
preventDefault
();
console
.
log
(
"Submitted data:"
,
typeof
(
submit_data
));
console
.
log
(
"Submitted data:"
,
submit_data
);
$
.
ajax
({
type
:
'POST'
,
url
:
purch_prod_url
,
data
:
{
'csrfmiddlewaretoken'
:
document
.
getElementsByName
(
'csrfmiddlewaretoken'
)[
0
].
value
,
'product_list'
:
JSON
.
stringify
(
productListCart
)
},
dataType
:
'json'
});
});
});
});
catalog/templates/base_top.html
View file @
b77d7f55
...
@@ -121,18 +121,21 @@
...
@@ -121,18 +121,21 @@
<!-- /.tab-pane -->
<!-- /.tab-pane -->
<!-- Settings tab content -->
<!-- Settings tab content -->
<div
class=
"tab-pane"
id=
"control-sidebar-settings-tab"
>
<div
class=
"tab-pane"
id=
"control-sidebar-settings-tab"
>
<div
class=
"container"
>
<form
id=
'purchased-product-form'
role=
"form"
method=
"post"
>
<div
class=
"sidebar-title"
>
{% csrf_token %}
<h3><b>
My cart
</b></h3>
<div
class=
"container"
>
</div>
<div
class=
"sidebar-title"
>
<div
class=
"sidebar-button"
>
<h3><b>
My cart
</b></h3>
<button
type=
"button"
name=
"search"
id=
"add-cart"
class=
"btn btn-primary"
>
</div>
Buy products
<div
class=
"sidebar-button"
>
</button>
<button
type=
"submit"
name=
"search"
id=
"purchase"
class=
"btn btn-primary"
>
Purchase
</button>
</div>
</div>
</div>
</div
>
<!-- this ul element is filled with data --
>
<!-- this ul element is filled with data --
>
<ul
id=
"product-list-cart"
class=
"sidebar-menu"
data-widget=
"tree"
></ul
>
<
ul
id=
"product-list-cart"
class=
"sidebar-menu"
data-widget=
"tree"
></ul
>
<
/form
>
</div>
</div>
<!-- /.tab-pane -->
<!-- /.tab-pane -->
</div>
</div>
...
...
catalog/templates/map.html
View file @
b77d7f55
...
@@ -250,8 +250,10 @@
...
@@ -250,8 +250,10 @@
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
purch_prod_url
=
"{% url 'purch-rqst' %}"
// url for requesting product purschase
</script>
</script>
{% endblock %}
{% endblock %}
catalog/urls.py
View file @
b77d7f55
...
@@ -8,6 +8,8 @@ urlpatterns = [
...
@@ -8,6 +8,8 @@ urlpatterns = [
url
(
r'^productlist/$'
,
views
.
productList
,
name
=
'productList'
),
url
(
r'^productlist/$'
,
views
.
productList
,
name
=
'productList'
),
url
(
r'^regionsearched/$'
,
views
.
regionSearched
,
name
=
'regionSearched'
),
url
(
r'^regionsearched/$'
,
views
.
regionSearched
,
name
=
'regionSearched'
),
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'^purchrequest/$'
,
views
.
purchaseProduct
,
name
=
'purch-rqst'
)
]
]
catalog/views.py
View file @
b77d7f55
...
@@ -2,12 +2,15 @@
...
@@ -2,12 +2,15 @@
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
catalog.forms
import
ASFSearchForm
from
catalog.forms
import
ASFSearchForm
from
catalog.models
import
Polygon
from
catalog.models
import
Polygon
,
CartProduct
,
Product_l1c
,
Purchase
from
django.http
import
HttpResponse
,
JsonResponse
,
HttpResponseRedirect
from
django.http
import
HttpResponse
,
JsonResponse
,
HttpResponseRedirect
from
django.urls
import
reverse
from
django.urls
import
reverse
from
django.views.generic.base
import
View
from
django.views.generic.base
import
View
from
django.template
import
loader
,
RequestContext
from
django.template
import
loader
,
RequestContext
from
django.contrib.auth.models
import
User
from
django.core
import
management
from
urllib
import
urlencode
from
urllib
import
urlencode
from
collections
import
OrderedDict
import
requests
,
json
,
unicodedata
,
sys
import
requests
,
json
,
unicodedata
,
sys
import
base64
import
base64
...
@@ -143,4 +146,88 @@ def regionSearched(request):
...
@@ -143,4 +146,88 @@ def regionSearched(request):
if
len
(
cityList
)
>
0
:
if
len
(
cityList
)
>
0
:
print
cityList
print
cityList
return
HttpResponseRedirect
(
reverse
(
'map'
))
return
HttpResponseRedirect
(
reverse
(
'map'
))
\ No newline at end of file
#-------------------------------------------------------------------------------
def
saveInCart
(
request
):
"""
Saves product in cart DB
"""
user
=
User
.
objects
.
filter
(
id
=
request
.
user
.
id
)[
0
]
product
=
json
.
loads
(
request
.
POST
[
'product'
])
product_num
=
int
(
request
.
POST
[
'product_num'
])
# print json.dumps(product, indent=3, sort_keys=True)
cartProd
=
CartProduct
(
user
=
user
,
prod_uuid
=
product
[
'uuid'
],
prod_num
=
product_num
,
purchased
=
False
)
cartProd
.
save
()
return
HttpResponse
(
status
=
204
)
#-------------------------------------------------------------------------------
def
purchaseProduct
(
request
):
"""
For now to purchase a product consists in downloading L1C products and saving them in DB.
"""
################# DEFINE PATH ##########################
prod_dir
=
'my_path'
########################################################
products_to_download
=
{
'uuid'
:
[],
'id'
:
[]
}
user
=
User
.
objects
.
filter
(
id
=
request
.
user
.
id
)[
0
]
prod_purchased
=
json
.
loads
(
request
.
POST
[
'product_list'
])
# prod_purchased = ['S2B_MSIL1C_20171226T162659_N0206_R040_T16QBJ_20171226T212212', 'S2B_MSIL1C_20180326T161909_N0206_R040_T15QZD_20180326T195757']
for
p
in
prod_purchased
:
p_uuid
=
p
[
'uuid'
]
p_identifier
=
p
[
'identifier'
]
PRODUCT_EXISTS
=
Product_l1c
.
objects
.
filter
(
uuid
=
p_uuid
)
.
exists
()
if
not
PRODUCT_EXISTS
:
products_to_download
[
'uuid'
]
.
append
(
p_uuid
)
products_to_download
[
'id'
]
.
append
(
p_identifier
)
# print json.dumps(p, indent=3, sort_keys=True)
## Saves data to DB using populate_products_l1c command ##
management
.
call_command
(
'populate_products_l1c'
,
file_path
=
prod_dir
,
products_list
=
products_to_download
[
'id'
])
## Register of user purchase ##
purch
=
Purchase
(
user
=
user
)
purch
.
save
()
for
p_uuid
in
products_to_download
[
'uuid'
]:
prod_l1c
=
Product_l1c
.
objects
.
get
(
uuid
=
p_uuid
)
purch
.
prod_list
.
add
(
prod_l1c
)
### TODO: Download products somewhere .. ###
# sentinel.downloadProducts(products, prod_dir)
### After that the code below is executed ###
# purch = Purchase(user=user)
# purch.save()
# # for prod_uuid in prod_purchased:
# for prod_id in prod_purchased:
# # prod_l1c = Product_l1c.objects.get(uuid=prod_uuid)
# prod_l1c = Product_l1c.objects.get(identifier=prod_id)
# print prod_l1c
# purch.prod_list.add(prod_l1c)
return
HttpResponse
(
status
=
204
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment