Skip to content

Commit

Permalink
added change name for upload files
Browse files Browse the repository at this point in the history
  • Loading branch information
gtsarik committed Dec 19, 2017
1 parent 696c506 commit 332d311
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
32 changes: 18 additions & 14 deletions src/core/functions_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

def getResultDirectory(dataset, shelfdata):
dirs_list = []
# is_ts = dataset.is_ts

try:
project_directory = os.path.join(PROJECTS_PATH, dataset.results_directory)
Expand Down Expand Up @@ -343,24 +342,29 @@ def uploadFile(request, data_set, file_name, path_ftp_user, path_kml_user, absol

# print '!!!!!!!!!! path_kml_user ================== ', path_kml_user

f_name = str(file_name).split('.')[:-1]
ext = str(file_name).split('.')[-1]
# f_name = str(file_name).split('.')[:-1]
# ext = str(file_name).split('.')[-1]

f_name, ext = os.path.splitext(file_name)

# print '!!!!!!!!!! F NAME ================== ', f_name
# print '!!!!!!!!!! F EXT ================== ', ext

CustomerPolygons.objects.filter(user=request.user,
name=f_name[0]).delete()
name=f_name).delete()

# print '!!!!!!!!!! FILE NAME ================== ', f_name
# print '!!!!!!!!!! FILE EXT ================== ', ext

# if DataPolygons.objects.filter(user=request.user, data_set=data_set,
# customer_polygons__name=f_name[0]).exists():
# customer_polygons__name=f_name).exists():
# DataPolygons.objects.filter(user=request.user, data_set=data_set,
# customer_polygons__name=f_name[0]).delete()
# customer_polygons__name=f_name).delete()

if ext == 'kmz':
zip_file = f_name[0] + '.zip'
if ext == '.kmz':
zip_file = f_name + '.zip'
# doc_file = 'doc.kml'
new_kml_file = '{0}.kml'.format(f_name[0])
new_kml_file = '{0}.kml'.format(f_name)
path_zip_file = os.path.join(path_ftp_user, zip_file)
path_doc_kml = os.path.join(path_ftp_user, 'doc.kml')
path_new_kml = os.path.join(path_ftp_user, new_kml_file)
Expand Down Expand Up @@ -396,7 +400,7 @@ def uploadFile(request, data_set, file_name, path_ftp_user, path_kml_user, absol
count_color = get_count_color()
upload_file = new_kml_file
calculation_aoi = is_calculation_aoi(doc_kml)
info_window = get_info_window(doc_kml, f_name[0], path_new_kml)
info_window = get_info_window(doc_kml, f_name, path_new_kml)

print '!!!!!!!!!!!!!!! KMZ calculation_aoi ============================ ', calculation_aoi

Expand All @@ -407,12 +411,12 @@ def uploadFile(request, data_set, file_name, path_ftp_user, path_kml_user, absol
# print '!!!!!!!!!!!! COORDINATE ======================== ', doc_kml.Document.Polygon.outerBoundaryIs.LinearRing.coordinates

load_aoi = addPolygonToDB(
f_name[0], new_kml_file, request.user,
f_name, new_kml_file, request.user,
new_path, kml_url,
data_set, text_kml=info_window
)

if ext == 'kml':
if ext == '.kml':
kml_url = os.path.join(absolute_kml_url, file_name)
new_path = os.path.join(path_kml_user, file_name)
doc_kml, error = copy_file_kml(path_test_data, new_path)
Expand All @@ -431,7 +435,7 @@ def uploadFile(request, data_set, file_name, path_ftp_user, path_kml_user, absol
count_color = get_count_color()
upload_file = file_name
calculation_aoi = is_calculation_aoi(doc_kml)
info_window = get_info_window(doc_kml, f_name[0], path_test_data)
info_window = get_info_window(doc_kml, f_name, path_test_data)

# print '!!!!!!!!!!!!!!! KML calculation_aoi ============================ ', calculation_aoi

Expand All @@ -445,7 +449,7 @@ def uploadFile(request, data_set, file_name, path_ftp_user, path_kml_user, absol
# print '!!!!!!!!!!!! COORDINATE ======================== ', doc_kml.Document.Polygon.outerBoundaryIs.LinearRing.coordinates

load_aoi = addPolygonToDB(
f_name[0], file_name, request.user,
f_name, file_name, request.user,
new_path, kml_url,
data_set, text_kml=info_window
)
Expand Down
16 changes: 9 additions & 7 deletions src/customers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4277,18 +4277,17 @@ def files_lister(request):

# print '!!!!!!!!!! POST ================== ', data_post
# print '!!!!!!!!!!!!! DATA SET ==================== ', request.session['select_data_set']
# recalculation_btn

if 'recalculation_btn' in data_post:
file_name = data_post['recalculation_btn']
calculation_aoi, upload_file, error = uploadFile(request, data_set, file_name,
path_ftp_user, path_kml_user, absolute_kml_url)

print '!!!!!!!!!!!!!!! calculation_aoi ===================== ', calculation_aoi
print '!!!!!!!!!!!!!!! upload_file ===================== ', upload_file
# print '!!!!!!!!!!!!!!! calculation_aoi ===================== ', calculation_aoi
# print '!!!!!!!!!!!!!!! upload_file ===================== ', upload_file

if error:
print '!!!!!!!!!!!!!!! ERROR ===================== ', error
print '!!!!!!!!!!!!!!! ERROR RE-CALCULATION ===================== ', error

return HttpResponseRedirect(u'%s?warning_message=%s' % (
reverse('files_lister'),
Expand All @@ -4303,14 +4302,17 @@ def files_lister(request):
info_window = ''
name_kml = ''
file_name = str(request.FILES['test_data']).decode('utf-8')
path_test_data = os.path.join(path_ftp_user, file_name)
fl, ext = os.path.splitext(file_name)
new_file_name = '{0}_{1}{2}'.format(data_set, fl, ext)
path_test_data = os.path.join(path_ftp_user, new_file_name)

####################### write log file
files_lister_log.write('LOAD FILE: {0}\n'.format(str(file_name)))
files_lister_log.write('\n')
#######################

# print '!!!!!!!!!! FILE NAME ================== ', file_name
# print '!!!!!!!!!! NEW FILE NAME ================== ', new_file_name

if not os.path.exists(path_ftp_user):
os.makedirs(path_ftp_user)
Expand All @@ -4332,8 +4334,8 @@ def files_lister(request):
calculation_aoi, upload_file, error = uploadFile(request, data_set, file_name,\
path_ftp_user, path_kml_user, absolute_kml_url)

print '!!!!!!!!!!!!!!! calculation_aoi ===================== ', calculation_aoi
print '!!!!!!!!!!!!!!! upload_file ===================== ', upload_file
# print '!!!!!!!!!!!!!!! calculation_aoi ===================== ', calculation_aoi
# print '!!!!!!!!!!!!!!! upload_file ===================== ', upload_file

if error:
print '!!!!!!!!!!!!!!! ERROR ===================== ', error
Expand Down

0 comments on commit 332d311

Please sign in to comment.