Skip to main content

Admin Panel for PostgreSQL DB with Gino ORM

Project description

Gino-Admin

Gino-Admin Logo

Docs (state: in process): Gino-Admin docs

Play with Demo (current master 0.2.3) >>>> Gino-Admin demo <<<< (login: admin, pass: 1234)

badge1 badge2 badge3

Admin Panel for PostgreSQL DB with Gino ORM and Sanic

Table view Load Presets

How to install

pip install gino-admin==0.2.3

How to use

You can find several code examples in examples/ folder.

Updates in version 0.2.2 (current master):

  1. Added support for types: JSONB, JSON and Time. Examples added as part of base_example - /Users/iuliia_volkova2/work/gino-admin/examples/base_example

  2. Main update: Not needed to use gino.ext.sanic in models as it was previos.

Now you can use any ext if you need (for Fast Api for example) or pure Gino() and you not need to add to your models, any ‘ifs’ to have additional gino.ext.sanic to get possible work with gino admin.

All examples was changed according to the update.

  1. Sanic was updated to 20.* version. Switched to use ‘request.ctx.’ in code

  2. Minor things: all date, datetime and timepickers now have default value == to current time/date/datetime.

  3. Tests: was updated structure of integraion tests

Updates in version 0.2.1

  1. Fixes:

1.1 Dependencies - removed unnecessary packages and added one lost for cli. Cli now works correct. 1.2 Login form now provide errors if you enter wrong user or passoword 1.3 Wrong attepts to login in Admin panel are adding to History now

  1. Added possibility to customize UI colors with config.

Default colors schema also changed:

Table view

Config object now has section ‘ui’. In UI section now exist ‘colors’ where you can set up colors that will be used for:

  • Primary buttons. Property: buttons

  • Second buttons. Property: buttons_second

  • Alert buttons (actions that something remove/reset - deleted, drop db and etc). Property: buttons_alert

  • Tables headers. Property: table

  • Tables with Alert headers (like in Init DB). Property: table_alerts

  • Footer background. Property: footer

  • Header background. Property: header

Admin panel used SemanticUI as CSS Framework so all names of possible colors is described and showed here: https://semantic-ui.com/usage/theming.html

