def csv_step_view(request, upload_session): import_session = upload_session.import_session attributes = import_session.tasks[0].layer.attributes # need to check if geometry is found # if so, can proceed directly to next step for attr in attributes: if attr.binding == u'com.vividsolutions.jts.geom.Point': upload_session.completed_step = 'csv' return _next_step_response(request, upload_session) # no geometry found, let's find all the numerical columns number_names = ['java.lang.Integer', 'java.lang.Double'] point_candidates = sorted([attr.name for attr in attributes if attr.binding in number_names]) # form errors to display to user error = None lat_field = request.POST.get('lat', '') lng_field = request.POST.get('lng', '') if request.method == 'POST': if not lat_field or not lng_field: error = 'Please choose which columns contain the latitude and longitude data.' elif (lat_field not in point_candidates or lng_field not in point_candidates): error = 'Invalid latitude/longitude columns' elif lat_field == lng_field: error = 'You cannot select the same column for latitude and longitude data.' if not error: upload.csv_step(upload_session, lat_field, lng_field) return _next_step_response(request, upload_session) # try to guess the lat/lng fields from the candidates lat_candidate = None lng_candidate = None non_str_in_headers = [] for candidate in attributes: if not isinstance(candidate.name, basestring): non_str_in_headers.append(str(candidate.name)) if candidate.name in point_candidates: if is_latitude(candidate.name): lat_candidate = candidate.name elif is_longitude(candidate.name): lng_candidate = candidate.name if request.method == 'POST': guessed_lat_or_lng = False selected_lat = lat_field selected_lng = lng_field else: guessed_lat_or_lng = bool(lat_candidate or lng_candidate) selected_lat = lat_candidate selected_lng = lng_candidate present_choices = len(point_candidates) >= 2 possible_data_problems = None if non_str_in_headers: possible_data_problems = "There are some suspicious column names in \ your data. Did you provide column names in the header? \ The following names look wrong: " possible_data_problems += ','.join(non_str_in_headers) context = dict(present_choices=present_choices, point_candidates=point_candidates, async_upload=_is_async_step(upload_session), selected_lat=selected_lat, selected_lng=selected_lng, guessed_lat_or_lng=guessed_lat_or_lng, layer_name=import_session.tasks[0].layer.name, error=error, possible_data_problems=possible_data_problems ) return render_to_response('upload/layer_upload_csv.html', RequestContext(request, context))
def csv_step_view(request, upload_session): import_session = upload_session.import_session if request.GET.__contains__('force_ajax') and request.GET['force_ajax']: url = reverse('data_upload') + "?id=%s" % import_session.id return json_response( {'url': url, 'status': 'incomplete', 'success': True, 'redirect_to': '/upload/csv', 'input_required': True, } ) item = import_session.tasks[0].items[0] feature_type = item.resource attributes = feature_type.attributes # need to check if geometry is found # if so, can proceed directly to next step for attr in attributes: if attr.binding == u'com.vividsolutions.jts.geom.Point': upload_session.completed_step = 'csv' return _next_step_response(request, upload_session) # no geometry found, let's find all the numerical columns number_names = ['java.lang.Integer', 'java.lang.Double'] point_candidates = [attr.name for attr in attributes if attr.binding in number_names] point_candidates.sort() # form errors to display to user error = None lat_field = request.POST.get('lat', '') lng_field = request.POST.get('lng', '') if request.method == 'POST': if not lat_field or not lng_field: error = 'Missing latitude/longitude fields' elif (lat_field not in point_candidates or lng_field not in point_candidates): error = 'Invalid latitude/longitude fields' elif lat_field == lng_field: error = 'Cannot choose same column for latitude and longitude' if not error: upload.csv_step(upload_session, lat_field, lng_field) return _next_step_response(request, upload_session) # try to guess the lat/lng fields from the candidates lat_candidate = None lng_candidate = None for candidate in attributes: if candidate.name in point_candidates: if is_latitude(candidate.name): lat_candidate = candidate.name elif is_longitude(candidate.name): lng_candidate = candidate.name if request.method == 'POST': guessed_lat_or_lng = False selected_lat = lat_field selected_lng = lng_field else: guessed_lat_or_lng = bool(lat_candidate or lng_candidate) selected_lat = lat_candidate selected_lng = lng_candidate present_choices = len(point_candidates) >= 2 context = dict(present_choices=present_choices, point_candidates=point_candidates, async_upload=_is_async_step(upload_session), selected_lat=selected_lat, selected_lng=selected_lng, guessed_lat_or_lng=guessed_lat_or_lng, layer_name = import_session.tasks[0].items[0].layer.name, error = error, ) return render_to_response('upload/layer_upload_csv.html', RequestContext(request, context))
def csv_step_view(request, upload_session): import_session = upload_session.import_session attributes = import_session.tasks[0].layer.attributes # need to check if geometry is found # if so, can proceed directly to next step for attr in attributes: if attr.binding == u'com.vividsolutions.jts.geom.Point': upload_session.completed_step = 'csv' return _next_step_response(request, upload_session) # no geometry found, let's find all the numerical columns number_names = ['java.lang.Integer', 'java.lang.Double'] point_candidates = sorted([attr.name for attr in attributes if attr.binding in number_names]) # form errors to display to user error = None lat_field = request.POST.get('lat', '') lng_field = request.POST.get('lng', '') if request.method == 'POST': if not lat_field or not lng_field: error = 'Please choose which columns contain the latitude and longitude data.' elif (lat_field not in point_candidates or lng_field not in point_candidates): error = 'Invalid latitude/longitude columns' elif lat_field == lng_field: error = 'You cannot select the same column for latitude and longitude data.' if not error: upload.csv_step(upload_session, lat_field, lng_field) return _next_step_response(request, upload_session) # try to guess the lat/lng fields from the candidates lat_candidate = None lng_candidate = None non_str_in_headers = [] for candidate in attributes: if not isinstance(candidate.name, basestring): non_str_in_headers.append(str(candidate.name)) if candidate.name in point_candidates: if is_latitude(candidate.name): lat_candidate = candidate.name elif is_longitude(candidate.name): lng_candidate = candidate.name if request.method == 'POST': guessed_lat_or_lng = False selected_lat = lat_field selected_lng = lng_field else: guessed_lat_or_lng = bool(lat_candidate or lng_candidate) selected_lat = lat_candidate selected_lng = lng_candidate present_choices = len(point_candidates) >= 2 possible_data_problems = None if non_str_in_headers: possible_data_problems = "There are some suspicious column names in \ your data. Did you provide column names in the header? \ The following names look wrong: " possible_data_problems += ','.join(non_str_in_headers) context = dict(present_choices=present_choices, point_candidates=point_candidates, async_upload=_is_async_step(upload_session), selected_lat=selected_lat, selected_lng=selected_lng, guessed_lat_or_lng=guessed_lat_or_lng, layer_name=import_session.tasks[0].layer.name, error=error, possible_data_problems=possible_data_problems ) return render_to_response('upload/layer_upload_csv.html', RequestContext(request, context))
def csv_step_view(request, upload_session): import_session = upload_session.import_session if request.GET.__contains__('force_ajax') and request.GET['force_ajax']: url = reverse('data_upload') + "?id=%s" % import_session.id return json_response( {'url': url, 'status': 'incomplete', 'success': True, 'redirect_to': '/upload/csv', 'input_required': True, } ) item = import_session.tasks[0].items[0] feature_type = item.resource attributes = feature_type.attributes # need to check if geometry is found # if so, can proceed directly to next step for attr in attributes: if attr.binding == u'com.vividsolutions.jts.geom.Point': upload_session.completed_step = 'csv' return _next_step_response(request, upload_session) # no geometry found, let's find all the numerical columns number_names = ['java.lang.Integer', 'java.lang.Double'] point_candidates = [attr.name for attr in attributes if attr.binding in number_names] point_candidates.sort() # form errors to display to user error = None lat_field = request.POST.get('lat', '') lng_field = request.POST.get('lng', '') if request.method == 'POST': if not lat_field or not lng_field: error = 'Missing latitude/longitude fields' elif (lat_field not in point_candidates or lng_field not in point_candidates): error = 'Invalid latitude/longitude fields' elif lat_field == lng_field: error = 'Cannot choose same column for latitude and longitude' if not error: upload.csv_step(upload_session, lat_field, lng_field) return _next_step_response(request, upload_session) # try to guess the lat/lng fields from the candidates lat_candidate = None lng_candidate = None for candidate in attributes: if candidate.name in point_candidates: if is_latitude(candidate.name): lat_candidate = candidate.name elif is_longitude(candidate.name): lng_candidate = candidate.name if request.method == 'POST': guessed_lat_or_lng = False selected_lat = lat_field selected_lng = lng_field else: guessed_lat_or_lng = bool(lat_candidate or lng_candidate) selected_lat = lat_candidate selected_lng = lng_candidate present_choices = len(point_candidates) >= 2 context = dict(present_choices=present_choices, point_candidates=point_candidates, async_upload=_is_async_step(upload_session), selected_lat=selected_lat, selected_lng=selected_lng, guessed_lat_or_lng=guessed_lat_or_lng, layer_name = import_session.tasks[0].items[0].layer.name, error = error, ) return render_to_response('upload/layer_upload_csv.html', RequestContext(request, context))