The PyCK Admin Interface

PyCK Admin Extension

Admin extension that automtically creates CRUD interfaces for all database models (or a selected list of models)

class pyck.ext.admin_controller.AdminController(request)

Enables automatic Admin interface generation from database models. The pyck.ext.admin_controller.AdminController allows you to quickly enable Admin interface for any number of database models you like. To use AdminController at minimum these steps must be followed.

1. In your application’s routes settings, specify the url where the CRUD interface should be displayed. You can use the pyck.ext.admin_controller.add_admin_handler() function for it. For example in your __init__.py; put code like:

from pyck.ext import AdminController, add_admin_handler
from pyck.lib import get_models
import my_application_package_name_here

# Place this with the config.add_route calls
add_admin_handler(config, db, get_models(my_application_package_name_here), 'admin', '/admin',
                  AdminController)

and that’s all you need to do to get a fully operation Admin interface.

Configuration Options

These parameters are to be set as class properties in a sub-class of AdminController

Parameters:
  • display_record_count – Boolean value controlling if record count is to be displayed next to the menu items for CRUD models
  • crud_list_sort_by

    Sort by specs for models.

    Example:

    crud_list_sort_by = {
        Post.__name__: Post.created.desc()
    }
    
  • crud_models_field_args

    A dictionary with key being the model name and value being the field args value for that model.

    Example:

    model_field_args = {
        'Product': {
            'category_id' : {'widget' : Select()}
        },
        'Category': {
            'description' : {'widget' : TextArea()}
        },
    }
    
  • crud_list_only

    A dictionary containing list of fields to be displayed (and not displaying any other fields) on the record listing page for a specific CRUD model

    Example:

    crud_list_only = {
        User.__name__: ['user_id', 'email']
    }
    
  • crud_list_exclude

    A dictionary containing list of fields not to be displayed on the record listing page for a specific CRUD model

    Example:

    crud_list_exclude = {
        User.__name__: ['id', 'comments']
    }
    
  • crud_list_actions

    A dictionary containing list of actions to be displayed on the record listing page for a specific CRUD model

    Example:

    crud_list_actions = {
        User.__name__: [
            {'link_text': '{friendly_name} popularity graph', 'link_url': '/pop_graph', 'css_class': 'btn btn-primary'},
        ]
    }
    
  • crud_list_per_record_actions

    A dictionary containing list of actions to be displayed next to each record in record listing for a specific CRUD model

    Example:

    crud_list_per_record_actions = {
        User.__name__: [
            {'link_text': 'Details', 'link_url': 'details/{PK}'},
            {'link_text': 'Edit', 'link_url': 'edit/{PK}'},
            {'link_text': 'Delete', 'link_url': 'delete/{PK}'},
            {'link_text': 'Upload Photo', 'link_url': '/photo_upload/user/{PK}'},
        ]
    }
    
  • crud_list_filter_condition

    A SQLAlchemy filter condition to be applied for to the listing page

    Example:

    crud_list_filter_condition = {
        UserFiles.__name__: "self.model.user_id == self.request.session.get('logged_in_user', '')"
    }
    
  • crud_detail_exclude

    A dictionary containing list of fields not to be displayed on the record details page for a specific CRUD model

    Example:

    crud_detail_exclude = {
        User.__name__: ['id', 'comments']
    }
    
  • crud_detail_actions

    A dictionary containing list of actions to be displayed on the details view page of a specific CRUD model

    Example:

    crud_list_per_record_actions = {
        User.__name__: [
            {'link_text': 'Details', 'link_url': 'details/{PK}'},
            {'link_text': 'Edit', 'link_url': 'edit/{PK}'},
            {'link_text': 'Delete', 'link_url': 'delete/{PK}'},
            {'link_text': 'Upload Photo', 'link_url': '/photo_upload/user/{PK}'},
        ]
    }
    

** TODO **

  • More documentation of various options and methods
  • An AdminController tutorial
  • Tests for the controller
  • Add support for composite primary keys
index()

Home page

pyck.ext.admin_controller.add_admin_handler(config, db_session, models=None, route_name_prefix='', url_pattern_prefix='', handler_class=None)

A utility function to quickly add all admin related routes and set them to the admin handler class with one function call, for example:

from pyck.ext import add_admin_handler, AdminController
from pyck.lib import get_models
import my_application_package_name_here

# Place this with the config.add_route calls
add_admin_handler(config, db, get_models(my_application_package_name_here), 'admin', '/admin',
                  AdminController)
Parameters:
  • config – The application config object
  • db – The database session object
  • models – Note: For backward compatibility this parameter can either be a list (old) or a dictionary (new). List/Dictionary of models for to include in the admin panel. get_models function can be used to include all models.
  • route_name_prefix – Optional string prefix to add to all route names generated inside the admin panel.
  • url_pattern_prefix – Optional string prefix to add to all admin section related url patterns
  • handler_class – The AdminController handler class.