Skip to main content

A django application that add portlets in right sidebar at app level.

Project description

django-admin-app-sidebar

A django application that add portlets in right sidebar at app level.

Install

pip install django-admin-app-sidebar

Usage

pro/settings.py

Note:

  • We used template override in django_admin_app_sidebar, so we MUST include django_admin_app_sidebar in INSTALLED_APPS.
  • The app django_static_fontawesome is optional choice. If you are using icon in sidebar portlet you may need it.
INSTALLED_APPS = [
    ...
    'django_static_fontawesome', # Optional, and install by yourself
    'django_admin_app_sidebar',
    ...
]

app/init.py

Note:

  • We are going to set an example portlet in AppConfig.ready
default_app_config = "django_admin_app_sidebar_example.apps.DjangoAdminAppSidebarExampleConfig"

app/apps.py

Note:

  • By default, django_admin_app_sidebar provides an simple navigation portlet. Just init a navigation instance, and register it as a portlet.
  • Navigation item config
    • title: required. the navigation link title.
    • url: required. the navigation link url.
    • icon: optional. icon class just before link title.
    • target: optional. link target, target=_blank means open in new window or tab.
    • depth: optional. depth=2 will add 20px indent to the link item. And depth=3 will add 40px.
    • if item=="-", then display a seperator.
from django.apps import AppConfig
from django_admin_app_sidebar.portlets import register_portlet
from django_admin_app_sidebar.portlets import SidebarNavigation
from django.utils.translation import ugettext_lazy as _
from django.urls import reverse_lazy

class DjangoAdminAppSidebarExampleConfig(AppConfig):
    name = 'django_admin_app_sidebar_example'

    def ready(self):
        navigation = SidebarNavigation("Navigation", [{
            "title": "Home",
            "url": "/admin/",
            "icon": "fas fa-home",
        },"-",{
            "title": "Example Index",
            "url": reverse_lazy("admin:app_list", kwargs={"app_label": self.name}),
            "icon": "fas fa-building",
        },{
            "title": "Category Manager",
            "url": reverse_lazy("admin:{0}_{1}_changelist".format(self.name, "category")),
            "icon": "fas fa-tree",
            "depth": 2,
        },{
            "title": "Book Manager",
            "url": reverse_lazy("admin:{0}_{1}_changelist".format(self.name, "book")),
            "icon": "fas fa-file",
            "depth": 2,
        }])
        register_portlet(navigation, app_label=self.name, extra_css=[
            "fontawesome/css/all.min.css",
        ])

Exported APIs

  • django_admin_app_sidebar.portlets.Portlet

    It is a portlet base class. You can use any callable function instead of Portlet, simply take a context parameter and return rendered html string.

  • django_admin_app_sidebar.portlets.SidebarNavigation

    A simple navigation portlet.

  • django_admin_app_sidebar.portlets.register_portlet

    Register a portlet to the system.

Detail of django_admin_app_sidebar.portlets.register_portlet

def register_portlet(render, order=0, app_label=None, model_name=None,
        show_in_app=True,
        show_in_app_index=False,
        show_in_model_site=False,
        show_in_model_changelist=False,
        show_in_model_change=False,
        show_in_model_add=False,
        show_in_model_history=False,
        extra_css=None,
        extra_js=None):
        ...

Parameters:

  • render: required, it is a Portlet instance or a equivalent callable function.
  • order: portlet display order
  • app_label: in which application views the portlet will be displayed
    • if None, the portlet will be displayed in all application.
  • model_name: in which model related view the portlet will be diplayed
    • if None, the portlet will be displayed in all views of the application
  • show_in_app: default to True. show the portlet in all views under the application.
  • show_in_app_index: default to False. show the portlet in app index view. app_label is required.
  • show_in_model_site: default to False. show the portlet in all views related to the model
  • show_in_model_changelist: default to False. show the portlet in changelist view.
  • show_in_model_change: default to False. show the portlet in change view.
  • show_in_model_add: default to False. show the portlet in add view.
  • show_in_model_history: default to False. show the portlet in history view. Not implemented yet

Releases

v0.1.0 @todo

  • First release.

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

django-admin-app-sidebar-0.1.0.tar.gz (9.2 kB view details)

Uploaded Source

File details

Details for the file django-admin-app-sidebar-0.1.0.tar.gz.

File metadata

  • Download URL: django-admin-app-sidebar-0.1.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

File hashes

Hashes for django-admin-app-sidebar-0.1.0.tar.gz
Algorithm Hash digest
SHA256 243312a2040c031e5a36c1fcaffdb402654873ed470455170cd4f93e5058b9c1
MD5 64040fb1458d9adbff2249fb940b3e17
BLAKE2b-256 7bcecea1ce5e0ddc6594c8338cc595590c81ba4d9b72673c5b8938aa352a611d

See more details on using hashes here.

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