Welcome to Django Lineup’s documentation!

Contents:

Django Lineup

https://badge.fury.io/py/django-lineup.svg https://travis-ci.org/otto-torino/django-lineup.svg?branch=master https://codecov.io/gh/otto-torino/django-lineup/branch/master/graph/badge.svg

Multiple navigation system for django sites.

Django Lineup lets you manage a tree of items. Each first level node represents a menu you can include in your templates.

_images/lineup.png

Documentation

The full documentation is at https://django-lineup.readthedocs.io.

Quickstart

Install Django Lineup:

pip install django-lineup

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'lineup.apps.LineupConfig',
    ...
)

Make sure the requests context processor is included (it is by default):

TEMPLATES = [
  {
    'OPTIONS': {
      'context_processors': [
        "django.template.context_processors.request",
      ],
    },
  },
]

Render a menu::

{% load lineup_tags %}
{% lineup_menu 'my-root-item-slug '%}

Render the breadcrumbs::

{% load lineup_tags %}
{% lineup_breadcrumbs 'my-root-item-slug '%}

Import a menu from a json::

$ python manage.py import_menu_from_json

Json example::

{
  "label": "Main Menu",
  "slug": "main-menu",
  "order": 0,
  "children": [
    {
      "label": "Tools",
      "slug": "tools",
      "order": 0,
      "children": [
        {
          "label": "DNS Tools",
          "slug": "dns-tools",
          "order": 0,
          "login_required": true,
          "children": [
            {
              "label": "DMARC DNS Tools",
              "slug": "dmarc-dns-tools",
              "link": "/dmarc-tools/",
              "title": "DMARC Rulez",
              "order": 0
            }
          ]
        },
        {
          "label": "Password Generator",
          "slug": "password-generator",
          "order": 1
        }
      ]
    },
    {
      "label": "Disabled Item",
      "slug": "disabled-item",
      "order": 1,
      "enabled": false,
      "children": [
        {
          "label": "Disabled child",
          "slug": "disabled-child",
          "order": 0
        }
      ]
    },
    {
      "label": "Perm Item",
      "slug": "perm-item",
      "order": 2,
      "permissions": [
        "add_permission",
        "view_session"
      ]
    }
  ]
}

Features

  • Multiple menus supported

  • Visibility logic: login required / permissions

  • Render menu tree templatetags

  • Breadcrumbs templetetag

  • Import a menu from json management command

  • Django Baton integration to highlight different menu in the admin

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install -r requirements_test.txt
(myenv) $ python runtests.py

Development commands

pip install -r requirements_dev.txt
invoke -l

Example app

This example is provided as a convenience feature to allow potential users to try the app straight from the app repo without having to create a django project.

It can also be used to develop the app in place.

To run this example, follow these instructions:

  1. Navigate to the root directory of your application (same as manage.py)

  2. Install the requirements for the package:

    pip install -r requirements_test.txt

  3. Make and apply migrations

    python manage.py makemigrations

    python manage.py migrate

  4. Run the server

    python manage.py runserver

  5. Access from the browser at http://127.0.0.1:8000

  6. Admin user account is admin:admin

Credits

Django Lineup is developed by Otto SRL.

Tools used in rendering this package:

Installation

Install with pip:

$ pip install django-lineup

Usage

To use Django Lineup in a project, add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'lineup.apps.LineupConfig',
    ...
)

Be sure the requests context processor is included (it is by default):

TEMPLATES = [
  {
    'OPTIONS': {
      'context_processors': [
        # ...
        "django.template.context_processors.request",
      ],
    },
  },
]

Templatetags

Django Lineup provides 2 templatetags to include the rendered menu and the breadcrumbs in your templates.

Render Lineup Menu

Templatetag used to render a menu inside a template

{% load lineup_tags %}
{% lineup_menu 'main-menu' %}

It takes one parameter: the slug of the menu root voice.

