Skip to content

Commit

Permalink
delete validatino kml files syntaxis error
Browse files Browse the repository at this point in the history
  • Loading branch information
gtsarik committed Nov 20, 2017
1 parent 6a9f223 commit a607292
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 106 deletions.
89 changes: 12 additions & 77 deletions src/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,10 @@ class DataSetList(APIView):
authentication_classes = (SessionAuthentication, BasicAuthentication, TokenAuthentication)
# authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
data = {'auth': 'Need YOUR ACCESS TOKEN'}

def get(self, request, format=None):
data = {'auth': 'Need YOUR ACCESS TOKEN'}

if request.auth:
customer_access = CustomerAccess.objects.get(user=request.user)
queryset = DataSet.objects.filter(customer_access=customer_access).order_by('id')
Expand All @@ -366,7 +367,6 @@ class DataSetDetail(APIView):
authentication_classes = (SessionAuthentication, BasicAuthentication, TokenAuthentication)
# authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
data = {'auth': 'Need YOUR ACCESS TOKEN'}

def get_object(self, ds_id):
try:
Expand All @@ -375,6 +375,8 @@ def get_object(self, ds_id):
raise Http404

def get(self, request, ds_id, format=None):
data = {'auth': 'Need YOUR ACCESS TOKEN'}

if request.auth:
dataset = self.get_object(ds_id)
serializer = DataSetsSerializer(dataset)
Expand All @@ -391,7 +393,6 @@ class ShapeFileDetail(APIView):
authentication_classes = (SessionAuthentication, BasicAuthentication, TokenAuthentication)
# authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
data = {'auth': 'Need YOUR ACCESS TOKEN'}

def get_object(self, sf_id):
try:
Expand All @@ -400,6 +401,8 @@ def get_object(self, sf_id):
raise Http404

def get(self, request, sf_id, format=None):
data = {'auth': 'Need YOUR ACCESS TOKEN'}

if request.auth:
# in_path = '/home/grigoriy/test/TMP/1_test.txt'
# out_path = '/home/grigoriy/test/TMP/11'
Expand All @@ -422,7 +425,6 @@ class TimeSeriesDetail(APIView):
authentication_classes = (SessionAuthentication, BasicAuthentication, TokenAuthentication)
# authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
data = {'auth': 'Need YOUR ACCESS TOKEN'}

def get_object(self, ts_id):
try:
Expand All @@ -431,6 +433,8 @@ def get_object(self, ts_id):
raise Http404

def get(self, request, ts_id, format=None):
data = {'auth': 'Need YOUR ACCESS TOKEN'}

if request.auth:
timeseries = self.get_object(ts_id)
serializer = TimeSeriesResultSerializer(timeseries)
Expand All @@ -447,7 +451,6 @@ class UploadFileAoiView(APIView):
authentication_classes = (SessionAuthentication, BasicAuthentication, TokenAuthentication)
# # authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
data = {'auth': 'Need YOUR ACCESS TOKEN'}
# parser_classes = (FileUploadParser,)

def get_object(self, ds_id):
Expand All @@ -457,6 +460,8 @@ def get_object(self, ds_id):
raise Http404

def post(self, request, ds_id, format=None):
data = {'auth': 'Need YOUR ACCESS TOKEN'}

if request.auth:
file_obj = request.FILES['file']
dataset = self.get_object(ds_id)
Expand Down Expand Up @@ -516,9 +521,10 @@ class UploadFileFtpView(APIView):
authentication_classes = (SessionAuthentication, BasicAuthentication, TokenAuthentication)
# authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
data = {'auth': 'Need YOUR ACCESS TOKEN'}

def post(self, request, format=None):
data = {'auth': 'Need YOUR ACCESS TOKEN'}

if request.auth:
file_obj = request.FILES['file']
file_name = file_obj.name
Expand All @@ -537,77 +543,6 @@ def post(self, request, format=None):
return Response(data)


# class DataSetsList(APIView):
# """
# View to list all users in the system.

# * Requires token authentication.
# * Only admin users are able to access this view.
# """

# authentication_classes = (SessionAuthentication, BasicAuthentication, TokenAuthentication)
# # authentication_classes = (SessionAuthentication, BasicAuthentication)
# permission_classes = (IsAuthenticated,)
# data = None

# def get_queryset(self):
# queryset = DataSet.objects.all()
# return queryset

# def get(self, request, format=None):
# # print 'GET auth ===================================== ', request.auth
# # print 'GET request shapefile ===================================== ', request.query_params
# content = {}
# error = False

# if request.auth:
# if request.query_params:
# try:
# if not 'shapefile' in request.query_params or not 'timeseries' in request.query_params:
# content = {'message error': 'Invalid or missing the parameters for request.'}

# if 'shapefile' in request.query_params:
# # dataset_id = request.query_params['dataset']
# shapefile_id = request.query_params['shapefile']

# # if not DataSet.objects.filter(id=dataset_id).exists():
# # content['error the parameter "dataset"'] = 'Invalid or missing the parameters "dataset".'
# # error = True
# # shapefile = CustomerPolygons.objects.get(id=shapefile_id)
# # url_status = status.HTTP_200_OK
# if not CustomerPolygons.objects.filter(id=shapefile_id).exists():
# content['error the parameter "shapefile"'] = 'Invalid or missing the parameters "shapefile".'
# else:
# if not error:
# data = CustomerPolygons.objects.get(id=shapefile_id)
# # data = DataSet.objects.get(id=dataset_id, shapefiles=shapefile_id)
# # serializer = DataSetSerializer(data)
# serializer = CustomerPolygonSerializer(data)
# content = serializer.data

