Skip to content

Commit

Permalink
Merge pull request #86 from jazzband/release/v2.0.0
Browse files Browse the repository at this point in the history
Prepare release of django-simple-menu 2.0.0
  • Loading branch information
mbeijen authored Nov 2, 2022
2 parents 51be8d1 + accc532 commit 1dc4faa
Show file tree
Hide file tree
Showing 63 changed files with 1,000 additions and 758 deletions.
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[run]
source = menu
source = simple_menu
branch = 1

[report]
omit = *migrations*,.tox/*,setup.py,*settings.py
omit = *migrations*,.tox/*,setup.py,*settings.py,menu/*
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9']
django-version: ['2.2', '3.0', '3.1', 'main']
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
django-version: ['3.2', '4.0', 'main']

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
rev: 1.11.0
hooks:
- id: django-upgrade
args: [--target-version, "2.2"]
args: [--target-version, "3.2"]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
Expand Down
12 changes: 9 additions & 3 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
django-simple-menu changelog
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Version 2.0.0 - Released ...
- Dropped support for Django < 2.2
- Dropped support for Python < 3.6
upcoming: Version 2.0.0
- BREAKING: dropped support for Python < 3.6
- BREAKING: dropped support for Django < 3.2
- DEPRECATION: the module is now called "simple_menu" instead of "menu" (#93)
- BREAKING: when using "simple_menu", the Bootstrap templates are located
inside the "simple_menu" subfolder
- Moved CI to GitHub Actions (#67, #72)
- Project is now a part of Jazzband (#54)
- Updated the example app

Version 1.2.1 - Released May 1st, 2016
- Fixing sdist packaging
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ include LICENSE
include README.rst
include CHANGES
include AUTHORS
recursive-include simple_menu/templates *
recursive-include simple_menu/templatetags *
recursive-include menu/templates *
recursive-include menu/templatetags *
recursive-include docs *
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ and more.
Quickstart
----------

**Requirements:** Python 3.6+, Django 2.2+
**Requirements:** Python 3.6+, Django 3.2+

1. Install the ``django-simple-menu`` package.

2. Add ``menu`` to your ``INSTALLED_APPS``.
2. Add ``simple_menu`` to your ``INSTALLED_APPS``.

- please ensure that you have ``django.template.context_processors.request``
listed under ``TEMPLATES[...]["OPTIONS"]["context_processors"]``.

3. Create ``menus.py`` inside each app you want to create a menu for and define
said menus using the ``Menu`` and ``MenuItem`` classes you can import from
the ``menu`` namespace.
the ``simple_menu`` package.

4. In your templates, load the template tags (``{% load menu %}``) and call
``{% generate_menu %}`` inside a block. Your context will be populated with
a new object named ``menus``. You can now iterate over it to render your
4. In your templates, load the template tags (``{% load simple_menu %}``) and
call ``{% generate_menu %}`` inside a block. Your context will be populated
with a new object named ``menus``. You can now iterate over it to render your
menus.

To quickly see ``django-simple-menu`` in action, check out the
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import sys, os

from menu import __version__
from simple_menu import __version__

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Installing django-simple-menu

pip install django-simple-menu

#. Add ``menu`` to your ``INSTALLED_APPS`` list in your settings
#. Add ``simple_menu`` to your ``INSTALLED_APPS`` list in your settings

#. ``django-simple-menu`` requires that the ``request`` object be available in
the context when you call the ``{% generate_menu %}`` template tag. This
Expand Down
25 changes: 10 additions & 15 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ access from within your templates. This way you can have a menu for your main
navigation, another menu for logged in users, another menu for anonymous users,
etc.

.. note::

Since we use the ``menu`` namespace you will get ``ImportError`` if you
have any files named ``menu.py``, ensure you use a plural version:
``menus.py``

To define your menus you need to create a file named ``menus.py`` inside of the
app that you wish to hook menus up to. In the ``menus.py`` file you should
import the ``Menu`` and ``MenuItem`` classes from the ``menu`` package::
import the ``Menu`` and ``MenuItem`` classes from the ``simple_menu`` package::

from menu import Menu, MenuItem
from simple_menu import Menu, MenuItem

The ``Menu`` class exposes a class method named ``add_item`` that accepts two
arguments; the menu name you want to add to, and the ``MenuItem`` you're going
Expand All @@ -44,7 +38,8 @@ available in your templates. For example adding ``separator=True`` could be
used to add separators to menus ``{% if item.separator %}<li
class="divider"></li>{% endif %}``

For the full list of ``MenuItem`` options see the `menu __init__.py source file`_.
For the full list of ``MenuItem`` options see the
`simple_menu __init__.py source file`_.

Usage Example
-------------
Expand Down Expand Up @@ -92,7 +87,7 @@ Once you have your menus defined you need to incorporate them into your
templates. This is done through the ``generate_menu`` template tag::

{% extends "base.html" %}
{% load menu %}
{% load simple_menu %}

{% block content %}
{% generate_menu %}
Expand All @@ -117,7 +112,7 @@ the following items will be set in the context for you.


See the bootstrap-navbar.html file in the templates dir of the source code for
an example that renders menus for the `Twitter Bootstrap Navbar Component`_.
an example that renders menus for the `Bootstrap Navbar Component`_.
You can use it like::

{% with menu=menus.main %}{% include "bootstrap-navbar.html" %}{% endwith %}
Expand All @@ -137,7 +132,7 @@ This assumes you have a ``utils`` package.

from django.core.urlresolvers import resolve

from menu import MenuItem
from simple_menu import MenuItem


class ViewMenuItem(MenuItem):
Expand All @@ -158,7 +153,7 @@ This assumes you have a ``utils`` package.

from utils.menus import ViewMenuItem

from menu import Menu, MenuItem
from simple_menu import Menu, MenuItem

from django.core.urlresolvers import reverse

Expand All @@ -175,5 +170,5 @@ This assumes you have a ``utils`` package.
children=reports_children))


.. _menu __init__.py source file: https://github.com/jazzband/django-simple-menu/blob/master/menu/__init__.py
.. _Twitter Bootstrap Navbar Component: http://twitter.github.com/bootstrap/components.html#navbar
.. _simple_menu __init__.py source file: https://github.com/jazzband/django-simple-menu/blob/master/simple_menu/__init__.py
.. _Bootstrap Navbar Component: https://getbootstrap.com/docs/5.1/components/navbar/
18 changes: 18 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### Django ###
db.sqlite3
db.sqlite3-journal

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# PyCharm
.idea/

# Visual Studio Code
.vscode/
73 changes: 52 additions & 21 deletions example/README.rst
Original file line number Diff line number Diff line change
@@ -1,30 +1,61 @@
Example Project for django-simple-menu
======================================
==============================
django-simple-menu example app
==============================

This is a complete example project for django-simple-menu that can be quickly
used to evaluate if django-simple-menu is right for you.
Set up
------

Setting up
----------
1. Create a virtualenv, source it, and install dependencies::

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

2. Initialize a database and create test users::

python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py createsuperuser --username admin
python3 manage.py createsuperuser --username user

3. Run server::

python3 manage.py runserver

4. Go to Django administration (probably under http://127.0.0.1:8000/admin/)
and remove superuser rights from the second user you've created.

5. Look around the website, try logging in, have fun :)

To setup the project you need to create a new virtualenv directory and install
the dependencies listed in the requirements file::
Screenshots
-----------
.. figure:: ./screenshots/main_page.png

virtualenv testenv
source testenv/bin/activate
pip install -r requirements.txt
Index page of the example app

Next setup the Django instance::
.. figure:: ./screenshots/subpage.png

Page featuring a submenu

.. figure:: ./screenshots/user_page.png

Page only shown to the authenticated users

.. figure:: ./screenshots/secret_page.png

Page only shown to the superusers

Learn more
----------

./manage.py syncdb
Full documentation, including installation and configuration instructions, is
available at https://django-simple-menu.readthedocs.io/.

And finally run the project::
``django-simple-menu`` is released under the *BSD 2-Clause "Simplified" License*.
If you like it, please consider contributing!

./manage.py runserver
``django-simple-menu`` was originally created by
Evan Borgstom <[email protected]> and was further developed by many
contributors_.

Once you access the project at http://127.0.0.1:8000 you will see a menu that
will change depending on if you're logged in, logged in as a staff member or
logged in as a superuser. To fully see the menu system in action you will need
to login to the Django admin and create two new users (one just a staff member
and the other a regular user, you already have a superuser from the syncdb
call) and then login with all three of them to compare the resulting menus.
.. _contributors: https://github.com/jazzband/django-simple-menu/graphs/contributors
6 changes: 6 additions & 0 deletions example/accounts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'accounts'
51 changes: 32 additions & 19 deletions example/accounts/menus.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,49 @@
from django.core.urlresolvers import reverse
from django.urls import reverse

from simple_menu import Menu, MenuItem

from menu import Menu, MenuItem

def profile_title(request):
"""
Return a personalized title for our profile menu item
"""Return a personalized title for our profile menu item
"""
# we don't need to check if the user is authenticated because our menu
# item will have a check that does that for us
name = request.user.get_full_name() or request.user

return "%s's Profile" % name
return f"{name}'s Profile"

Menu.add_item("main", MenuItem("Accounts Index",
reverse("accounts.views.index")))

submenu_items = [
MenuItem(f"Page {i}",
reverse('accounts:subpage', kwargs={'i': i}),
icon=f'{i}-circle')
for i in range(1, 4)
]
Menu.add_item("user", MenuItem("Subpages",
reverse('accounts:subpage', kwargs={'i': 1}),
icon="menu-app",
children=submenu_items))

# this item will be shown to users who are not logged in
Menu.add_item("user", MenuItem("Login",
reverse('django.contrib.auth.views.login'),
check=lambda request: not request.user.is_authenticated()))
Menu.add_item("user", MenuItem("Sign in",
reverse('accounts:sign_in'),
icon='box-arrow-in-right',
check=lambda r: not r.user.is_authenticated))

# this will only be shown to logged in users and also demonstrates how to use
# a callable for the title to return a customized title for each request
Menu.add_item("user", MenuItem(profile_title,
reverse('accounts.views.profile'),
check=lambda request: request.user.is_authenticated()))
Menu.add_item("user", MenuItem("Logout",
reverse('django.contrib.auth.views.logout'),
check=lambda request: request.user.is_authenticated()))
reverse('accounts:profile'),
icon='person-circle',
check=lambda r: r.user.is_authenticated))

# this only shows to superusers
Menu.add_item("user", MenuItem("Admin",
reverse("admin:index"),
separator=True,
check=lambda request: request.user.is_superuser))
Menu.add_item("user", MenuItem("Secret superuser page",
reverse("accounts:super_only"),
icon='incognito',
check=lambda r: r.user.is_superuser))

Menu.add_item("user", MenuItem("Sign out",
reverse('accounts:sign_out'),
icon='box-arrow-right',
check=lambda r: r.user.is_authenticated))
File renamed without changes.
Loading

0 comments on commit 1dc4faa

Please sign in to comment.