I have a view that creates a list of managers in the context. I want
to test if a logged in user is in the list before displaying a link to
the manager dashboard.
class IndexView(TemplateView):
template_name = 'index.html'
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
context['mgr_list'] = Manager.objects.all() # TODO: filter for
expired status
return context
The test in the template:
{% if user.is_authenticated %}
<li><a href="{% url 'logout' %}">logout</a></li>
{% if user.email in mgr_list %}
<li><a href="{% url 'mgr_dashboard' %}">Manager Dashboard</a></li>
{% endif %}
{% else %}
<li><a href="{% url 'register' %}">register</a></li>
<li><a href="{% url 'login' %}">login</a></li>
{% endif %}
The correct items are displayed for the user.is_authenticated test.
Just for testing I put {{mgr_list}} in my template and it displays this:
[<Manager:
j...@mlhim.org>, <Manager:
t...@mlhim.org>]
which is correct as far as the emails are concerned but I do not
understand where the 'Manager:' comes from and why are they wrapped in
angle brackets? This seems to be why my 'if' doesn't test correctly
but I do not know what to change.
Thoughts?
Thanks,
Tim
--
MLHIM VIP Signup:
http://goo.gl/22B0U
============================================
Timothy Cook, MSc +55 21 94711995
MLHIM
http://www.mlhim.org
Like Us on FB:
https://www.facebook.com/mlhim2
Circle us on G+:
http://goo.gl/44EV5
Google Scholar:
http://goo.gl/MMZ1o
LinkedIn Profile:
http://www.linkedin.com/in/timothywaynecook