Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare release of django-simple-menu 2.0.0 #86

Merged
merged 36 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7a32d8e
Move all files into a new directory
kytta Jun 6, 2022
b68a78c
Allow importing 'menu' with warning
kytta Jun 6, 2022
90e9255
Rename template tag library and add warning for the old name
kytta Jun 6, 2022
fc5945c
Rename test files
kytta Jun 6, 2022
733f3a1
Restore file structure to fix importing issues
kytta Jun 6, 2022
4e36f02
Omit old source code from coverage testing
kytta Jun 6, 2022
b00b6d4
Update README
kytta Jul 14, 2022
8786bda
Update docs
kytta Jul 14, 2022
cadf25f
Update change log
kytta May 14, 2022
7af3eb2
Bump Django version in pre-commit config
kytta May 14, 2022
ed73b3d
Bump Django and Python versions in test workflow
kytta May 14, 2022
af52efd
Bump versions in PyPI classifiers
kytta May 31, 2022
e93ab11
Bump version in README
kytta May 14, 2022
55acb99
Add "OS Independent" classifier
kytta May 31, 2022
319565f
Rename module from 'menu' to 'simple_menu' (#93)
kytta Aug 26, 2022
066ea6b
Update CHANGELOG
kytta Aug 26, 2022
056d389
Move Bootstrap templates
kytta Aug 26, 2022
dc4d66a
Replace tabs with spaces
kytta Aug 26, 2022
0de7f1a
Delete old example app
kytta May 31, 2022
bcb2179
Add .gitignore
kytta May 31, 2022
4981e82
Create new example project
kytta May 31, 2022
3f34d0d
Recreate accounts app
kytta May 31, 2022
ca017e1
Use new package name in imports
kytta Aug 26, 2022
5fefa2c
Update documentations on the pages
kytta Aug 26, 2022
03b9de5
Remove "main" menu
kytta Aug 26, 2022
022dabe
Add the super_only page instead of Django admin
kytta Aug 26, 2022
8af5213
Make index page prettier
kytta Aug 26, 2022
e19678d
Change how menu is included
kytta Aug 26, 2022
b0c6a63
Enable MENU_SELECT_PARENTS
kytta Aug 26, 2022
752d232
Add submenu
kytta Aug 26, 2022
2b952aa
Autofocus username field
kytta Aug 26, 2022
c38dc47
Update Bootstrap Icons
kytta Aug 26, 2022
aed1eef
Add screenshots
kytta Aug 26, 2022
1036f17
Update changelog
kytta Aug 26, 2022
759ed09
Update example app (#89)
kytta Aug 26, 2022
accc532
Use importlib_metadata to retrieve version
kytta Aug 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.8.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