# if 'timeseries' in request.query_params:
# pass
# except CustomerPolygons.DoesNotExist:
# content = {'message error': 'Invalid or missing the parameters for request.'}
# else:
# customer_access = CustomerAccess.objects.get(user=request.user)
# queryset = DataSet.objects.filter(customer_access=customer_access).order_by('id')
# serializer = DataSetsSerializer(queryset, many=True)
# content = serializer.data
# else:
# content = {
# 'auth': 'Need YOUR ACCESS TOKEN',
# }

# # content = {
# # 'user': unicode(request.user), # `django.contrib.auth.User` instance.
# # 'auth': unicode(request.auth), # None
# # }
# # print 'request.user ======================== ', request.user

# return Response(content)


@api_view(['GET',])
@authentication_classes((SessionAuthentication, BasicAuthentication))
@permission_classes((IsAuthenticated,))
Expand Down
93 changes: 64 additions & 29 deletions src/customers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2758,7 +2758,7 @@ def customer_section(request):
else:
dirs_list = getTsResultDirectory(data_set)

print '!!!!!!!!!!!!!!!!!!!! DIRRR LISTTT ============================ ', dirs_list
# print '!!!!!!!!!!!!!!!!!!!! DIRRR LISTTT ============================ ', dirs_list

if dirs_list:
info_panel = createCustomerInfoPanel(
Expand Down Expand Up @@ -4254,6 +4254,52 @@ def get_coord_aoi(doc):
except Exception:
pass

try:
outer_boundary_is = doc.Placemark.Polygon.outerBoundaryIs

for n in xrange(len(outer_boundary_is)):
tmp_tuples = []
tmp = str(doc.Placemark.Polygon.outerBoundaryIs[n].LinearRing.coordinates).split('\n')

# print '!!!!!!!!!!!!!!!! TMP ======================== ', len(tmp)

if len(tmp) == 1:
tmp_copy = []
tmp_list = tmp[0].split(' ')

# print '!!!!!!!!!!!!!!!! TMP LIST ======================== ', tmp_list

for m in tmp_list:
m_split = m.split(',')

# print '!!!!!!!!!!!!!!!! M SPLIT ======================== ', m_split

if m_split[-1] == '0.0':
tmp_copy.append(tuple(m_split[:-1]))

# print '!!!!!!!!!!!!!!!! TMP COPY ======================== ', tmp_copy

outer_coord.append(tmp_copy)

# print '!!!!!!!!!!!!!!!! outer_coord ======================== ', outer_coord
else:
if not tmp[0]:
tmp = tmp[1:]

if not tmp[-1]:
tmp = tmp[:-1]

for m in tmp:
line = m.split(',')
tmp_tuples.append(tuple(line))

# print '!!!!!!!!!!!!!!!! outer_boundary_is ======================== ', len(tmp)
# print '!!!!!!!!!!!!!!!! outer_boundary_is ======================== ', tmp_tuples

outer_coord.append(tmp_tuples)
except Exception:
pass

try:
inner_boundary_is = doc.Document.Placemark.Polygon.innerBoundaryIs

Expand Down Expand Up @@ -4344,14 +4390,14 @@ def validation_kml(kml_name, kml_path):
The file has more than 1000 objects'.format(file_name)
return error_msg

try:
schema_ogc = Schema("ogckml22.xsd")
schema_gx = Schema("kml22gx.xsd")
# try:
# schema_ogc = Schema("ogckml22.xsd")
# schema_gx = Schema("kml22gx.xsd")

schema_ogc.assertValid(kml_name)
schema_gx.assertValid(kml_name)
except Exception, e:
return str(e)
# schema_ogc.assertValid(kml_name)
# schema_gx.assertValid(kml_name)
# except Exception, e:
# return str(e)

return error_msg

Expand Down Expand Up @@ -4836,33 +4882,22 @@ def files_lister(request):

try:
if not error:
count_color = get_count_color()

try:
count_color = get_count_color()
name_kml = doc_kml.Document.Placemark.description
upload_file = file_name
calculation_aoi = True
# print '!!!!!!!!!!!!!!! KML description NAME ===================== ', name_kml
if doc_kml.Document.Placemark.Polygon.outerBoundaryIs:
calculation_aoi = True
except Exception, e:
print '!!!!!!!!!!!!!!! ERROR EE ===================== ', e
# name_kml = ''
print '!!!!!!!!!!!!!!! ERROR KML Document ===================== ', e

if not name_kml:
try:
name_kml = doc_kml.Document.Placemark.name
upload_file = file_name
try:
if doc_kml.Placemark.Polygon.outerBoundaryIs:
calculation_aoi = True
# print '!!!!!!!!!!!!!!! KML description NAME ===================== ', name_kml
except Exception, e:
print '!!!!!!!!!!!!!!! ERROR EE ===================== ', e
# name_kml = ''

if not calculation_aoi:
name_kml = ''

# print '!!!!!!!!!!!!!!! KML NAME ===================== ', name_kml
except Exception, e:
print '!!!!!!!!!!!!!!! ERROR KML Placemark ===================== ', e

info_window = '<h4 align="center" style="color:{0};"><b>Attribute report: {1}</b></h4>\n'.format(
COLOR_HEX_NAME[count_color], name_kml)
COLOR_HEX_NAME[count_color], f_name)

except Exception, e:
print '!!!!!!!!!!!!!!! ERROR COPY KML ===================== ', e
Expand Down

0 comments on commit a607292

Please sign in to comment.