Ejemplo n.º 1
0
    def post(self, request, schema, table):
        """
        Handles the behaviour if a .csv-file is sent to the view of a table.
        The contained datasets are inserted into the corresponding table via
        the API.
        :param request: A HTTP-request object sent by the Django framework
        :param schema: Name of a schema
        :param table: Name of a table
        :return: Redirects to the view of the table the data was sent to.
        """
        if request.POST and request.FILES:
            csvfile = TextIOWrapper(request.FILES['csv_file'].file,
                                    encoding=request.encoding)

            reader = csv.DictReader(csvfile, delimiter=',')

            actions.data_insert(
                {
                    'schema': schema,
                    'table': table,
                    'method': 'values',
                    'values': reader
                }, {'user': request.user})
        return redirect('/dataedit/view/{schema}/{table}'.format(schema=schema,
                                                                 table=table))
Ejemplo n.º 2
0
    def post(self, request, schema, table):
        """
        Handles the behaviour if a .csv-file is sent to the view of a table.
        The contained datasets are inserted into the corresponding table via
        the API.
        :param request: A HTTP-request object sent by the Django framework
        :param schema: Name of a schema
        :param table: Name of a table
        :return: Redirects to the view of the table the data was sent to.
        """
        if request.POST and request.FILES:
            csvfile = TextIOWrapper(request.FILES["csv_file"].file,
                                    encoding=request.encoding)

            reader = csv.DictReader(csvfile, delimiter=",")

            actions.data_insert(
                {
                    "schema": schema,
                    "table": table,
                    "method": "values",
                    "values": reader,
                },
                {"user": request.user},
            )
        return redirect("/dataedit/view/{schema}/{table}".format(schema=schema,
                                                                 table=table))
Ejemplo n.º 3
0
    def post(self, request, schema, table):
        if request.POST and request.FILES:
            csvfile = TextIOWrapper(request.FILES['csv_file'].file,
                                    encoding=request.encoding)

            reader = csv.DictReader(csvfile, delimiter=',')

            actions.data_insert({
                'schema': actions.get_meta_schema_name(schema),
                'table': actions.get_comment_table_name(table),
                'method': 'values',
                'values': reader
            }, {'user': request.user})
        return redirect('/dataedit/view/{schema}/{table}/comments'.format(schema=schema,
                                                                table=table))
Ejemplo n.º 4
0
    def __insert_row(self, request, schema, table, row, row_id=None):
        if row_id and row.get("id", int(row_id)) != int(row_id):
            return actions._response_error(
                "The id given in the query does not " "match the id given in the url"
            )
        if row_id:
            row["id"] = row_id

        context = {
            "connection_id": request.data["connection_id"],
            "cursor_id": request.data["cursor_id"],
            "user": request.user,
        }

        query = {
            "schema": schema,
            "table": table,
            "values": [row] if isinstance(row, dict) else row,
        }

        if not row_id:
            query["returning"] = [{"type": "column", "column": "id"}]
        result = actions.data_insert(query, context)

        return result
Ejemplo n.º 5
0
    def post(self, request, schema, table):
        if request.POST and request.FILES:
            csvfile = TextIOWrapper(request.FILES['csv_file'].file,
                                    encoding=request.encoding)

            reader = csv.DictReader(csvfile, delimiter=',')

            actions.data_insert(
                {
                    'schema': actions.get_meta_schema_name(schema),
                    'table': actions.get_comment_table_name(table),
                    'method': 'values',
                    'values': reader
                }, {'user': request.user})
        return redirect('/dataedit/view/{schema}/{table}/comments'.format(
            schema=schema, table=table))
Ejemplo n.º 6
0
    def __insert_row(self, request, schema, table, row, row_id=None):
        if row_id and row.get('id', int(row_id)) != int(row_id):
            return actions._response_error(
                'The id given in the query does not '
                'match the id given in the url')
        if row_id:
            row['id'] = row_id

        context = {
            'connection_id': request.data['connection_id'],
            'cursor_id': request.data['cursor_id'],
            'user': request.user
        }

        query = {
            'schema': schema,
            'table': table,
            'values': [row] if isinstance(row, dict) else row
        }

        if not row_id:
            query['returning'] = [{'type': 'column', 'column': 'id'}]
        result = actions.data_insert(query, context)

        return result