Browse Source

Fix project names in the top navigation dropdown menu.

pull/214/head
Pēteris Caune 6 years ago
parent
commit
e98bd42438
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 10 additions and 14 deletions
  1. +4
    -1
      hc/accounts/middleware.py
  2. +6
    -13
      templates/base.html

+ 4
- 1
hc/accounts/middleware.py View File

@ -1,3 +1,4 @@
from django.db.models import Q
from hc.accounts.models import Profile, Project
@ -9,7 +10,9 @@ class TeamAccessMiddleware(object):
if not request.user.is_authenticated:
return self.get_response(request)
projects_q = Project.objects.filter(member__user_id=request.user.id)
is_owner = Q(owner=request.user)
is_member = Q(member__user_id=request.user.id)
projects_q = Project.objects.filter(is_owner | is_member)
projects_q = projects_q.select_related("owner")
request.get_projects = lambda: list(projects_q)


+ 6
- 13
templates/base.html View File

@ -116,7 +116,7 @@
<li class="dropdown">
<a id="nav-email" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">
{% if check %}
{{ check.project.owner.profile }}
{{ check.project }}
{% else %}
{{ request.project }}
{% endif %}
@ -124,26 +124,19 @@
</a>
<ul class="dropdown-menu">
{% with projects=request.get_projects %}
{% if projects %}
<li class="dropdown-header">{{ request.user.profile }}</li>
<li>
<a href="{% url 'hc-switch-team' request.user.username %}" class="active">Checks</a>
</li>
{% endif %}
<li><a href="{% url 'hc-profile' %}">Account Settings</a></li>
<li role="separator" class="divider"></li>
{% for project in projects %}
<li class="dropdown-header">{{ project }}</li>
<li>
<a href="{% url 'hc-switch-team' project.owner.username %}">Checks</a>
</li>
{% if project.owner == request.user %}
<li><a href="{% url 'hc-profile' %}">Account Settings</a></li>
{% endif %}
<li role="separator" class="divider"></li>
{% endfor %}
<li><a href="{% url 'hc-logout' %}">Log Out</a></li>
{% endwith %}
<li><a href="{% url 'hc-logout' %}">Log Out</a></li>
</ul>
</li>
</ul>


Loading…
Cancel
Save