Esempio n. 1
0
def ajax_get_layer_data(request):
	layer_id = request.GET.get('layer_id')
	
	if layer_id:
		layer = WorkspaceLayer.objects.get(pk=layer_id)
		table_columns = TableColumnDescriptor.objects.filter(table=layer.table)
		
		fields = []
		columns = []
		for table_column in table_columns:
			fields.append({'name':table_column.id, 'type':change_to_extjs_field_type(table_column.data_type)})
			columns.append({'name':table_column.id, 'header':table_column.name, 'dataIndex':table_column.id})
		
		metadata = {'idProperty':'id', 'root':'rows','sort_info':{'field':'id','direction':'ASC'},'fields':fields}
		
		from project.functions import get_table_data
		data = get_table_data(layer.table)
		
		rows = []
		for datum in data:
			datum_columns = {'id':datum.id}
			for table_column in table_columns:
				datum_columns[table_column.id] = getattr(datum, table_column.db_column_name)
			
			rows.append(datum_columns)
		
		table_data = {'metaData':metadata, 'success':True, 'results':len(data), 'rows':rows, 'columns':columns}
		
		return HttpResponse(simplejson.dumps(table_data))
	
	return HttpResponse('')
Esempio n. 2
0
def ajax_get_layer_spatial_data(request):
	layer_ids = request.GET.getlist('layer')
	
	if layer_ids:
		layers = []
		for layer_id in layer_ids:
			layer = WorkspaceLayer.objects.get(pk=layer_id)
			
			from project.functions import get_table_data
			data = get_table_data(layer.table)
			
			rows = []
			for datum in data:
				datum_columns = {'id':datum.id, 'spatial':serialize_spatial(getattr(datum, 'spatial'))}
				rows.append(datum_columns)
				
			layers.append({'id':layer.id, 'name':layer.name, 'spatial_type':layer.table.spatial_type, 'rows':rows})
			
		return HttpResponse(simplejson.dumps({'layers':layers}))
		
	return HttpResponse('')