Giter Club home page Giter Club logo

godmode2's Introduction

GodMode 2

GodMode is a semi-automatic customizable admin interface generator that lets you add admin interface to any SQL database. Written in Python 3.x, Flask and SQLAlchemy reflections.

Automatically creates CRUD pages for any table in your database with ability to customize rows and views, create filters, batch actions and manage access policies for users and groups.

Inspired by Django Admin Interface and Flask-Admin extension, but designed to be a standalone application. So you don't need to have you app written using Django, Flask or even in Python at all. All you need is a SQL database. Tested on several pet-projects and medium startups. Good for a quick start because you can make a simple CRUD using a few lines of code and may add additional functionality as your product grows.

Best for PostgreSQL, MySQL and SQLite. Also supports other SQLAlchemy drivers: Firebird, Microsoft SQL Server, Oracle and Sybase but they were not officially tested.

Screenshot

Installation

Demo user and password: demo/demo.

Make sure that you have a Python 3.x. Python 2.x is not supported.

Clone this repository, install all requirements and run app.py.

$ git clone https://github.com/vas3k/GodMode2.git
$ cd GodMode2
$ sudo pip3 install -r requirements.txt
$ python3 app.py

Then open your browser at localhost:1488, enter demo/demo to access demo version of the main screen.

Quick Start

For example your PostgreSQL database on localhost called dbname and you have the users table in your database that you want to manage. So your DSN is postgresql+psycopg2://username:password@localhost/dbname. Check that you have an access to the database from your computer before the first step.

First step: create new file in db directory and name it for example my.py. You can use demo.py as an example. If you're familiar with SQLAlchemy it will be easy.

import sqlalchemy as sa

from base.db import BaseDatabase


class MyDatabase(BaseDatabase):
    dsn = "postgresql+psycopg2://username:[email protected]/dbname"

MyDatabase.bind()  # you need to call bind() before any table declarations


class User(MyDatabase.TableBase):
    __table__ = sa.Table("users", MyDatabase.metadata, autoload=True)
    # you can declare your table columns here, but autoload=True will try to do it for you

Second step: create new model file for users admin in models directory. For example users.py.

from base.model import BaseAdminModel
from db.my import MyDatabase, User

class UsersAdminModel(BaseAdminModel):
    db = MyDatabase
    table = User
    name = "users"  # for URL's
    title = "Users"  # for sidebar
    icon = "icon-user"

Third step: modify app.py file in the root directory and specify your database and model classes.

import settings
from godmode import GodModeApp
from db.my import MyDatabase
from models.users import UsersAdminModel

app = GodModeApp(
    databases=[MyDatabase],
    models=[
        UsersAdminModel,
    ]
)

if settings.DEBUG:
    app.run()

Now run $ python3 app.py and open localhost:1488. You should see your Users table in the sidebar.

Great, you've just created your first simple CRUD for users table. Check the Usage section to learn how to configure it.

Maybe one day all these steps will be automated by the one script.

Usage

UNDER CONSTRUCTION

Databases and Tables

db/<your_db_name>.py

# how to connect to your database
class FirstDatabase(BaseDatabase):
    dsn = "sqlite:///internal/demo.sqlite"

# bind your database class with engine (call it before any table declaration!)
FirstDatabase.bind()

# you even can have multiple databases (but better to describe them in separate files)
class SecondDatabase(BaseDatabase):
    dsn = "postgresql+psycopg2://username:[email protected]/dbname"

SecondDatabase.bind()

# describe couple of tables
class User(FirstDatabase.TableBase):
    __table__ = sa.Table('users', FirstDatabase.metadata, autoload=True)


class Post(FirstDatabase.TableBase):
    __table__ = sa.Table('posts', FirstDatabase.metadata, autoload=True)

    # if you want GodMode to make fast links for you
    user = relationship('User')

Now tell GodMode about all your databases by editing app.py.

app = GodModeApp(
    databases=[DemoDatabase, SecondDatabase],
    models=[]
)

Models

models/<name_your_model>.py

class YourAdminModel(BaseAdminModel):
    db = FirstDatabase                      # database class
    table = User                            # table class
    acl = ACL.ADMIN                         # lowest ACL group who has access to this model
    name = "my_table"                       # name for url building (must be unique)
    title = "My Table"                      # title for sidebar
    icon = "icon-loadingeight"              # icon from webhostinghub.com/glyphs/
    index = 0                               # higher index -> higher position
    place = "sidebar"                       # "sidebar" (left) or "navbar" (top)
    group = None                            # group class (see Groups section)
    actions = []                            # default actions for all views (see Actions section)
    enable_log = False                      # turn off activity logging for this model
    excluded_fields_for_log = ["password"]  # exclude "password" field from activity log
    fields = [                              # default fieldset for all views
        "id",
        ("name", {"widget": NameWidget}),
        "bio",
        ("is_locked", {"widget": BooleanWidget})
    ]
    id_field = "id"                         # primary key field (for relative linking)
    custom_widgets = {                      # default widget classes for certain fields
        "name": NameWidget                  # if you don't want to specify all fields in big table
    }

    # use BaseListView for display this table (default behaviour)
    list_view = BaseListView

    # do not generate create, edit and delete views,
    # for example for read-only tables
    edit_view = None
    create_view = None
    delete_view = None

    # you can make your custom details view based on BaseDetailsView
    # for example if you want to use your own template
    class CustomDetailsView(BaseDetailsView):
        template = "views/my_custom_details.html"

    details_view = CustomDetailsView        # see Views section for more info

Now return to the app.py file to specify new models for your app.

app = GodModeApp(
    databases=[FirstDatabase, SecondDatabase],
    models=[YourAdminModel]  # put new model here
)

Views

Actions

Widgets

Groups

ACL's and policies

Future Plans

  • Buy more beer
  • Fix HTML/CSS bugs
  • Support default values from database
  • Security test for XSS and injections (be careful with that, check all models you create and send me pull requests)
  • Think about better filtering/sorting interface
  • Make an install~~.php~~ file for easier cold start
  • Maybe more AJAX for validation and inline editing

Similar Projects

Other great projects for automatic admin interfaces:

License

vas3k (c) 2016+

Licensed under the WTFPL license. Full text of the license can be found in the LICENSE.txt file.

vas3k.ru  ·  GitHub @vas3k  ·  Twitter @vas3k

godmode2's People

Contributors

vas3k avatar

Watchers

Serg avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.