Commit dcac1d5c authored by Luis Ernesto Dominguez Uriostegui's avatar Luis Ernesto Dominguez Uriostegui

cambios de ulises realizados,boton historial de compras

parents 23298339 d55ba54d
# compiled code
*.pyc
*.pyc
# project
.idea/
__pycache__/
geosentinel/
geosentinel
db.sqlite3-journal
# django stufff
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
media
# virtual env
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# pyenv
.python-version
......@@ -27,4 +27,5 @@ urlpatterns = [
url(r'^reports/', include('reports.urls')),
url(r'^$', RedirectView.as_view(url='/catalog/', permanent=True)),
url(r'^accounts/', include('django.contrib.auth.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
]
#+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
from django.shortcuts import HttpResponseRedirect
from django.urls import reverse
# from django.core.urlresolvers import reverse
class AuthRequiredMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
# Code to be executed for each request before
# the view (and later middleware) are called.
def __call__(self, request):
# Code to be executed for each request before
# the view (and later middleware) are called.
response = self.get_response(request)
print (request.path_info)
print (reverse('login'))
response = self.get_response(request)
print(request.path_info)
print(reverse('login'))
# if request.path_info == reverse('ws-news-list2'):
# return response
# if request.path_info == reverse('ws-news-list2'):
# return response
if not request.user.is_authenticated() and request.path_info != reverse('login'):
return HttpResponseRedirect(reverse('login'))
if not request.user.is_authenticated and request.path_info != reverse('login'):
return HttpResponseRedirect(reverse('login'))
# Code to be executed for each request/response after
# the view is called.
# Code to be executed for each request/response after
# the view is called.
return response
return response
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -26,33 +26,33 @@ var makeRequest = function (value) {
dataType : 'json',
success : function(data) {
polygonList = data.polygonList;
while (pol_element.firstChild) {
pol_element.removeChild(pol_element.firstChild);
}
if (polygonList.length <= 0) {
var temp = document.querySelector('#city_list_template');
// filling template
temp.content.querySelector('li').id = '';
temp.content.querySelectorAll('span')[0].textContent = 'No cities matched your search. Try again.';
temp.content.querySelectorAll('span')[1].textContent = '';
temp.content.querySelectorAll('div')[3].textContent = '';
var clone = document.importNode(temp.content, true);
document.querySelector('#polygon-list').appendChild(clone);
} else {
data.polygonList.forEach(function (polygon) {
var temp = document.querySelector('#city_list_template');
// filling template
temp.content.querySelector('li').id = polygon.id;
temp.content.querySelectorAll('span')[0].textContent = polygon.city + ", " + polygon.state;
temp.content.querySelectorAll('span')[1].textContent = polygon.description;
temp.content.querySelectorAll('div')[3].textContent = "Fuente: " + polygon.source;
var clone = document.importNode(temp.content, true);
document.querySelector('#polygon-list').appendChild(clone);
});
......@@ -84,16 +84,16 @@ function drawPolygon(element) {
osmap.removePolygon();
// draw wkt polygon
// osmap.addWKTPolygon(polygon.wkt_polygon);
osmap.addWKTPolygon(polygon.wkt_polygon);
// format coords to draw
var coords = osmap.formatCoords(polygon.geojson.geometry.coordinates);
// var coords = osmap.formatCoords(polygon.geojson.geometry.coordinates);
// get the biggest area
var biggest = osmap.getBiggestPolygon(coords);
// var biggest = osmap.getBiggestPolygon(coords);
// draw coordsR
osmap.addPolygon(biggest);
// osmap.addPolygon(biggest);
}
})
}
......@@ -114,7 +114,7 @@ $("#id_polygon").on('keyup', function (e) {
// this function cleans list of available products
function erase_product_list_globe() {
prevfeature = null;
prevfeature = new Map();
var pol_element = document.getElementById('product-list-globe');
while (pol_element.firstChild) {
pol_element.removeChild(pol_element.firstChild);
......@@ -140,21 +140,23 @@ function erase_product_list_cart() {
}
var prevfeature = null;
var prevfeature = new Map();
function drawApiResponse(element) {
var list_globe = document.getElementById('product-list-globe').children;
for (var i=0; i<list_globe.length; i++) {
var listElement = list_globe[i];
listElement.style.textDecoration = 'none';
}
for (var i=0; i<product_list.catalog.length; i++) {
var data = product_list.catalog[i];
if (data.uuid === element.id.replace("-li", '')) {
element.style.textDecoration = 'underline';
console.log("footprint:\n", data.product.footprint);
prevfeature = osmap.addfootprint(data.product.footprint, prevfeature);
if (!prevfeature.has(data.uuid)){
element.style.textDecoration = 'underline';
prevfeature.set(data.uuid, osmap.addfootprint(data.product.footprint, prevfeature));
}else{
if (prevfeature.length != 0){
element.style.textDecoration = 'none';
osmap.deletefootprint(prevfeature.get(data.uuid));
prevfeature.delete(data.uuid);
}
}
}
}
}
......@@ -162,7 +164,7 @@ function drawApiResponse(element) {
function createProductContainer() {
var temp_1 = document.querySelector('#product_cart_1');
// filling template
temp_1.content.querySelector('span').textContent = "Product";
......@@ -178,7 +180,7 @@ $('#ajax-input').focus(function () {
$('#option-list').show();
OPT_LIST_IS_HIDDEN = false;
}
}).blur(function () {
}).blur(function (event) {
INPUT_ON_FOCUS = false;
if (!OPT_LIST_IS_HIDDEN && $(this).val() && $(event.target).closest('#option-list').length) {
$('#option-list').hide();
......@@ -228,7 +230,7 @@ $(document).ready(function () {
var pol_element = document.getElementById('polygon-list');
var typingTimer;
var typingInterval = 800; //milliseconds
var typingInterval = 300; //milliseconds
var productListGlobe = [];
var cartProductList = []; // this array represent DB where products will be stored
var productsToObtain = [];
......@@ -243,17 +245,26 @@ $(document).ready(function () {
typingTimer = setTimeout(makeRequest.bind(null, value), typingInterval);
} else {
$('#option-list').hide();
while (pol_element.firstChild) {
pol_element.removeChild(pol_element.firstChild);
}
OPT_LIST_IS_HIDDEN = true;
return
}
});
// disable enter in search input
$('#ajax-input').on('keyup keypress', function(event) {
var keyCode = event.keyCode || event.which;
if (keyCode === 13) {
event.preventDefault();
return false;
}
});
// var PRODUCT_IN_LIST = false;
// function for making POST request to productList in view.py
......@@ -304,7 +315,7 @@ $(document).ready(function () {
temp.content.querySelectorAll('span')[1].textContent = data.product.identifier;
temp.content.querySelectorAll('span')[2].textContent = data.product.size;
temp.content.querySelectorAll('span')[3].textContent = data.product.instrumentname;
var clone = document.importNode(temp.content, true);
document.querySelector('#product-list-globe').appendChild(clone);
}
......@@ -397,7 +408,7 @@ $(document).ready(function () {
productsToObtain = [];
data.product_list.forEach(function (product) {
var temp_2 = document.querySelector('#product_cart_2');
// filling template
temp_2.content.querySelector('li').id = product.uuid;
temp_2.content.querySelector('h4').id = product.uuid + "-h4";
......@@ -424,7 +435,7 @@ $(document).ready(function () {
}
});
// purchasing products in cart
$('#purchased-product-form').submit(function (event) {
event.preventDefault();
......
......@@ -121,12 +121,13 @@ OpenStreetMapsClass.prototype.addWKTPolygon = function(wkt)
document.getElementById("id_polygon").value = wkt;
}
OpenStreetMapsClass.prototype.addfootprint = function(wkt, prevFeature)
{
if (prevFeature) {
OpenStreetMapsClass.prototype.deletefootprint = function (prevFeature) {
if (prevFeature){
this.vectorLayer.getSource().removeFeature(prevFeature);
}
}
OpenStreetMapsClass.prototype.addfootprint = function(wkt, prevFeature){
var format = new ol.format.WKT();
var feature = format.readFeature(wkt, {
......@@ -135,16 +136,16 @@ OpenStreetMapsClass.prototype.addfootprint = function(wkt, prevFeature)
});
var style = new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#dc7828',
width: 1
}),
fill: new ol.style.Fill({
color: 'rgba(255,255,0,0.1)'
})
})
feature.setStyle(style);
stroke: new ol.style.Stroke({
color: getRandomColor(),
width: 1
}),
fill: new ol.style.Fill({
color: 'rgba(255,255,0,0.1)'
})
})
feature.setStyle(style);
this.map.getView().fit(feature.getGeometry(), {duration: 1000, padding: [0, 0, 70, 0]});
this.vectorLayer.getSource().addFeature(feature);
......@@ -263,3 +264,11 @@ OpenStreetMapsClass.prototype.iconStyle = function(url,x,y)
}
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -12,5 +12,4 @@ urlpatterns = [
url(r'^cartrequest/$', views.saveInCart, name='cart-rqst'),
url(r'^fromcartrqst/$', views.getFromCart, name='from-cart-rqst'),
url(r'^purchcartrqst/$', views.purchaseProduct, name='purch-prod-rqst'),
url(r'^scl/$', views.L2ASCL_data, name='L2ASCL-data')
]
......@@ -49,6 +49,7 @@ def requestToImage(request):
img_link = request.GET['value']
r = requests.get(img_link, auth=("emmhp", "geoemm29"), stream=True)
img_str = base64.b64encode(r.content)
img_str = img_str.decode('utf-8')
return JsonResponse({'img': img_str})
......@@ -89,8 +90,12 @@ def productList(request):
catalog = []
for p in products:
# img_link = products[p]['link_icon']
# 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:]
if products[p].get('tileid') is None:
titleid = products[p]['title'].split("_")
products[p]['tileid'] = titleid[5][1:]
catalog.append({
'process' : process,
'start_date' : init_date,
......@@ -262,11 +267,11 @@ def purchaseProduct(request):
## TODO: Add product L1C to Cart DB after product download. ##
#-------------------------------------------------------------------------------
def L2ASCL_data(request):
with open("/home/mchc/data.json") as f:
json_data = json.load(f)
print(json_data)
return render(request, 'L2ASCL_data.html', {"labels":",".join([k for k in json_data]), "vegetation":[v["4"] for k,v in json_data.items()] })
# def L2ASCL_data(request):
# with open("/home/ulises/REPSAT_NAS/mario_repsat_test/T15QZD_sclData.json") as f:
# json_data = json.load(f)
# print(json_data)
# return render(request, 'L2ASCL_data.html', {"labels":",".join([k for k in json_data]), "vegetation":[v["4"] for k,v in json_data.items()] })
#-------------------------------------------------------------------------------
# def purchaseProduct(request):
# """
......
No preview for this file type
This diff is collapsed.
from django.conf.urls import url
from . import views
from reports import views
urlpatterns = [
url(r'^$', views.report_L2ASCL, name='report'),
url(r'^(?P<report>\w+)$', views.report_L2ASCL, name='report'),
url(r'^(?P<report>[\w\-]+)/$', views.report_L2ASCL, name='report'),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import io
from django.http import FileResponse
from reportlab.pdfgen import canvas
from django.shortcuts import render
# Create your views here.
from collections import OrderedDict
import json
#-------------------------------------------------------------------------------
def report_L2ASCL(request, report=0):
with open("/home/mario/NAS_MarioCh/mario_repsat_test/T15QZD_sclData.json") as f:
json_data = OrderedDict(json.load(f))
graphData = dict()
graphData['type']="line"
data=dict()
data['labels'] = [ k for k,v in sorted(json_data.items()) ]
# data['click']="chartOnClick"
data['datasets'] = list()
labels = set()
for d in json_data:
labels |= set(json_data[d].keys())
labels.remove('date')
labelNames = ["No Data", "Saturated", "Shadows", "Cloud Shadows", "Vegetation", "Not-Vegetated", "Whater", "Unclassified", "Cloud Medium Probablilty", "Cloud Hight Probablilty", "Thin Cirrus", "Snow"]
colors = ["Black", "Red", "DarkGray", "Brown", "Green", "Yellow", "Blue", "Grey", "LightGray", "White", "Aqua", "Pink"]
for l in labels:
item = dict()
item['label'] = labelNames[int(l)]
if l == "0":
item['hidden'] = "true"
item['data'] = [ v[l] * 60*60/1000000. for k,v in sorted(json_data.items()) if l in v]
item['backgroundColor']=colors[int(l)]
data['datasets'].append(item)
graphData['data']=data
# graphData['options']['responsive']=True
# graphData['options']['maintainAspectRatio']=False
print( json.dumps(graphData).encode("utf-8"))
return render(request, 'L2ASCL_data.html', {"graphData":json.dumps(graphData).encode("utf-8")})
# -------------------------------------------------------------------------------
from reportlab.pdfgen import canvas
from GeoInt_SIDT import settings
def report_L2ASCL(request, report):
with open("/home/ulises/REPSAT_NAS/mario_repsat_test/"+report+".json") as f:
json_data = OrderedDict(json.load(f))
graphData = dict()
graphData['type'] = "line"
data = dict()
data['labels'] = [k for k, v in sorted(json_data.items())]
# data['click']="chartOnClick"
data['datasets'] = list()
labels = set()
for d in json_data:
labels |= set(json_data[d].keys())
labels.remove('date')
labelNames = ["No Data", "Saturated", "Shadows", "Cloud Shadows", "Vegetation", "Not-Vegetated", "Whater",
"Unclassified", "Cloud Medium Probablilty", "Cloud Hight Probablilty", "Thin Cirrus", "Snow"]
colors = ["Black", "Red", "DarkGray", "Brown", "Green", "Yellow", "Blue", "Grey", "LightGray", "White", "Aqua",
"Pink"]
for l in labels:
item = dict()
item['label'] = labelNames[int(l)]
# item['fill'] = "false"
if l == "0":
item['hidden'] = "true"
item['data'] = [v[l] * 60 * 60 / 1000000. for k, v in sorted(json_data.items()) if l in v]
item['backgroundColor'] = colors[int(l)]
data['datasets'].append(item)
graphData['data'] = data
#print(settings.BASE_URL)
# graphData['options']['responsive']=True
# graphData['options']['maintainAspectRatio']=False
#print(json.dumps(graphData).encode("utf-8"))
return render(request, 'L2ASCL_data.html', {"graphData": json.dumps(graphData), "report_name": report})
# -------------------------------------------------------------------------------
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