switch de publico

parent 7f9d7b16
import re
from django.shortcuts import HttpResponseRedirect
from django.urls import reverse
......@@ -7,7 +8,7 @@ from catalog.models import Publics, Purchase
class AuthRequiredMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
self.get_response = get_response
def __call__(self, request):
# Code to be executed for each request before
......@@ -16,12 +17,24 @@ class AuthRequiredMiddleware(object):
if "/reports/" in request.path_info and not request.user.is_authenticated:
if re.match("^(?:\/reports\/)+[0-9]*$", request.path_info):
purchase_id = request.path_info.replace("/reports/", "")
print ("----->", purchase_id)
purchase = Purchase.objects.filter(pk=int(purchase_id))
if len(purchase) > 0 and purchase[0].is_public == True:
return response
else:
return HttpResponseRedirect(reverse('login'))
#elif not request.user.is_authenticated and request.path_info == reverse('tile') or request.path_info == reverse('tileinfo') :
# return response
#if "/reports/" in request.path_info and "/scl_data" in request.path_info and purchase:
if "/reports/" in request.path_info and "/scl_data" in request.path_info:
pass
elif request.path_info == reverse('ipn'):
print(request.path_info)
return response
elif not request.user.is_authenticated and request.path_info != reverse('login') and not request.user.is_active:
return HttpResponseRedirect(reverse('login'))
......
......@@ -195,7 +195,7 @@
class="hidden" {% endif %}>
<a title="View Report"
{% if product.initial_folder %}
href="../reports/{{ product.purchase_id }}/{{ product.initial_folder }}"
href="../reports/{{ product.purchase_id }}"
{% endif %}
class="btn btn-success">
<i class="fa fa-eye"></i>
......
<div class="form-group">
<br>
<ul class="sidebar-menu" data-widget="tree">
{% if request.user.is_authenticated %}
<li>
<a class="treeview " href="{{ BASE_URL }}/reports">
<i class="fa fa-map"></i>
......@@ -10,6 +11,7 @@
</span>
</a>
</li>
{% endif %}
{% if folders %}
<li class="treeview">
<a href="#">
......
......@@ -4,7 +4,8 @@ from . import views
from reports import views
urlpatterns = [
url(r'^(?P<purchase_id>(\d+))/(?P<report>[\w\-]+)$', views.report_L2ASCL, name='report'),
#url(r'^(?P<purchase_id>(\d+))/(?P<report>[\w\-]+)$', views.report_L2ASCL, name='report'),
url(r'^(?P<purchase_id>(\d+))$', views.report_L2ASCL, name='report'),
url(r'^$', views.Reports, name='reports'),
url(r'^ws/process_progress$', views.wsProcessProgress, name='wsProcessProgress'),
url(r'^ws/is_public', views.wsIs_Public, name='wsIs_Public'),
......
......@@ -30,19 +30,14 @@ USERS_PATH = config['PATHS']['PATH_USERS']
###########################################################
def report_L2ASCL(request, report, purchase_id):
purchase = Purchase.objects.filter(pk=purchase_id, is_public=True)
if not request.user.is_authenticated and purchase:
email = "user@algo.com"
print (email)
elif not request.user.is_authenticated and not purchase:
return redirect('../../../')
else:
email = request.user.email
def report_L2ASCL(request, purchase_id):
template = "sclData.html"
reporteDir = 'mask'
folders = ""
purchase = Purchase.objects.values('user__email','is_public').filter(pk=purchase_id)
email = purchase[0]['user__email']
path = USERS_PATH + email + '/' + purchase_id + '/'
scl_data_path = USERS_PATH + email + "/" + purchase_id + "/" + report + ".json"
scl_data_path = USERS_PATH + email + "/" + purchase_id + "/scl_data.json"
with open(USERS_PATH + email + "/" + purchase_id + "/findProducts.json") as p:
......@@ -53,49 +48,6 @@ def report_L2ASCL(request, report, purchase_id):
dataProduct['endDate'])[6:8]
graphData, label, defaultLabel, defaultDataset,datasets = ProcessChartData(scl_data_path)
#print(datasets)
if report == 'scl_data':
template = "sclData.html"
reporteDir='mask'
folders=""
#return render(request,"sclData.html",{"graphData": json.dumps(graphData),
# "report_name": "Aqui va el mapa",
# "startDate": startDate, "endDate": endDate,
# "clouds": dataProduct['clouds'], "platform": dataProduct['platform'],
# "productLevel": dataProduct['productLevel'],'dafaultLabel': defaultLabel,
# 'defaultDataSet': defaultDataset,"purchaseID": purchase_id,
# "labels": graphData['data']['labels']})
else:
template = "L2ASCL_data.html"
reporteDir = report.replace('_sclData', '')
reporteDir += "/mask"
absolute_path = USERS_PATH + email + "/" + purchase_id + "/out"
folders = os.listdir(absolute_path)
json_route = USERS_PATH + email + "/" + purchase_id + "/"
for file in os.listdir(json_route):
if file.endswith("_sclData.json") and not file.endswith("merge_out_sclData.json"):
with open(USERS_PATH + email + "/" + purchase_id + "/" + file) as f:
json_data = OrderedDict(json.load(f))
if len(json_data) == 0:
if file[:6] in folders:
folders.remove(file[:6])
with open(USERS_PATH + email + "/" + purchase_id + "/" + report + ".json") as f:
json_data = OrderedDict(json.load(f))
if len(json_data) == 0:
graphData = ""
defaultLabel = ""
defaultDataset = ""
folders.remove(reporteDir)
image_path = email + "/" + purchase_id + "/" + "out/" + reporteDir + "/TCI/thumbnails/"
SCL_path = email + "/" + purchase_id + "/" + "out/" + reporteDir + "/SCL/"
......@@ -228,12 +180,12 @@ def wsProcessProgress(request):
if request.is_ajax():
progress = 0
productList2 = []
product_list = Purchase.objects.values('id', 'productList', 'aggreg_date', 'search__clouds',
product_list = Purchase.objects.values('id','user__email', 'productList', 'aggreg_date', 'search__clouds',
'search__startDate', 'search__endDate',
'search__process_id__name', 'progress').filter(user_id=request.user.id,
purchased=1)
for producto in product_list:
log_info = USERS_PATH + request.user.email + "/" + str(producto['id']) + "/L2ASCL_AreaProcessing.log"
log_info = USERS_PATH + producto['user__email'] + "/" + str(producto['id']) + "/L2ASCL_AreaProcessing.log"
#####################################################
# progress bar #
......@@ -277,12 +229,15 @@ def wsProcessProgress(request):
# tiles
def tiles(request, purchase_id, report, layer_type, date, z, x, y):
purchase = Purchase.objects.values('user__email', 'is_public').filter(pk=purchase_id)
email = purchase[0]['user__email']
split = '/split' if layer_type[:3] == "SCL" else ''
layer_class = layer_type[3:] if layer_type[:3] == "SCL" else ''
m_number = '60' if layer_type[:3] == "SCL" else '10'
image_path = "{}{}/{}/out/{}/{}{}/tiles/{}_{}_{}m{}/{}/{}/{}.png".format(
USERS_PATH, request.user.email, purchase_id, report, layer_type[:3], split,
USERS_PATH, email, purchase_id, report, layer_type[:3], split,
date, layer_type[:3], m_number, layer_class, z, x, y
)
......@@ -300,14 +255,20 @@ def tileinfo(request):
if request.is_ajax():
req = dict(request.POST)
purchase = Purchase.objects.values('user__email').filter(pk=int(req['purchase_id'][0]))
email = purchase[0]['user__email']
resource_path = "{}{}/{}/out/{}/TCI/tiles/{}_TCI_10m/tilemapresource.xml".format(
USERS_PATH, request.user.email, req['purchase_id'][0], req['report'][0],
USERS_PATH, email, req['purchase_id'][0], req['report'][0],
req['date'][0]
)
if not os.path.exists(resource_path):
raise Http404
tree = ET.parse(resource_path)
bounding_box = tree.find('BoundingBox')
sets = [int(set.get('order')) for set in tree.findall('TileSets/TileSet')]
......@@ -331,6 +292,7 @@ def tileinfo(request):
raise Http404
# ------------------------------------------------------------------------
def PDFGenerator(request, ruta, reporteDir, datasets):
thumbs = ruta + 'out/' + reporteDir + '/TCI/thumbnails/'
......
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