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
1e85c92c
Commit
1e85c92c
authored
Aug 23, 2018
by
Renán Sosa Guillen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GeoInt_SIDT
parent
17d13bec
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
316 additions
and
170 deletions
+316
-170
models.py
catalog/models.py
+11
-12
body.css
catalog/static/css/body.css
+7
-2
dataRetrieval.js
catalog/static/js/dataRetrieval.js
+198
-85
openLayers4.js
catalog/static/js/openLayers4.js
+2
-1
map.html
catalog/templates/map.html
+5
-5
templates.html
catalog/templates/templates.html
+1
-1
urls.py
catalog/urls.py
+1
-1
views.py
catalog/views.py
+91
-63
No files found.
catalog/models.py
View file @
1e85c92c
...
@@ -46,15 +46,14 @@ class Product_l2a(models.Model):
...
@@ -46,15 +46,14 @@ class Product_l2a(models.Model):
class
CartProduct
(
models
.
Model
):
class
CartProduct
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
CASCADE
)
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
CASCADE
)
add_date
=
models
.
DateTimeField
(
auto_now
=
True
)
aggreg_date
=
models
.
DateTimeField
(
auto_now
=
True
)
## date of product aggregation
prod_uuid
=
models
.
CharField
(
max_length
=
50
)
uuid
=
models
.
CharField
(
max_length
=
50
)
prod_num
=
models
.
IntegerField
()
info
=
models
.
TextField
(
null
=
True
)
prod_l1c
=
models
.
ForeignKey
(
Product_l1c
,
on_delete
=
models
.
CASCADE
,
null
=
True
)
purchased
=
models
.
NullBooleanField
()
purchased
=
models
.
NullBooleanField
()
# class Purchase(models.Model):
class
Purchase
(
models
.
Model
):
# user = models.ForeignKey(User, on_delete=models.CASCADE)
user
=
models
.
ForeignKey
(
User
,
on_delete
=
models
.
CASCADE
)
# pur_date = models.DateTimeField(auto_now=True) ## transaction date
pur_date
=
models
.
DateTimeField
(
auto_now
=
True
)
## transaction date
# prod_list = models.ManyToManyField(Product_l1c)
prod_list
=
models
.
ManyToManyField
(
Product_l1c
)
catalog/static/css/body.css
View file @
1e85c92c
...
@@ -330,9 +330,14 @@ div .menu-info h4 {
...
@@ -330,9 +330,14 @@ div .menu-info h4 {
/*padding-left: 58%;*/
/*padding-left: 58%;*/
/*}*/
/*}*/
div
#product-list-globe
,
div
#product-list-globe
{
max-height
:
773px
;
overflow
:
auto
;
}
div
#product-list-cart-items
{
div
#product-list-cart-items
{
max-height
:
500px
;
max-height
:
700px
;
max-width
:
207px
;
overflow
:
auto
;
overflow
:
auto
;
}
}
...
...
catalog/static/js/dataRetrieval.js
View file @
1e85c92c
This diff is collapsed.
Click to expand it.
catalog/static/js/openLayers4.js
View file @
1e85c92c
...
@@ -212,7 +212,8 @@ OpenStreetMapsClass.prototype.formatCoords = function(coords)
...
@@ -212,7 +212,8 @@ OpenStreetMapsClass.prototype.formatCoords = function(coords)
OpenStreetMapsClass
.
prototype
.
showCoords
=
function
(
geometry
)
OpenStreetMapsClass
.
prototype
.
showCoords
=
function
(
geometry
)
{
{
var
wkt
=
new
ol
.
format
.
WKT
();
var
wkt
=
new
ol
.
format
.
WKT
();
document
.
getElementById
(
"id_polygon"
).
value
=
wkt
.
writeGeometry
(
geometry
.
clone
().
transform
(
'EPSG:3857'
,
'EPSG:4326'
));
var
wkt_polygon
=
wkt
.
writeGeometry
(
geometry
.
clone
().
transform
(
'EPSG:3857'
,
'EPSG:4326'
));
document
.
getElementById
(
"id_polygon"
).
value
=
wkt_polygon
;
}
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/**
/**
...
...
catalog/templates/map.html
View file @
1e85c92c
...
@@ -250,10 +250,10 @@
...
@@ -250,10 +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
prod_cart_url
=
"{% url 'cart-rqst' %}"
// url for requesting product saving in cart
var
p
urch_prod_url
=
"{% url 'purch-rqst' %}"
// url for requesting product purschase
var
p
rod_from_cartDB_url
=
"{% url 'from-cart-rqst' %}"
// url for requesting product from cart table in DB
</script>
</script>
{% endblock %}
{% endblock %}
catalog/templates/templates.html
View file @
1e85c92c
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
<a
href=
"javascript:void(0)"
>
<a
href=
"javascript:void(0)"
>
<i
class=
"menu-icon glyphicon glyphicon-bookmark bg-red"
></i>
<i
class=
"menu-icon glyphicon glyphicon-bookmark bg-red"
></i>
<div
class=
"menu-info"
>
<div
class=
"menu-info"
>
<h4
id=
""
class=
"control-sidebar-subheading"
onclick=
"drawApiResponse(this)"
></h4>
<h4
id=
""
class=
"control-sidebar-subheading"
onclick=
"drawApiResponse(this)
;
"
></h4>
<p></p>
<p></p>
<input
type=
"checkbox"
name=
"product_selected"
value=
""
checked
>
<input
type=
"checkbox"
name=
"product_selected"
value=
""
checked
>
</div>
</div>
...
...
catalog/urls.py
View file @
1e85c92c
...
@@ -10,6 +10,6 @@ urlpatterns = [
...
@@ -10,6 +10,6 @@ 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'^
purchrequest/$'
,
views
.
purchaseProduct
,
name
=
'purch
-rqst'
)
url
(
r'^
fromcartrqst/$'
,
views
.
getFromCart
,
name
=
'from-cart
-rqst'
)
]
]
catalog/views.py
View file @
1e85c92c
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
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
,
CartProduct
,
Product_l1c
,
Purchase
from
catalog.models
import
Polygon
,
CartProduct
,
Product_l1c
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
...
@@ -11,11 +11,10 @@ from django.contrib.auth.models import User
...
@@ -11,11 +11,10 @@ from django.contrib.auth.models import User
from
django.core
import
management
from
django.core
import
management
from
urllib
import
urlencode
from
urllib
import
urlencode
from
collections
import
OrderedDict
from
collections
import
OrderedDict
import
requests
,
json
,
unicodedata
,
sys
import
requests
,
json
,
unicodedata
,
sys
,
base64
import
base64
sys
.
path
.
append
(
'../'
)
sys
.
path
.
append
(
'../'
)
from
geosentinel
import
APISentinel
from
geosentinel
import
APISentinel
,
polygonToBox
sentinel
=
APISentinel
.
APISentinel
(
'emmhp'
,
'geoemm29'
)
sentinel
=
APISentinel
.
APISentinel
(
'emmhp'
,
'geoemm29'
)
...
@@ -71,13 +70,17 @@ def productList(request):
...
@@ -71,13 +70,17 @@ def productList(request):
# if cloud_percentage.strip():
# if cloud_percentage.strip():
# params['cloudcoverpercentage'] = cloud_percentage
# params['cloudcoverpercentage'] = cloud_percentage
params
[
'cloudcoverpercentage'
]
=
cloud_percentage
params
[
'cloudcoverpercentage'
]
=
cloud_percentage
## getting the bounding box of the polygon
pol_bbox
=
polygonToBox
.
getWKTPolygonBoundingBox
(
area
,
True
)
products
=
sentinel
.
getProducts
(
area
,
date
,
params
)
## requesting producto to sentinel api
products
=
sentinel
.
getProducts
(
pol_bbox
,
date
,
params
)
## path from image preview storage location
## path from image preview storage location
img_preview
=
'/static/images/sat_preview/sat_test.jpg'
img_preview
=
'/static/images/sat_preview/sat_test.jpg'
# se crea una lista de objetos del catalogo
#
#
se crea una lista de objetos del catalogo
catalog
=
[]
catalog
=
[]
for
p
in
products
:
for
p
in
products
:
# img_link = products[p]['link_icon']
# img_link = products[p]['link_icon']
...
@@ -89,11 +92,12 @@ def productList(request):
...
@@ -89,11 +92,12 @@ def productList(request):
'end_date'
:
end_date
,
'end_date'
:
end_date
,
'cloud_percentage'
:
cloud_percentage
,
'cloud_percentage'
:
cloud_percentage
,
'product'
:
products
[
p
],
'product'
:
products
[
p
],
'
id'
:
products
[
p
][
'uuid'
],
'
uuid'
:
products
[
p
][
'uuid'
],
'img'
:
img_preview
'img'
:
img_preview
})
})
return
JsonResponse
({
'catalog'
:
catalog
});
return
JsonResponse
({
'catalog'
:
catalog
});
# return HttpResponse(status=204)
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
class
SearchSubmitView
(
View
):
class
SearchSubmitView
(
View
):
...
@@ -151,83 +155,107 @@ def regionSearched(request):
...
@@ -151,83 +155,107 @@ def regionSearched(request):
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
def
saveInCart
(
request
):
def
saveInCart
(
request
):
"""
"""
Saves product in cart DB
Saves product in cart
table in
DB
"""
"""
user
=
User
.
objects
.
filter
(
id
=
request
.
user
.
id
)[
0
]
user
=
User
.
objects
.
get
(
id
=
request
.
user
.
id
)
product
=
json
.
loads
(
request
.
POST
[
'product'
])
product_list
=
json
.
loads
(
request
.
POST
[
'cart_product_list'
])
product_num
=
int
(
request
.
POST
[
'product_num'
])
# print json.dumps(product, indent=3, sort_keys=True)
for
product
in
product_list
:
p_uuid
=
product
[
'uuid'
]
cartProd
=
CartProduct
(
p_info
=
product
[
'info'
]
user
=
user
,
PRODUCT_EXISTS
=
CartProduct
.
objects
.
filter
(
uuid
=
p_uuid
,
user
=
user
)
.
exists
()
prod_uuid
=
product
[
'uuid'
],
prod_num
=
product_num
,
if
not
PRODUCT_EXISTS
:
purchased
=
False
cartProd
=
CartProduct
(
)
user
=
user
,
uuid
=
p_uuid
,
cartProd
.
save
()
info
=
json
.
dumps
(
p_info
,
indent
=
3
,
sort_keys
=
True
,
ensure_ascii
=
True
),
purchased
=
False
)
cartProd
.
save
()
return
HttpResponse
(
status
=
204
)
return
HttpResponse
(
status
=
204
)
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
def
purchaseProduc
t
(
request
):
def
getFromCar
t
(
request
):
"""
"""
For now to purchase a product consists in downloading L1C products and saving them in DB.
Temporarily gets product from cart table based on uuid porperty to show in cart section
"""
"""
################# 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
:
user
=
User
.
objects
.
get
(
id
=
request
.
user
.
id
)
products_to_download
[
'uuid'
]
.
append
(
p_uuid
)
prod_uuid_list
=
request
.
POST
[
'product_uuid_list'
]
.
split
(
","
)
products_to_download
[
'id'
]
.
append
(
p_identifier
)
prod_list
=
[]
for
prod_uuid
in
prod_uuid_list
:
product
=
CartProduct
.
objects
.
filter
(
uuid
=
prod_uuid
,
user
=
user
)
.
first
()
prod_list
.
append
({
'uuid'
:
product
.
uuid
,
'info'
:
json
.
loads
(
product
.
info
)
})
return
JsonResponse
({
'product_list'
:
prod_list
})
#-------------------------------------------------------------------------------
# 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.get(id=request.user.id)
# 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)
#
# print json.dumps(p, indent=3, sort_keys=True)
## Saves data to DB using populate_products_l1c command ##
#
## 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'
])
#
management.call_command('populate_products_l1c', file_path=prod_dir, products_list=products_to_download['id'])
## Register of user purchase ##
#
## Register of user purchase ##
purch
=
Purchase
(
user
=
user
)
#
purch = Purchase(user=user)
purch
.
save
()
#
purch.save()
for
p_uuid
in
products_to_download
[
'uuid'
]:
#
for p_uuid in products_to_download['uuid']:
prod_l1c
=
Product_l1c
.
objects
.
get
(
uuid
=
p_uuid
)
#
prod_l1c = Product_l1c.objects.get(uuid=p_uuid)
purch
.
prod_list
.
add
(
prod_l1c
)
#
purch.prod_list.add(prod_l1c)
### TODO: Download products somewhere .. ###
#
### TODO: Download products somewhere .. ###
# sentinel.downloadProducts(products, prod_dir)
#
# sentinel.downloadProducts(products, prod_dir)
### After that the code below is executed ###
#
### After that the code below is executed ###
# purch = Purchase(user=user)
#
# purch = Purchase(user=user)
# purch.save()
#
# purch.save()
# # for prod_uuid in prod_purchased:
#
# # for prod_uuid in prod_purchased:
# for prod_id in prod_purchased:
#
# for prod_id in prod_purchased:
# # prod_l1c = Product_l1c.objects.get(uuid=prod_uuid)
#
# # prod_l1c = Product_l1c.objects.get(uuid=prod_uuid)
# prod_l1c = Product_l1c.objects.get(identifier=prod_id)
#
# prod_l1c = Product_l1c.objects.get(identifier=prod_id)
# print prod_l1c
#
# print prod_l1c
# purch.prod_list.add(prod_l1c)
#
# purch.prod_list.add(prod_l1c)
return
HttpResponse
(
status
=
204
)
# 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