Render Lineup Breadcrumbs

Templatetag used to render the breadcrumbs inside a template

{% load lineup_tags %}
{% lineup_breadcrumbs 'main-menu' %}

It takes one parameter: the slug of the menu root voice.

Management Commands

Django Lineup provides a management command you can use to import a JSON formatted menu from file

$ python manage.py import_menu_from_json /path/to/menu.json

The file should contain a JSON representation of the menu, i.e.

{
  "label": "Main Menu",
  "slug": "main-menu",
  "order": 0,
  "children": [
    {
      "label": "Tools",
      "slug": "tools",
      "order": 0,
      "children": [
        {
          "label": "DNS Tools",
          "slug": "dns-tools",
          "order": 0,
          "login_required": true,
          "children": [
            {
              "label": "DMARC DNS Tools",
              "slug": "dmarc-dns-tools",
              "link": "/dmarc-tools/",
              "title": "DMARC Rulez",
              "order": 0
            }
          ]
        },
        {
          "label": "Password Generator",
          "slug": "password-generator",
          "order": 1
        }
      ]
    },
    {
      "label": "Disabled Item",
      "slug": "disabled-item",
      "order": 1,
      "enabled": false,
      "children": [
        {
          "label": "Disabled child",
          "slug": "disabled-child",
          "order": 0
        }
      ]
    },
    {
      "label": "Perm Item",
      "slug": "perm-item",
      "order": 2,
      "permissions": [
        "add_permission",
        "view_session"
      ]
    }
  ]
}

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

Types of Contributions

Report Bugs

Report bugs at https://github.com/otto-torino/django-lineup/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.

  • Any details about your local setup that might be helpful in troubleshooting.

  • Detailed steps to reproduce the bug.

Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.

Implement Features

Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement it.

Write Documentation

Django Lineup could always use more documentation, whether as part of the official Django Lineup docs, in docstrings, or even on the web in blog posts, articles, and such.

Submit Feedback

The best way to send feedback is to file an issue at https://github.com/otto-torino/django-lineup/issues.

If you are proposing a feature:

  • Explain in detail how it would work.

  • Keep the scope as narrow as possible, to make it easier to implement.

  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Get Started!

Ready to contribute? Here’s how to set up django-lineup for local development.

  1. Fork the django-lineup repo on GitHub.

  2. Clone your fork locally:

    $ git clone git@github.com:your_name_here/django-lineup.git
    
  3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:

    $ mkvirtualenv django-lineup
    $ cd django-lineup/
    $ python setup.py develop
    
  4. Create a branch for local development:

    $ git checkout -b name-of-your-bugfix-or-feature
    

    Now you can make your changes locally.

  5. When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:

    $ flake8 lineup tests
    $ python setup.py test
    $ tox
    

    To get flake8 and tox, just pip install them into your virtualenv.

  6. Commit your changes and push your branch to GitHub:

    $ git add .
    $ git commit -m "Your detailed description of your changes."
    $ git push origin name-of-your-bugfix-or-feature
    
  7. Submit a pull request through the GitHub website.

Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

  1. The pull request should include tests.

  2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.

  3. The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. Check https://travis-ci.org/otto-torino/django-lineup/pull_requests and make sure that the tests pass for all supported Python versions.

Tips

To run a subset of tests:

$ python -m unittest tests.test_lineup

Credits

Development Lead

Contributors

None yet. Why not be the first?

History

0.3.1 (2022-12-22)

  • Adds Dajngo 4 support

0.3.0 (2021-04-27)

  • Adds the extras field

0.2.3 (2021-02-28)

  • Fixes tests

0.2.2 (2021-02-28)

  • Fixes baton row attributes method

0.2.1 (2020-12-14)

  • Adds order field as editable in change list page

  • First stable release

0.2.0 (2020-12-14)

  • First stable release

0.1.0 (2020-12-11)

  • First release on PyPI.