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
b0133c01
Commit
b0133c01
authored
Jul 12, 2018
by
Renán Sosa Guillen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
templates update
parent
c1b6be88
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
542 additions
and
604 deletions
+542
-604
dataRetrieval.js
catalog/static/js/dataRetrieval.js
+90
-126
base_top.html
catalog/templates/base_top.html
+227
-166
map.html
catalog/templates/map.html
+200
-213
views.py
catalog/views.py
+25
-99
No files found.
catalog/static/js/dataRetrieval.js
View file @
b0133c01
This diff is collapsed.
Click to expand it.
catalog/templates/base_top.html
View file @
b0133c01
This diff is collapsed.
Click to expand it.
catalog/templates/map.html
View file @
b0133c01
This diff is collapsed.
Click to expand it.
catalog/views.py
View file @
b0133c01
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.shortcuts
import
render
from
catalog.forms
import
ASFSearchForm
from
catalog.models
import
Polygon
from
django.http
import
HttpResponse
,
JsonResponse
,
HttpResponseRedirect
from
django.urls
import
reverse
from
django.views.generic.base
import
View
from
django.template
import
loader
from
django.template
import
loader
,
RequestContext
from
urllib
import
urlencode
import
requests
,
json
,
unicodedata
,
sys
import
base64
...
...
@@ -17,6 +16,7 @@ from geosentinel import APISentinel
sentinel
=
APISentinel
.
APISentinel
(
'emmhp'
,
'geoemm29'
)
# Create your views here.
#-------------------------------------------------------------------------------
def
login
(
request
):
...
...
@@ -24,9 +24,9 @@ def login(request):
View function for home page of site.
"""
# Render the HTML template index.html with the data in the context variable
return
render
(
request
,
'login.html'
,{})
#-------------------------------------------------------------------------------
def
map
(
request
):
"""
...
...
@@ -40,10 +40,8 @@ def map(request):
#-------------------------------------------------------------------------------
def
requestToImage
(
request
):
img_link
=
request
.
GET
[
'value'
]
# img_link = img_link[:img_link.find("/") + 2] + "emmhp:geoemm29@" + img_link[img_link.find("/") + 2:]
r
=
requests
.
get
(
img_link
,
auth
=
(
"emmhp"
,
"geoemm29"
),
stream
=
True
)
img_str
=
base64
.
b64encode
(
r
.
content
)
r
=
requests
.
get
(
img_link
,
auth
=
(
"emmhp"
,
"geoemm29"
),
stream
=
True
)
img_str
=
base64
.
b64encode
(
r
.
content
)
return
JsonResponse
({
'img'
:
img_str
})
...
...
@@ -64,7 +62,7 @@ def productList(request):
## ----- aqui llamada a api sentinel
## ----- antes consultar en DB si no se tiene ya el producto
date
=
(
""
.
join
(
init_date
.
split
(
'-'
)),
""
.
join
(
end_date
.
split
(
'-'
)))
date
=
(
""
.
join
(
init_date
.
split
(
'-'
)),
""
.
join
(
end_date
.
split
(
'-'
)))
params
=
{
"platformname"
:
"Sentinel-2"
}
# if cloud_percentage.strip():
...
...
@@ -73,8 +71,6 @@ def productList(request):
products
=
sentinel
.
getProducts
(
area
,
date
,
params
)
## simulation of 6-digit random id, this will be obtain from sentinel(?)
# random_id = ''.join(["%s" % random.randint(0, 9) for i in range(0, 6)])
## path from image preview storage location
img_preview
=
'/static/images/sat_preview/sat_test.jpg'
...
...
@@ -85,33 +81,20 @@ def productList(request):
img_link
=
img_link
[:
img_link
.
find
(
"/"
)
+
2
]
+
"emmhp:geoemm29@"
+
img_link
[
img_link
.
find
(
"/"
)
+
2
:]
catalog
.
append
({
'process'
:
process
,
'start_date'
:
init_date
,
'end_date'
:
end_date
,
'cloud_percentage'
:
cloud_percentage
,
'product'
:
products
[
p
],
'id'
:
products
[
p
][
'uuid'
],
'img'
:
img_preview
'process'
:
process
,
'start_date'
:
init_date
,
'end_date'
:
end_date
,
'cloud_percentage'
:
cloud_percentage
,
'product'
:
products
[
p
],
'id'
:
products
[
p
][
'uuid'
],
'img'
:
img_preview
})
return
JsonResponse
({
'catalog'
:
catalog
});
# r2 = dict(request.POST)
# r2.pop('csrfmiddlewaretoken', None)
# print("R2: ", r2.keys());
# url = 'https://api.daac.asf.alaska.edu/services/search/param?'+urlencode(r2, 'utf-8')+"&output=JSON"
# response = requests.get(url)
# json = response.json()
# return render(request, 'productList.html', {}) #"catalog":json[0]})
# return HttpResponse(json.dumps(item_data, ensure_ascii=True), content_type="application/json")
# return render(request, 'productList.html', {'item_data': item_data})
return
JsonResponse
({
'catalog'
:
catalog
});
#-------------------------------------------------------------------------------
class
SearchSubmitView
(
View
):
template
=
'map.html'
# template = 'search_submit.html'
def
strip_accents
(
self
,
s
):
return
''
.
join
((
c
for
c
in
unicodedata
.
normalize
(
'NFD'
,
s
)
if
unicodedata
.
category
(
c
)
!=
'Mn'
))
...
...
@@ -123,86 +106,29 @@ class SearchSubmitView(View):
searchValue
=
self
.
strip_accents
(
searchValue
)
.
lower
()
## A simple query for Polygon objects whose name is 'searchValue'
# polygonList = Polygon.objects.filter(name=searchValue)
polygonList
=
Polygon
.
objects
.
filter
(
name__startswith
=
searchValue
)
# data = []
list
=
[]
data_list
=
[]
if
len
(
polygonList
)
>
0
:
for
polygon
in
polygonList
:
polygonInfo
=
json
.
loads
(
polygon
.
json_info
)
# data.append({
# 'city' : polygon.name,
# 'state' : self.state_parser[polygonInfo['properties']['CVE_ENT']],
# 'geojson': polygon.json_info
# })
list
.
append
({
'id'
:
str
(
polygon
.
id
),
'city'
:
polygonInfo
[
'properties'
][
'NOMGEO'
],
'state'
:
polygonInfo
[
'properties'
][
'ENT_NAME'
],
'geojson'
:
polygonInfo
,
'wkt_polygon'
:
polygon
.
wkt_polygon
,
'description'
:
polygon
.
description
,
'source'
:
polygon
.
source
data_list
.
append
({
'id'
:
str
(
polygon
.
id
),
'city'
:
polygonInfo
[
'properties'
][
'NOMGEO'
],
'state'
:
polygonInfo
[
'properties'
][
'ENT_NAME'
],
'geojson'
:
polygonInfo
,
'wkt_polygon'
:
polygon
.
wkt_polygon
,
'description'
:
polygon
.
description
,
'source'
:
polygon
.
source
})
# context = {
# 'searchValue': searchValue,
# 'data': json.dumps(data, ensure_ascii=True)
# }
data
=
{
'polygonList'
:
list
'polygonList'
:
data_
list
}
# rendered_template = template.render(context, request)
# print("DATA:", data)
# return HttpResponse(rendered_template, content_type='application/json')
# return HttpResponse(json.dumps(data, ensure_ascii=True), content_type='application/json')
return
JsonResponse
(
data
)
#-------------------------------------------------------------------------------
# class SearchSubmitView(View):
# template = 'map.html'
# # template = 'search_submit.html'
# state_parser = {'31': "Yucatán"}
#
# def post(self, request):
# template = loader.get_template(self.template)
# searchValue = request.POST.get('value', '')
#
# ## A simple query for Polygon objects whose name is 'searchValue'
# polygonList = Polygon.objects.filter(name=searchValue)
#
# data = []
# if len(polygonList) > 0:
# for polygon in polygonList:
# polygonInfo = json.loads(polygon.json_info)
#
# # data.append({
# # 'city' : polygon.name,
# # 'state' : self.state_parser[polygonInfo['properties']['CVE_ENT']],
# # 'geojson': polygon.json_info
# # })
# data.append({
# 'city': polygonInfo['properties']['NOMGEO'],
# 'state': self.state_parser[polygonInfo['properties']['CVE_ENT']],
# 'geojson': polygonInfo
# })
#
# context = {
# 'searchValue': searchValue,
# 'data': data
# }
#
# # rendered_template = template.render(context, request)
# print("DATA:", data)
# # return render(request, self.template, context)
# return HttpResponseRedirect(reverse(map), json.dumps(data, ensure_ascii=True), content_type='application/json')
#-------------------------------------------------------------------------------
def
regionSearched
(
request
):
"""
...
...
@@ -210,7 +136,7 @@ def regionSearched(request):
"""
city_name
=
request
.
POST
[
'value'
]
cityList
=
Polygon
.
objects
.
filter
(
name
=
city_name
)
cityList
=
Polygon
.
objects
.
filter
(
name
=
city_name
)
if
len
(
cityList
)
>
0
:
print
cityList
...
...
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