Pastebin
Paste #25074: No description
< previous paste - next paste>
Pasted by Anonymous Coward
### context_processors.py
from django.urls import reverse
def menu_items(request):
menu_dict = {'menu_items': []}
if request.user.is_authenticated:
if request.user.userprofile.is_consultant():
menu_dict['menu_items'].extend([
{'name': 'Leads', 'url': reverse('leads_view')},
{'name': 'Deals', 'url': reverse('deals_view')},
{'name': 'Customers', 'url': reverse('customers_view')},
{'name': 'Contacts', 'url': reverse('contacts_view')},
{'name': 'Consultants', 'url': reverse('consultants_view')},
])
if request.user.userprofile.is_manager():
menu_dict['menu_items'].extend([
{'name': 'New Deal', 'url': reverse('deal_new')},
{'name': 'New Lead', 'url': reverse('lead_new')},
{'name': 'New Customer', 'url': reverse('customer_new')},
{'name': 'New Contact', 'url': reverse('contact_new')},
{'name': 'New Consultant', 'url': reverse('consultant_new')},
])
return menu_dict
## nav.html
...
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
{% for item in menu_items %}
<li class="nav-item">
<a class="nav-link" href="{{ item.url }}">{{ item.name }}</a>
</li>
{% endfor %}
</ul>
...
New Paste
Go to most recent paste.