flask-admin-csv-model


Nameflask-admin-csv-model JSON
Version 0.0.1 PyPI version JSON
download
home_pagehttps://github.com/fholmer/flask-admin-csv-model
SummaryA CSV-file model backend for Flask-Admin
upload_time2023-08-05 06:06:50
maintainer
docs_urlNone
authorFrode Holmer
requires_python
licenseBSD-3-Clause
keywords flask-admin csv
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # flask-admin-csv-model

A CSV-file model backend for Flask-Admin

## Warning

- This is a beta version. Not ready for production.

## Installation

Open command line and and install using pip:

```bash

$ pip install flask-admin-csv-model

```

## Usage

The first step is to initialize an empty admin interface for your Flask app:

```python

from flask import Flask
import flask_admin as admin

app = Flask(__name__)
app.config["SECRET_KEY"] = "123456790"


@app.route("/")
def index():
    return '<a href="/admin/">Click me to get to Admin!</a>'


if __name__ == "__main__":

    admin = admin.Admin(app, name="Example: Csv")
    app.run(debug=True)

```

Adding Model View:

```python

import pathlib
import csv
from flask_admin_csv_model.contrib.csv import ModelView, Model, TextField

csv_file = pathlib.Path("./example.csv")
with csv_file.open() as f:
    dialect = csv.Sniffer().sniff(f.read(1024))

class BaseModel(Model):
    class Meta:
        file: pathlib.Path = csv_file
        dialect: csv.Dialect = dialect

class Data(BaseModel):
    first = TextField()
    second = TextField()
    third = TextField()
    fourth = TextField()
    fifth = TextField()

class DataAdmin(ModelView):
    can_delete = True
    can_create = True
    can_edit = True

admin = admin.Admin(app, name="Example: Csv")
admin.add_view(DataAdmin(Data))

```

### To run this example

1. Clone the repository:

    ```bash
    git clone https://github.com/fholmer/flask-admin-csv-model
    cd flask-admin-csv-model
    ```

2. Create and activate a virtual environment:

    ```bash
    python3 -m venv .venv
    source .venv/bin/activate
    ```

3. Install requirements:

    ```bash
    pip install -r requirements.txt
    ```


4. Run the application::

    ```bash
    python app.py
    ```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/fholmer/flask-admin-csv-model",
    "name": "flask-admin-csv-model",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "flask-admin,csv",
    "author": "Frode Holmer",
    "author_email": "fholmer+flask@gmail.com",
    "download_url": "",
    "platform": null,
    "description": "# flask-admin-csv-model\n\nA CSV-file model backend for Flask-Admin\n\n## Warning\n\n- This is a beta version. Not ready for production.\n\n## Installation\n\nOpen command line and and install using pip:\n\n```bash\n\n$ pip install flask-admin-csv-model\n\n```\n\n## Usage\n\nThe first step is to initialize an empty admin interface for your Flask app:\n\n```python\n\nfrom flask import Flask\nimport flask_admin as admin\n\napp = Flask(__name__)\napp.config[\"SECRET_KEY\"] = \"123456790\"\n\n\n@app.route(\"/\")\ndef index():\n    return '<a href=\"/admin/\">Click me to get to Admin!</a>'\n\n\nif __name__ == \"__main__\":\n\n    admin = admin.Admin(app, name=\"Example: Csv\")\n    app.run(debug=True)\n\n```\n\nAdding Model View:\n\n```python\n\nimport pathlib\nimport csv\nfrom flask_admin_csv_model.contrib.csv import ModelView, Model, TextField\n\ncsv_file = pathlib.Path(\"./example.csv\")\nwith csv_file.open() as f:\n    dialect = csv.Sniffer().sniff(f.read(1024))\n\nclass BaseModel(Model):\n    class Meta:\n        file: pathlib.Path = csv_file\n        dialect: csv.Dialect = dialect\n\nclass Data(BaseModel):\n    first = TextField()\n    second = TextField()\n    third = TextField()\n    fourth = TextField()\n    fifth = TextField()\n\nclass DataAdmin(ModelView):\n    can_delete = True\n    can_create = True\n    can_edit = True\n\nadmin = admin.Admin(app, name=\"Example: Csv\")\nadmin.add_view(DataAdmin(Data))\n\n```\n\n### To run this example\n\n1. Clone the repository:\n\n    ```bash\n    git clone https://github.com/fholmer/flask-admin-csv-model\n    cd flask-admin-csv-model\n    ```\n\n2. Create and activate a virtual environment:\n\n    ```bash\n    python3 -m venv .venv\n    source .venv/bin/activate\n    ```\n\n3. Install requirements:\n\n    ```bash\n    pip install -r requirements.txt\n    ```\n\n\n4. Run the application::\n\n    ```bash\n    python app.py\n    ```\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "A CSV-file model backend for Flask-Admin",
    "version": "0.0.1",
    "project_urls": {
        "Homepage": "https://github.com/fholmer/flask-admin-csv-model",
        "Source Code": "https://github.com/fholmer/flask-admin-csv-model"
    },
    "split_keywords": [
        "flask-admin",
        "csv"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fe28ec681cbb08a14e3a41990d0a1b3c884d5067823b2d6d69b498a95acdaa60",
                "md5": "ec18e83037e738212ec0c6850d279195",
                "sha256": "2a7c2194d8285484d9236e45834d678519edc782ee3faa424a6fbbec633a0049"
            },
            "downloads": -1,
            "filename": "flask_admin_csv_model-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ec18e83037e738212ec0c6850d279195",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5872,
            "upload_time": "2023-08-05T06:06:50",
            "upload_time_iso_8601": "2023-08-05T06:06:50.388395Z",
            "url": "https://files.pythonhosted.org/packages/fe/28/ec681cbb08a14e3a41990d0a1b3c884d5067823b2d6d69b498a95acdaa60/flask_admin_csv_model-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-05 06:06:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fholmer",
    "github_project": "flask-admin-csv-model",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "flask-admin-csv-model"
}
        
Elapsed time: 0.12905s