Debian Codegraph @

README.rst

raw
1 Django Menu Generator - next generation
2 =======================================
3
4 A menu generating application for Django
5
6 Forked from the original at https://github.com/LaLogiaDePython/django-menu-generator
7
8
9 A productivity tool that enables the generation of full featured menus
10 through python dictionaries list, you only need to setup the HTML
11 structure once for each menu you like to build and then use the
12 dictionaries to generate menu items
13
14 Features:
15 ---------
16
17 - Tested support to Python 3.7, 3.8, 3.9
18 - Tested support to Django 2.2, 3.0, 3.1
19 - No database
20 - Support unlimited menus
21 - Icons support
22 - Semi-Automatically identifies the selected item and his breadcrums
23 - Conditional menu items display through validators (Permissions,
24 Authentications or whatever you want)
25
26 Documentation:
27 --------------
28 The full documentation for Django Menu Generator is allowed here:
29
30 http://django-menu-generator.readthedocs.io/en/latest/index.html
31
32 Installation:
33 -------------
34
35 You can install it with one of these options:
36
37 - ``easy_install django-menu-generator``
38 - ``pip install django-menu-generator``
39 - ``git clone https://github.com/LaLogiaDePython/django-menu-generator``
40
41 1. ``cd django-menu-generator``
42 2. run python setup.py
43
44 - ``wget https://github.com/LaLogiaDePython/django-menu-generator/zipball/master``
45
46 1. unzip the downloaded file
47 2. cd into django-menu-generator-\* directory
48 3. run python setup.py
49
50 Usage:
51 ------
52
53 1. Once installed, add ``'menu_generator'`` to your INSTALLED\_APPS.
54 2. Add ``{% load menu_generator %}`` to templates that will handle the
55 menus.
56 3. Add the list dictionaries containing the menu items to the settings
57
58 .. code:: python
59
60 ####################################################################################
61 Example: settings.py
62 ####################################################################################
63
64 NAV_MENU_LEFT = [
65 {
66 "name": "Home",
67 "url": "/",
68 },
69 {
70 "name": "About",
71 "url": "/about",
72 },
73 ]
74
75 NAV_MENU_RIGHT = [
76 {
77 "name": "Login",
78 "url": "login_url_view", # reversible
79 "validators": ["menu_generator.validators.is_anonymous"],
80 },
81 {
82 "name": "Register",
83 "url": "register_view_url", # reversible
84 "validators": ["menu_generator.validators.is_anonymous"],
85 },
86 {
87 "name": "Account",
88 "url": "/acount",
89 "validators": ["menu_generator.validators.is_authenticated"],
90 "submenu": [
91 {
92 "name": "Profile",
93 "url": "/account/profile",
94 },
95 {
96 "name": "Account Balance",
97 "url": "/account/balance",
98 "validators": ["myapp.profiles.is_paid_user"],
99 },
100 {
101 "name": "Account Secrets",
102 "url": "/account/secrets",
103 "validators": ["menu_generator.validators.is_superuser"],
104 }
105 ],
106 },
107 ]
108
109 FOOTER_MENU_LEFT = [
110 {
111 "name": "Facebook",
112 "url": "facebook.com/foobar",
113 },
114 {
115 "name": "Contact US",
116 "url": "/contact",
117 },
118 ]
119
120 FOOTER_MENU_RIGHT = [
121 {
122 "name": "Address",
123 "url": "/address",
124 },
125 ]
126
127 Or you can build the menu dictionaries list inside the project apps with
128 ``menus.py`` files, see docs for more.
129
130 4. In your template, load the template tag to generate your menu.
131
132 ::
133
134 {% load menu_generator %}
135 <!DOCTYPE html>
136 <html>
137 <head><title>Django Menu Generator</title></head>
138 <body>
139 <!-- NAV BAR Start -->
140 {% get_menu "NAV_MENU_LEFT" as left_menu %}
141 <div style="float:left;">
142 {% for item in left_menu %}
143 <li class="{% if item.selected %} active {% endif %}">
144 <a href="{{ item.url }}"> <i class="{{ item.icon_class }}"></i> {{ item.name }}</a>
145 </li>
146 {% if item.submenu %}
147 <ul>
148 {% for menu in item.submenu %}
149 <li class="{% if menu.selected %} active {% endif %}">
150 <a href="{{ menu.url }}">{{ menu.name }}</a>
151 </li>
152 {% endfor %}
153 </ul>
154 {% endif %}
155 {% endfor %}
156 </div>
157
158 {% get_menu "NAV_MENU_RIGHT" as right_menu %}
159 <div style="float:right;">
160 {% for item in right_menu %}
161 <li class="{% if item.selected %} active {% endif %}">
162 <a href="{{ item.url }}">{{ item.name }}</a>
163 </li>
164 {% if item.submenu %}
165 <ul>
166 {% for menu in item.submenu %}
167 <li class="{% if menu.selected %} active {% endif %}">
168 <a href="{{ menu.url }}">{{ menu.name }}</a>
169 </li>
170 {% endfor %}
171 </ul>
172 {% endif %}
173 {% endfor %}
174 </div>
175 <!-- NAV BAR End -->
176
177 <!-- Footer Start -->
178 {% get_menu "FOOTER_MENU_LEFT" as left_footer_menu %}
179 <div style="float:left;">
180 <!-- loop through your left footer menus -->
181 </div>
182
183 {% get_menu "FOOTER_MENU_RIGHT" as right_footer_menu %}
184 <div style="float:right;">
185 <!-- loop through your right footer menus -->
186 </div>
187 <!-- Footer End -->
188 </body>
189 </html>
190
191 5. Now you must to see your menus generated when you run your project
192
193 Running the tests:
194 ------------------
195
196 To run the tests against configured environments:
197
198 ::
199
200 tox
201
202 License:
203 --------
204
205 Released under a (`MIT <LICENSE>`__) license.
206
207 Author and mantainers:
208 ----------------------
209
210 This fork is maintained by the AlekSIS team.
211
212 Original authors and maintainers
213 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214
215 The following people maintained django-menu-generator for a long time:
216
217 `Milton Lenis <https://github.com/MiltonLn>`__ - [email protected]
218
219 `Juan Diego GarcĂ­a <https://github.com/yamijuan>`__ - [email protected]
220
221 Credits:
222 --------
223
224 We would like to thank `Val Kneeman <https://github.com/un33k>`__, the
225 original author of this project under the name 'menuware'
226 https://github.com/un33k/django-menuware