Browse Source

Add user menu sidebar to all user pages

Previously, the user menu sidebar was only available on the "base" user
page, but disappeared if you went into any of the individual pages. This
adds it to all of the pages, including highlighting the current page in
the menu.

Behavior of the "invite count" was changed slightly to save needing to
do an extra query on every page - it now only includes the number of
"un-generated" invite codes, not the number that have already been
generated but are sitting unused.
merge-requests/13/head
Ivan Fonseca 7 years ago
committed by Deimos
parent
commit
6d8b3c2d3a
  1. 5
      tildes/scss/modules/_nav.scss
  2. 7
      tildes/tildes/templates/base_user_menu.jinja2
  3. 2
      tildes/tildes/templates/invite.jinja2
  4. 69
      tildes/tildes/templates/macros/user_menu.jinja2
  5. 2
      tildes/tildes/templates/messages.jinja2
  6. 2
      tildes/tildes/templates/notifications_unread.jinja2
  7. 2
      tildes/tildes/templates/settings.jinja2
  8. 37
      tildes/tildes/templates/user.jinja2
  9. 13
      tildes/tildes/views/user.py

5
tildes/scss/modules/_nav.scss

@ -11,6 +11,11 @@
font-size: 0.8rem;
font-weight: normal;
border-bottom: 0;
&.active a {
color: $blue;
text-decoration: underline;
}
}
}

7
tildes/tildes/templates/base_user_menu.jinja2

@ -0,0 +1,7 @@
{% extends 'base.jinja2' %}
{% from 'macros/user_menu.jinja2' import render_user_menu with context %}
{% block sidebar %}
{{ render_user_menu() }}
{% endblock %}

2
tildes/tildes/templates/invite.jinja2

@ -1,4 +1,4 @@
{% extends 'base_no_sidebar.jinja2' %}
{% extends 'base_user_menu.jinja2' %}
{% block title %}Invite someone{% endblock %}

69
tildes/tildes/templates/macros/user_menu.jinja2

@ -0,0 +1,69 @@
{% macro render_user_menu() %}
{% set route = request.matched_route.name %}
<h2>User menu</h2>
<ul class="nav">
<li>Profile</li>
<ul class="nav">
<li class="nav-item {{ 'active' if route == 'user' else ''}}">
<a href="/user/{{ request.user }}">
Recent activity
</a>
</li>
</ul>
<li>Notifications</li>
<ul class="nav">
{% if request.user.num_unread_notifications > 0 %}
<li class="nav-item {{ 'active' if route == 'notifications_unread' else '' }}">
<strong><a href="/notifications/unread">
Unread ({{ request.user.num_unread_notifications }})
</a></strong>
</li>
{% endif %}
<li class="nav-item {{ 'active' if route == 'notifications' else '' }}">
<a href="/notifications">
Previously read
</a>
</li>
</ul>
<li>Messages</li>
<ul class="nav">
{% if request.user.num_unread_messages > 0 %}
<li class="nav-item {{ 'active' if route == 'messages_unread' else '' }}">
<strong><a href="/messages/unread">
Unread ({{ request.user.num_unread_messages }})
</a></strong>
</li>
{% endif %}
<li class="nav-item {{ 'active' if route == 'messages' else '' }}">
<a href="/messages">
Inbox
</a>
</li>
<li class="nav-item {{ 'active' if route == 'messages_sent' else '' }}">
<a href="/messages/sent">
Sent messages
</a>
</li>
</ul>
<li>Misc</li>
<ul class="nav">
<li class="nav-item {{ 'active' if route == 'invite' else '' }}">
{% if request.user.invite_codes_remaining %}<strong>{% endif %}
<a href="/invite">
Invite someone {% if request.user.invite_codes_remaining %}({{ request.user.invite_codes_remaining }}){% endif %}
</a>
{% if request.user.invite_codes_remaining %}</strong>{% endif %}
</li>
<li class="nav-item {{ 'active' if route == 'settings' else '' }}">
<a href="/settings">
Settings
</a>
</li>
<li class="nav-item"><a href="/logout">Log out</a></li>
</ul>
</ul>
{% endmacro %}

2
tildes/tildes/templates/messages.jinja2

@ -1,4 +1,4 @@
{% extends 'base_no_sidebar.jinja2' %}
{% extends 'base_user_menu.jinja2' %}
{% from 'macros/datetime.jinja2' import time_ago_responsive %}
{% from 'macros/links.jinja2' import username_linked %}

2
tildes/tildes/templates/notifications_unread.jinja2

@ -1,4 +1,4 @@
{% extends 'base_no_sidebar.jinja2' %}
{% extends 'base_user_menu.jinja2' %}
{% from 'macros/comments.jinja2' import comment_tag_options_template, render_single_comment with context %}
{% from 'macros/links.jinja2' import group_linked %}

2
tildes/tildes/templates/settings.jinja2

@ -1,4 +1,4 @@
{% extends 'base_no_sidebar.jinja2' %}
{% extends 'base_user_menu.jinja2' %}
{% block title %}User settings{% endblock %}

37
tildes/tildes/templates/user.jinja2

@ -1,4 +1,4 @@
{% extends 'base.jinja2' %}
{% extends 'base_user_menu.jinja2' %}
{% from 'macros/comments.jinja2' import render_single_comment with context %}
{% from 'macros/links.jinja2' import group_linked, username_linked %}
@ -37,40 +37,7 @@
{% block sidebar %}
{% if user == request.user %}
<h2>User menu</h2>
<ul class="nav">
<li>Notifications</li>
<ul class="nav">
{% if request.user.num_unread_notifications > 0 %}
<li class="nav-item"><strong><a href="/notifications/unread">
Unread ({{ request.user.num_unread_notifications }})
</a></strong></li>
{% endif %}
<li class="nav-item"><a href="/notifications">Previously read</a></li>
</ul>
<li>Messages</li>
<ul class="nav">
{% if request.user.num_unread_messages > 0 %}
<li class="nav-item"><strong><a href="/messages/unread">
Unread ({{ request.user.num_unread_messages }})
</a></strong></li>
{% endif %}
<li class="nav-item"><a href="/messages">Inbox</a></li>
<li class="nav-item"><a href="/messages/sent">Sent messages</a></li>
</ul>
<li>Misc</li>
<ul class="nav">
{% if request.user.invite_codes_remaining or num_active_invite_codes %}
<li class="nav-item"><strong><a href="/invite">
Invite someone ({{ request.user.invite_codes_remaining + num_active_invite_codes }})
</a></strong></li>
{% endif %}
<li class="nav-item"><a href="/settings">Settings</a></li>
<li class="nav-item"><a href="/logout">Log out</a></li>
</ul>
</ul>
{{ super() }}
<hr>
{% endif %}

13
tildes/tildes/views/user.py

@ -54,22 +54,9 @@ def get_user(request: Request) -> dict:
)
merged_posts = merged_posts[:page_size]
# if the user is on their own page, check if they have active invite codes
num_active_invite_codes = None
if user == request.user:
num_active_invite_codes = (
request.query(UserInviteCode)
.filter(
UserInviteCode.user_id == request.user.user_id,
UserInviteCode.invitee_id == None, # noqa
)
.count()
)
return {
'user': user,
'merged_posts': merged_posts,
'num_active_invite_codes': num_active_invite_codes,
}

Loading…
Cancel
Save