Simple and extensible admin interface framework for Flask
86
Quality
Pending
Does it follow best practices?
Impact
86%
1.30xAverage score across 10 eval scenarios
Core administrative interface classes including the main Admin collection, base views for custom pages, and menu system components.
The Admin class serves as the main administrative interface manager, coordinating views, menu structure, and Flask application integration.
class Admin:
def __init__(
self,
app=None,
name=None,
url=None,
subdomain=None,
index_view=None,
translations_path=None,
endpoint=None,
static_url_path=None,
base_template=None,
template_mode=None,
category_icon_classes=None
):
"""
Initialize admin interface.
Args:
app (Flask, optional): Flask application instance
name (str, optional): Admin interface name for title/branding
url (str, optional): Admin URL prefix (default: '/admin')
subdomain (str, optional): Subdomain for admin interface
index_view (AdminIndexView, optional): Custom index page view
translations_path (str, optional): Path to translation files
endpoint (str, optional): Admin blueprint endpoint
static_url_path (str, optional): Static files URL path
base_template (str, optional): Base template path
template_mode (str, optional): Template theme ('bootstrap2', 'bootstrap3', 'bootstrap4')
category_icon_classes (dict, optional): Icon classes for categories
"""
def add_view(self, view):
"""
Add view to admin interface.
Args:
view (BaseView): Admin view instance
"""
def add_views(self, *args):
"""
Add multiple views to admin interface.
Args:
*args: Variable number of view instances
"""
def add_category(self, name, class_name=None, icon_type=None, icon_value=None):
"""
Add menu category.
Args:
name (str): Category name
class_name (str, optional): CSS class for category
icon_type (str, optional): Icon type ('glyph', 'fa', 'image', 'image-url')
icon_value (str, optional): Icon identifier
"""
def add_sub_category(self, name, parent_name):
"""
Add submenu category.
Args:
name (str): Subcategory name
parent_name (str): Parent category name
"""
def add_link(self, link):
"""
Add menu link.
Args:
link (MenuLink): Menu link instance
"""
def add_links(self, *args):
"""
Add multiple menu links.
Args:
*args: Variable number of MenuLink instances
"""
def init_app(self, app, index_view=None, endpoint=None, url=None):
"""
Initialize admin with Flask application.
Args:
app (Flask): Flask application instance
index_view (AdminIndexView, optional): Custom index page
endpoint (str, optional): Blueprint endpoint
url (str, optional): URL prefix
"""
def menu(self):
"""
Get menu hierarchy.
Returns:
list: Menu items and categories
"""
def menu_links(self):
"""
Get menu links.
Returns:
list: Menu link items
"""Foundation classes for creating custom administrative views with URL routing, template rendering, and access control.
def expose(url='/', methods=('GET',)):
"""
Decorator to expose view methods with URL routing.
Args:
url (str): URL pattern (default: '/')
methods (tuple): HTTP methods (default: ('GET',))
Returns:
function: Decorated method
"""
class BaseView:
def __init__(
self,
name=None,
category=None,
endpoint=None,
url=None,
static_folder=None,
static_url_path=None,
menu_class_name=None,
menu_icon_type=None,
menu_icon_value=None
):
"""
Initialize base admin view.
Args:
name (str, optional): Display name in menu
category (str, optional): Menu category
endpoint (str, optional): Blueprint endpoint prefix
url (str, optional): URL prefix for view
static_folder (str, optional): Static files folder path
static_url_path (str, optional): Static files URL path
menu_class_name (str, optional): CSS class for menu item
menu_icon_type (str, optional): Icon type
menu_icon_value (str, optional): Icon identifier
"""
def create_blueprint(self, admin):
"""
Create Flask blueprint for view.
Args:
admin (Admin): Admin instance
Returns:
Blueprint: Flask blueprint
"""
def render(self, template, **kwargs):
"""
Render template with admin context.
Args:
template (str): Template path
**kwargs: Template variables
Returns:
str: Rendered HTML
"""
def is_visible(self):
"""
Check if view should be visible in menu.
Returns:
bool: True if visible
"""
def is_accessible(self):
"""
Check if view is accessible (permission check).
Returns:
bool: True if accessible
"""
def inaccessible_callback(self, name, **kwargs):
"""
Handle inaccessible view requests.
Args:
name (str): Endpoint name
**kwargs: URL parameters
"""
def get_url(self, endpoint, **kwargs):
"""
Generate URL for endpoint.
Args:
endpoint (str): Endpoint name
**kwargs: URL parameters
Returns:
str: Generated URL
"""
class AdminIndexView(BaseView):
def __init__(
self,
name=None,
category=None,
endpoint=None,
url=None,
template='admin/index.html',
menu_class_name=None,
menu_icon_type=None,
menu_icon_value=None
):
"""
Initialize admin index view.
Args:
name (str, optional): Display name
category (str, optional): Menu category
endpoint (str, optional): Blueprint endpoint
url (str, optional): URL pattern
template (str, optional): Index template path
menu_class_name (str, optional): Menu CSS class
menu_icon_type (str, optional): Icon type
menu_icon_value (str, optional): Icon identifier
"""
@expose('/')
def index(self):
"""
Index view method.
Returns:
str: Rendered index page
"""Menu system classes for creating hierarchical navigation with categories, links, and custom items.
class BaseMenu:
def __init__(
self,
name,
class_name=None,
icon_type=None,
icon_value=None,
target=None
):
"""
Initialize base menu item.
Args:
name (str): Menu item name
class_name (str, optional): CSS class
icon_type (str, optional): Icon type
icon_value (str, optional): Icon identifier
target (str, optional): Link target
"""
def add_child(self, menu):
"""
Add child menu item.
Args:
menu (BaseMenu): Child menu item
"""
def get_url(self):
"""
Get menu URL (abstract method).
Returns:
str: Menu URL
"""
def is_category(self):
"""
Check if item is category.
Returns:
bool: True if category
"""
def is_active(self, view):
"""
Check if menu is active for current view.
Args:
view (BaseView): Current view
Returns:
bool: True if active
"""
def is_visible(self):
"""
Check menu visibility.
Returns:
bool: True if visible
"""
def is_accessible(self):
"""
Check menu accessibility.
Returns:
bool: True if accessible
"""
def get_children(self):
"""
Get accessible, visible child menu items.
Returns:
list: Child menu items
"""
class MenuCategory(BaseMenu):
"""
Menu category container for grouping related items.
"""
def get_url(self):
"""
Get category URL.
Returns:
None: Categories don't have URLs
"""
def is_category(self):
"""
Check if item is category.
Returns:
bool: Always True for categories
"""
class MenuView(BaseMenu):
def __init__(self, name, view=None, cache=True):
"""
Initialize admin view menu item.
Args:
name (str): Menu item name
view (BaseView, optional): Associated view
cache (bool, optional): Enable URL caching
"""
def get_url(self):
"""
Get view URL with caching.
Returns:
str: View URL
"""
def is_active(self, view):
"""
Check if menu corresponds to active view.
Args:
view (BaseView): Current view
Returns:
bool: True if active
"""
class MenuLink(BaseMenu):
def __init__(
self,
name,
url=None,
endpoint=None,
category=None,
class_name=None,
icon_type=None,
icon_value=None,
target=None
):
"""
Initialize external link menu item.
Args:
name (str): Link text
url (str, optional): Direct URL
endpoint (str, optional): Flask endpoint
category (str, optional): Menu category
class_name (str, optional): CSS class
icon_type (str, optional): Icon type
icon_value (str, optional): Icon identifier
target (str, optional): Link target (_blank, _self, etc.)
"""
def get_url(self):
"""
Get link URL.
Returns:
str: Link URL
"""
class SubMenuCategory(MenuCategory):
"""
Submenu category with dropdown styling.
"""Icon type constants for menu customization.
ICON_TYPE_GLYPH = 'glyph' # Bootstrap glyph icons
ICON_TYPE_FONT_AWESOME = 'fa' # Font Awesome icons
ICON_TYPE_IMAGE = 'image' # Images relative to Flask static
ICON_TYPE_IMAGE_URL = 'image-url' # External image URLsInstall with Tessl CLI
npx tessl i tessl/pypi-flask-admindocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10