(red: #B03060; orange #FE9A76; yellow: #FFD700; olive: #32CD32 green: #016936; teal : #008080; blue : #0E6EB8; violet: #EE82EE; purple: #B413EC; pink: #FF1493; brown: #A52A2A; grey : #A0A0A0; black: #000000;)

To change colors pass config as:

create_admin_app(
        host="0.0.0.0",
        port=os.getenv("PORT", 5000),
        db=example.models.db,
        db_models=db_models,
        config={
            "ui" : {
                "colors":
                {"buttons": "orange",
                "buttons_alert": "pink"}
                },
            "db_uri": "postgresql://gino:gino@localhost:5432/gino"
        },
    )

Example here: examples/colored_ui/

  1. Added example how to add all models from file with one method (to avoid import each model separate) - palced in examples/colored_ui/src/app.py method - create_models_list

  2. Added valid input for Text columns as Text Area

    Text Area Inouts

Updates in version 0.2.0:

  1. UI fixes:

  • Data Picker was fixed, required fields now dispalayed with ‘* required’ in UI.

  • Menu in header became scrollable, now you can see 20+ models without pain

  • Tables became scrollable horisontal - you can keep dozen columns and see them (hooray!)

  • in Add/edit forms now displayd the field type

  1. Major changes:

  • Limitation to have ‘unique’ rows was removed. Now you not need any unique keys to make possible work with table in Admin panel. Just keep in mind that if you edit row - you will also edit all full ‘dublicated’ rows. So we try identify row by all fields. But if you have several full duplicates in rows - edit action will edit all of them.

Limits:

Deepcopy does not available for tables without primary keys right now.

  • Primary keys now also used to identify unique rows. Now Admin Panel don’t expect only ‘unique’ key in model. Now it firstly works with Primary Keys and only if primary key not exist in model - use ‘unique’ fields to identify unique rows. Also it supports Composite Primary keys (2 and more fields) in all type of operations: delete/update/insert/deepcopy/copy.

  • Schemas support

Now if you work using the custom “schema” name - it’s okay and supported by Admin Panel.

  1. Fixed in types support:

  • passing data as a string - now supported both Date & DateTime format (before correct work only DataTime format)

  • parsing lists (for fields with ARRAY type), also parsed type inside array

  1. Types support improvement:

  • Added support for ARRAYS, TEXT, SmallInt, CHAR, Time

  1. New features:

  • Added Users to Admin Panel - now you can add multiple users for the panel to track history of changes correct and separate accesses

  • URI to DB now can be passed as config parameter ‘db_uri’ or with env variable ‘DB_URI’, for example, no need to setup SANIC variables:

create_admin_app(
        host="0.0.0.0",
        port=os.getenv("PORT", 5000),
        db=example.models.db,
        db_models=db_models,
        config={
            "presets_folder": os.path.join(current_path, "csv_to_upload"),
            "db_uri": "postgresql://local:local@localhost:5432/gino_admin"
        },
    )
  1. More fixes:

  • History works again

Supported features

  • Auth by login/pass with cookie check

  • Create(Add new) item by one for the Model

  • Delete all rows/per element

  • Copy existed element (data table row)

  • Edit existed data (table row)

  • Search/sort in tables

  • Deepcopy element (recursive copy all rows/objects that depend on chosen as ForeignKey)

  • Upload/export data from/to CSV

  • SQL-Runner (execute SQL-queries)

  • Presets: Define order and Load to DB bunch of CSV-files

  • Init DB (Full clean up behavior: Drop tables & Recreate)

  • Composite CSV: Load multiple relative tables in one CSV-file

  • History logs on changes (log for admin panel actions - edit, delete, add, init_db, load presets and etc)

  • Support multiple users for Admin panel (add, edit, remove users from ‘Admin Users’ page)

  • UI Colors customizing

TODO:

  • Add possible to add new Presets from GUI

  • Select multiple rows for delete

  • Copy/deepcopy multiple items

  • Edit multiple items (?)

  • Roles for Admin Panel users (split accessess)

  • Filters in Table’s columns

  • Other staff on Gino Project Dashboard

How to run Gino-Admin

Run with Cli

gino-admin run #module_name_with_models -d postgresql://%(DB_USER):%(DB_PASSWORD)@%(DB_HOST):%(DB_PORT)/%(DB)

gino-admin run --help # use to get cli help
Optional params:
    -d --db
        Expected format: postgresql://%(DB_USER):%(DB_PASSWORD)@%(DB_HOST):%(DB_PORT)/%(DB)
        Example: postgresql://gino:gino@%gino:5432/gino (based on DB settings in examples/)
        Notice: DB credentials can be set up as  env variables with 'SANIC_' prefix
    -h --host
    -p --port
    -c --config Example:  -c "presets_folder=examples/base_example/src/csv_to_upload;some_property=1"
                Notice: all fields that not supported in config will be ignored, like 'some_property' in example
    --no-auth  Run Admin Panel without Auth in UI
    -u --user Admin User login & password
        Expected format: login:password
        Example: admin:1234
        Notice: user also can be defined from env variable with 'SANIC_' prefix - check Auth section example

Example:

gino-admin run examples/run_from_cli/src/db.py --db postgresql://gino:gino@localhost:5432/gino -u admin:1234

Run Admin Panel as Standalone App (no matter that framework you use in main app)

You can use Gino Admin as stand alone web app. Does not matter what Framework used for your main App and that Gino Ext used to init Gino().

Code example in: examples/fastapi_as_main_app How to run example in: examples/fastapi_as_main_app/how_to_run_example.txt

You need to create admin.py (for example, you can use any name) to run admin panel:

import os

from gino_admin import create_admin_app
# import module with your models
import models

# gino admin uses Sanic as a framework, so you can define most params as environment variables with 'SANIC_' prefix
# in example used this way to define DB credentials & login-password to admin panel

# but you can use 'db_uri' in config to define creds for Database
# check examples/colored_ui/src/app.py as example

os.environ["SANIC_DB_HOST"] = os.getenv("DB_HOST", "localhost")
os.environ["SANIC_DB_DATABASE"] = "gino"
os.environ["SANIC_DB_USER"] = "gino"
os.environ["SANIC_DB_PASSWORD"] = "gino"


os.environ["SANIC_ADMIN_USER"] = "admin"
os.environ["SANIC_ADMIN_PASSWORD"] = "1234"

current_path = os.path.dirname(os.path.abspath(__file__))


if __name__ == "__main__":
    # host & port - will be used to up on them admin app
    # config - Gino Admin configuration - check docs to see all possible properties,
    # that allow set path to presets folder or custom_hash_method, optional parameter
    # db_models - list of db.Models classes (tables) that you want to see in Admin Panel
    create_admin_app(
        host="0.0.0.0",
        port=os.getenv("PORT", 5000),
        db=models.db,
        db_models=[models.User, models.City, models.GiftCard, models.Country],
        config={
            "presets_folder": os.path.join(current_path, "csv_to_upload")},
    )

All environment variables you can move to define in docker or .env files as you wish, they not needed to be define in ‘.py’, this is just for example shortness.

Add Admin Panel to existed Sanic application as ‘/admin’ route

Create in your project ‘admin.py’ file and use add_admin_panel from from gino_admin import add_admin_panel

Code example in: examples/base_example How to run example in: examples/base_example/how_to_run_example.txt

Example:

from from gino_admin import add_admin_panel


# your app code


add_admin_panel(
    app, db, [User, Place, City, GiftCard], custom_hash_method=custom_hash_method
)

Where:

  • ‘app’: your Sanic application

  • ‘db’ : from gino.ext.sanic import Gino; db = Gino() and

  • [User, Place, City, GiftCard] - list of models that you want to add in Admin Panel to maintain

  • custom_hash_method - optional parameter to define you own hash method to encrypt all ‘_hash’ columns of your Models.

In admin panel _hash fields will be displayed without ‘_hash’ prefix and fields values will be hidden like ‘**

Presets

Load multiple CSV to DB in order by one click. Presets described that CSV-s files and in that order need to be loaded in DB.

Read the docs: Presets

Composite CSV to Upload

Composite CSV - one file that contains data for several relative tables.

Read the docs: Composite CSV to Upload

Config Gino Admin

Read the docs: Config

Init DB

Init DB feature used for doing full clean up DB - it drop all tables & create them after Drop for all models in Admin Panel.

Upload from CSV

Files-samples for example project can be found here: examples/base_example/src/csv_to_upload

Authorization

Read in docs: Authorization

Limitations

In current version, for correct work of Deepcopy feature in Admin Panel model MUST contain at least one unique or primary_key Column (field).

Screens:

Check in docs: UI Screens

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gino-admin-0.2.3a1.tar.gz (43.3 kB view hashes)

Uploaded Source

Built Distribution

gino_admin-0.2.3a1-py3-none-any.whl (49.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page