GithubHelp home page GithubHelp logo

danielflopez / django-menu-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lalogiadepython/django-menu-generator

0.0 2.0 0.0 42 KB

A straightforward menu generator for Django

License: MIT License

Python 100.00%

django-menu-generator's Introduction

Django Menu Generator

A menu generating application for Django

status-image version-image coverage-image

A productivity tool that enables the generation of full featured menus through python dictionaries list, you only need to setup the HTML structure once for each menu you like to build and then use the dictionaries to generate menu items

Features:

  • Tested support to Python 2.7, 3.4, 3.5, 3.6
  • Tested support to Django 1.8.18, 1.9.13, 1.10.7, 1.11
  • No database
  • Support unlimited menus
  • Icons support
  • Semi-Automatically identifies the selected item and his breadcrums
  • Conditional menu items display through validators (Permissions, Authentications or whatever you want)

Installation:

You can install it with one of these options:

Usage:

  1. Install 'django-menu-generator' as per the above instructions.
  2. Add 'menu_generator' to your INSTALLED_APPS.
  3. Add {% load menu_generator %} to templates that will handle the menus.
####################################################################################
Example: settings.py
####################################################################################

NAV_MENU_LEFT = [
    {
        "name": "Home",
        "url": "/",
    },
    {
        "name": "About",
        "url": "/about",
    },
]

NAV_MENU_RIGHT = [
    {
        "name": "Login",
        "url": "login_url_view",  # reversible
        "validators": ["menu_generator.validators.is_anonymous"],
    },
    {
        "name": "Register",
        "url": "register_view_url",  # reversible
        "validators": ["menu_generator.validators.is_anonymous"],
    },
    {
        "name": "Account",
        "url": "/acount",
        "validators": ["menu_generator.validators.is_authenticated"],
        "submenu": [
            {
                "name": "Profile",
                "url": "/account/profile",
            },
            {
                "name": "Account Balance",
                "url": "/account/balance",
                "validators": ["myapp.profiles.is_paid_user"],
            },
            {
                "name": "Account Secrets",
                "url": "/account/secrets",
                "validators": ["menu_generator.validators.is_superuser"],
            }
        ],
    },
]

FOOTER_MENU_LEFT = [
    {
        "name": "Facebook",
        "url": "facebook.com/foobar",
    },
    {
        "name": "Contact US",
        "url": "/contact",
    },
]

FOOTER_MENU_RIGHT = [
    {
        "name": "Address",
        "url": "/address",
    },
]

You can build the menu dictionaries list inside the project apps with menus.py files, see the docs for more.

Then in your template, load the template tag to generate your menu.

 <!-- base.html -->
 {% load menu_generator %}

 <!DOCTYPE html>
 <html>
     <head><title>Django Menu Generator</title></head>
     <body>
         <!-- NAV BAR Start -->
         {% get_menu "NAV_MENU_LEFT" as left_menu %}
         <div style="float:left;">
             {% for item in left_menu %}
                 <li class="{% if item.selected %} active {% endif %}">
                 <a href="{{ item.url }}"> <i class="{{ item.icon_class }}"></i> {{ item.name }}</a>
                 </li>
                 {% if item.submenu %}
                     <ul>
                     {% for menu in item.submenu %}
                         <li class="{% if menu.selected %} active {% endif %}">
                             <a href="{{ menu.url }}">{{ menu.name }}</a>
                         </li>
                     {% endfor %}
                     </ul>
                 {% endif %}
             {% endfor %}
         </div>

         {% get_menu "NAV_MENU_RIGHT" as right_menu %}
         <div style="float:right;">
             {% for item in right_menu %}
                 <li class="{% if item.selected %} active {% endif %}">
                     <a href="{{ item.url }}">{{ item.name }}</a>
                 </li>
                 {% if item.submenu %}
                     <ul>
                     {% for menu in item.submenu %}
                         <li class="{% if menu.selected %} active {% endif %}">
                             <a href="{{ menu.url }}">{{ menu.name }}</a>
                         </li>
                     {% endfor %}
                     </ul>
                 {% endif %}
             {% endfor %}
         </div>
         <!-- NAV BAR End -->

         <!-- Footer Start -->
         {% get_menu "FOOTER_MENU_LEFT" as left_footer_menu %}
         <div style="float:left;">
             <!-- loop through your left footer menus -->
         </div>

         {% get_menu "FOOTER_MENU_RIGHT" as right_footer_menu %}
         <div style="float:right;">
             <!-- loop through your right footer menus -->
         </div>
         <!-- Footer End -->
     </body>
 </html>

Running the tests:

To run the tests against the current environment:

python manage.py test

License:

Released under a (MIT) license.

Author and mantainers:

Milton Lenis - [email protected]

Credits:

I'd like to thank Val Kneeman, the original author of this project under the name 'menuware' https://github.com/un33k/django-menuware

django-menu-generator's People

Watchers

 avatar  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.