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

templates update

parent c1b6be88
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
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
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 from django.template import loader, RequestContext
from urllib import urlencode from urllib import urlencode
import requests, json, unicodedata, sys import requests, json, unicodedata, sys
import base64 import base64
...@@ -17,6 +16,7 @@ from geosentinel import APISentinel ...@@ -17,6 +16,7 @@ from geosentinel import APISentinel
sentinel = APISentinel.APISentinel('emmhp', 'geoemm29') sentinel = APISentinel.APISentinel('emmhp', 'geoemm29')
# Create your views here. # Create your views here.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def login(request): def login(request):
...@@ -24,9 +24,9 @@ def login(request): ...@@ -24,9 +24,9 @@ def login(request):
View function for home page of site. View function for home page of site.
""" """
# Render the HTML template index.html with the data in the context variable # Render the HTML template index.html with the data in the context variable
return render(request,'login.html',{}) return render(request,'login.html',{})
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def map(request): def map(request):
""" """
...@@ -40,10 +40,8 @@ def map(request): ...@@ -40,10 +40,8 @@ def map(request):
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def requestToImage(request): def requestToImage(request):
img_link = request.GET['value'] 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}) return JsonResponse({'img': img_str})
...@@ -64,7 +62,7 @@ def productList(request): ...@@ -64,7 +62,7 @@ def productList(request):
## ----- aqui llamada a api sentinel ## ----- aqui llamada a api sentinel
## ----- antes consultar en DB si no se tiene ya el producto ## ----- 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"} params = {"platformname": "Sentinel-2"}
# if cloud_percentage.strip(): # if cloud_percentage.strip():
...@@ -73,8 +71,6 @@ def productList(request): ...@@ -73,8 +71,6 @@ def productList(request):
products = sentinel.getProducts(area, date, params) 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 ## path from image preview storage location
img_preview = '/static/images/sat_preview/sat_test.jpg' img_preview = '/static/images/sat_preview/sat_test.jpg'
...@@ -85,33 +81,20 @@ def productList(request): ...@@ -85,33 +81,20 @@ def productList(request):
img_link = img_link[:img_link.find("/")+2] + "emmhp:geoemm29@" + img_link[img_link.find("/")+2:] img_link = img_link[:img_link.find("/")+2] + "emmhp:geoemm29@" + img_link[img_link.find("/")+2:]
catalog.append({ catalog.append({
'process' : process, 'process' : process,
'start_date' : init_date, 'start_date' : init_date,
'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'], 'id' : products[p]['uuid'],
'img' : img_preview 'img' : img_preview
}) })
return JsonResponse({'catalog':catalog}); 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})
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
class SearchSubmitView(View): class SearchSubmitView(View):
template = 'map.html' template = 'map.html'
# template = 'search_submit.html'
def strip_accents(self, s): def strip_accents(self, s):
return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn')) return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn'))
...@@ -123,86 +106,29 @@ class SearchSubmitView(View): ...@@ -123,86 +106,29 @@ class SearchSubmitView(View):
searchValue = self.strip_accents(searchValue).lower() searchValue = self.strip_accents(searchValue).lower()
## A simple query for Polygon objects whose name is 'searchValue' ## A simple query for Polygon objects whose name is 'searchValue'
# polygonList = Polygon.objects.filter(name=searchValue)
polygonList = Polygon.objects.filter(name__startswith=searchValue) polygonList = Polygon.objects.filter(name__startswith=searchValue)
# data = [] data_list = []
list = []
if len(polygonList) > 0: if len(polygonList) > 0:
for polygon in polygonList: for polygon in polygonList:
polygonInfo = json.loads(polygon.json_info) polygonInfo = json.loads(polygon.json_info)
# data.append({ data_list.append({
# 'city' : polygon.name, 'id' : str(polygon.id),
# 'state' : self.state_parser[polygonInfo['properties']['CVE_ENT']], 'city' : polygonInfo['properties']['NOMGEO'],
# 'geojson': polygon.json_info 'state' : polygonInfo['properties']['ENT_NAME'],
# }) 'geojson' : polygonInfo,
list.append({ 'wkt_polygon' : polygon.wkt_polygon,
'id': str(polygon.id), 'description' : polygon.description,
'city': polygonInfo['properties']['NOMGEO'], 'source' : polygon.source
'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 = { 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) 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): def regionSearched(request):
""" """
...@@ -210,7 +136,7 @@ def regionSearched(request): ...@@ -210,7 +136,7 @@ def regionSearched(request):
""" """
city_name = request.POST['value'] city_name = request.POST['value']
cityList = Polygon.objects.filter(name=city_name) cityList = Polygon.objects.filter(name=city_name)
if len(cityList) > 0: if len(cityList) > 0:
print cityList print cityList
......
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