Exemplo n.º 1
0
def linechart_update(request, layer_id, chart_id):
    if request.method == 'POST':
        layer = Layer.objects.get(id=int(layer_id))
        chart = Chart.objects.get(id=int(chart_id))

        title = request.POST.get('title')
        description = request.POST.get('description')
        chart_conf = request.POST.get('chart_conf')

        chart.title = title
        chart.description = description
        chart.conf = chart_conf

        chart.save()

        return HttpResponse(json.dumps({'success': True}, indent=4),
                            content_type='application/json')

    else:
        layer = Layer.objects.get(id=int(layer_id))
        chart = Chart.objects.get(id=int(chart_id))

        layer = Layer.objects.get(id=int(layer_id))
        datastore = Datastore.objects.get(id=layer.datastore_id)
        workspace = Workspace.objects.get(id=datastore.workspace_id)
        gs = geographic_servers.get_instance().get_server_by_id(
            workspace.server.id)

        (ds_type, resource) = gs.getResourceInfo(workspace.name, datastore,
                                                 layer.name, "json")
        fields = utils.get_fields(resource)
        numeric_fields = utils.get_numeric_fields(fields)
        alpha_numeric_fields = utils.get_alphanumeric_fields(fields)
        geom_fields = utils.get_geometry_fields(fields)

        conf = json.loads(chart.conf)

        y_axis_begin_at_zero = False
        if 'y_axis_begin_at_zero' in conf:
            y_axis_begin_at_zero = conf['y_axis_begin_at_zero']

        return render(
            request, 'linechart_update.html', {
                'layer_id': layer_id,
                'chart_id': chart_id,
                'fields': json.dumps(fields),
                'numeric_fields': json.dumps(numeric_fields),
                'alpha_numeric_fields': json.dumps(alpha_numeric_fields),
                'geom_fields': json.dumps(geom_fields),
                'title': chart.title,
                'description': chart.description,
                'dataset_type': conf['dataset_type'],
                'x_axis_title': conf['x_axis_title'],
                'y_axis_title': conf['y_axis_title'],
                'y_axis_begin_at_zero': y_axis_begin_at_zero,
                'geographic_names_column': conf['geographic_names_column'],
                'geometries_column': conf['geometries_column'],
                'selected_columns': json.dumps(conf['columns'])
            })
Exemplo n.º 2
0
def piechart_add(request, layer_id):
    if request.method == 'POST':
        layer = Layer.objects.get(id=int(layer_id))

        title = request.POST.get('title')
        description = request.POST.get('description')
        chart_conf = request.POST.get('chart_conf')

        chart = Chart(layer=layer,
                      type='piechart',
                      title=title,
                      description=description,
                      conf=chart_conf)
        chart.save()

        return HttpResponse(json.dumps({'success': True}, indent=4),
                            content_type='application/json')

    else:
        layer = Layer.objects.get(id=int(layer_id))

        layer = Layer.objects.get(id=int(layer_id))
        datastore = Datastore.objects.get(id=layer.datastore_id)
        workspace = Workspace.objects.get(id=datastore.workspace_id)
        gs = geographic_servers.get_instance().get_server_by_id(
            workspace.server.id)

        (ds_type, resource) = gs.getResourceInfo(workspace.name, datastore,
                                                 layer.name, "json")
        fields = utils.get_fields(resource)
        numeric_fields = utils.get_numeric_fields(fields)
        alpha_numeric_fields = utils.get_alphanumeric_fields(fields)
        geom_fields = utils.get_geometry_fields(fields)

        conf = {
            'layer_id': layer_id,
            'fields': json.dumps(fields),
            'numeric_fields': json.dumps(numeric_fields),
            'alpha_numeric_fields': json.dumps(alpha_numeric_fields),
            'geom_fields': json.dumps(geom_fields)
        }

        return render(request, 'piechart_add.html', conf)