Commit 72153411 authored by Irving David's avatar Irving David

Prueba de ejecución de proceso al hacer clic en el botón pay

parent a6c297b5
...@@ -16,7 +16,7 @@ import os ...@@ -16,7 +16,7 @@ import os
import sys import sys
from geosentinel import APISentinel, polygonToBox from geosentinel import APISentinel, polygonToBox
###########3 lee archivo de configuración ################ ########### lee archivo de configuración ################
dirname = os.path.dirname(__file__) dirname = os.path.dirname(__file__)
configfile = os.path.join(dirname, '../config/config.json') configfile = os.path.join(dirname, '../config/config.json')
...@@ -31,13 +31,14 @@ print(config['API_SENTINEL']['SENTINEL_PASS']) ...@@ -31,13 +31,14 @@ print(config['API_SENTINEL']['SENTINEL_PASS'])
NAS_PATH = config['PATHS']['PATH_NAS'] NAS_PATH = config['PATHS']['PATH_NAS']
USERS_PATH = config['PATHS']['PATH_USERS']
SENTINEL_PATH = config['PATHS']['PATH_GEOSENTINEL'] SENTINEL_PATH = config['PATHS']['PATH_GEOSENTINEL']
API_SENTINEL_USER = config['API_SENTINEL']['SENTINEL_USER'] API_SENTINEL_USER = config['API_SENTINEL']['SENTINEL_USER']
API_SENTINEL_PATH = config['API_SENTINEL']['SENTINEL_PASS'] API_SENTINEL_PASS = config['API_SENTINEL']['SENTINEL_PASS']
########################################################### ###########################################################
sys.path.append(SENTINEL_PATH) sys.path.append(SENTINEL_PATH)
sentinel = APISentinel.APISentinel(API_SENTINEL_USER, API_SENTINEL_PATH) sentinel = APISentinel.APISentinel(API_SENTINEL_USER, API_SENTINEL_PASS)
# Create your views here. # Create your views here.
...@@ -454,8 +455,30 @@ def purchaseProduct(request): ...@@ -454,8 +455,30 @@ def purchaseProduct(request):
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def showCart(request): def showCart(request):
user = User.objects.get(id=request.user.id)
prod_list = []
product_list = Purchase.objects.values('user', 'productList', 'purchased', 'price', 'aggreg_date').filter(user=user, purchased=0)
total_price = 0
total_products = 0
for products in product_list:
product = json.loads(products['productList'])
prod_list.append({
'purchased': products['purchased'],
'price': products['price'],
'aggreg_date': products['aggreg_date'],
'catalog': product
})
total_price += products['price']
total_products += 1
return render(request, 'show_cart.html', {'product_list': prod_list, 'total_price': total_price, 'total_products': total_products})
#-------------------------------------
def Pay (request):
#---------------test process---------------------- #---------------test process----------------------
print("showcart!!!") print("PAGAR!!!!")
user = User.objects.get(id=request.user.id) user = User.objects.get(id=request.user.id)
query = [] query = []
query = Purchase.objects.values('id','search__area','user','user__username','user__email', 'search_id', 'search__clouds','search__startDate','search__endDate').filter(user=user, purchased=0) query = Purchase.objects.values('id','search__area','user','user__username','user__email', 'search_id', 'search__clouds','search__startDate','search__endDate').filter(user=user, purchased=0)
...@@ -475,7 +498,9 @@ def showCart(request): ...@@ -475,7 +498,9 @@ def showCart(request):
useremail = values['user__email'] useremail = values['user__email']
userdir = NAS_PATH + "repsat_test_dev/"+useremail ##crea el directorio del usuario #userdir = NAS_PATH + "repsat_test_dev/"+useremail ##crea el directorio del usuario
userdir = USERS_PATH + useremail
if not os.path.exists(userdir): if not os.path.exists(userdir):
os.makedirs(userdir) os.makedirs(userdir)
...@@ -493,15 +518,11 @@ def showCart(request): ...@@ -493,15 +518,11 @@ def showCart(request):
data['productLevel'] = 'L2A' data['productLevel'] = 'L2A'
data['startDate'] = str(values['search__startDate'].date()).replace("-", "") #quita los guiones de la fecha data['startDate'] = str(values['search__startDate'].date()).replace("-", "") #quita los guiones de la fecha
data['endDate'] = str(values['search__endDate'].date()).replace("-", "") #quita los guiones de la fecha data['endDate'] = str(values['search__endDate'].date()).replace("-", "") #quita los guiones de la fecha
# data['startDate'] = request.POST['startDate']
# data['endDate'] = request.POST['endDate']
data['clouds'] = values['search__clouds'] data['clouds'] = values['search__clouds']
# data['productsDir'] = '/home/david/NAS/sentinelImages/L2A/'
# data['linksDir'] = '/home/david/centroGEO/repsat/tests/L2A/'
data['productsDir'] = products_dir data['productsDir'] = products_dir
data['linksDir'] = linksDir data['linksDir'] = linksDir
data['username'] = 'emmhp' data['username'] = API_SENTINEL_USER
data['password'] = 'geoemm29' data['password'] = API_SENTINEL_PASS
#json_data = json.dumps(data, indent=4,sort_keys=True) #json_data = json.dumps(data, indent=4,sort_keys=True)
#formatea el json #formatea el json
...@@ -510,7 +531,9 @@ def showCart(request): ...@@ -510,7 +531,9 @@ def showCart(request):
#escribe el json en el archivo #escribe el json en el archivo
fidProductsFile = open(search_dir+"/findProducts.json", "w") fidProductsFile = open(search_dir+"/findProducts.json", "w")
fidProductsFile.write(json_data) fidProductsFile.write(json_data)
fidProductsFile.close() fidProductsFile.close()
os.system("L2ASCL_AreaProcessing.sh "+search_dir+"/ 1 > "+search_dir+"/L2ASCL_AreaProcessing.log") ###ejecuta el proceso
...@@ -531,28 +554,10 @@ def showCart(request): ...@@ -531,28 +554,10 @@ def showCart(request):
#~ }) #~ })
#~ return JsonResponse({'product_list': prod_list}) #~ return JsonResponse({'product_list': prod_list})
#------------------------------------- #-------------------------------------
user = User.objects.get(id=request.user.id)
prod_list = []
product_list = Purchase.objects.values('user', 'productList', 'purchased', 'price', 'aggreg_date').filter(user=user, purchased=0)
total_price = 0
total_products = 0
for products in product_list:
product = json.loads(products['productList'])
prod_list.append({
'purchased': products['purchased'],
'price': products['price'],
'aggreg_date': products['aggreg_date'],
'catalog': product
})
total_price += products['price']
total_products += 1
return render(request, 'show_cart.html', {'product_list': prod_list, 'total_price': total_price, 'total_products': total_products})
#-------------------------------------
def Pay (request):
Purchase.objects.filter(user_id=request.user.id, purchased=0).update(purchased=True) Purchase.objects.filter(user_id=request.user.id, purchased=0).update(purchased=True)
return redirect('../../reports') return redirect('../../reports')
{ {
"PATHS": { "PATHS": {
"PATH_GEOSENTINEL": "/home/david/centroGEO/repsat/Geosentinel", "PATH_GEOSENTINEL": "/home/david/centroGEO/repsat/Geosentinel",
"PATH_NAS": "/home/david/NAS/" "PATH_NAS": "/home/david/NAS/",
"PATH_USERS" : "/home/david/NAS/repsat_test_dev/"
}, },
"API_SENTINEL": { "API_SENTINEL": {
"SENTINEL_USER" : "emmhp", "SENTINEL_USER" : "emmhp",
......
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