From 6d8b3c2d3a49e421a6b62f72c110030f1b3b9d3a Mon Sep 17 00:00:00 2001 From: Ivan Fonseca Date: Fri, 20 Jul 2018 22:14:38 -0400 Subject: [PATCH] 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. --- tildes/scss/modules/_nav.scss | 5 ++ tildes/tildes/templates/base_user_menu.jinja2 | 7 ++ tildes/tildes/templates/invite.jinja2 | 2 +- .../tildes/templates/macros/user_menu.jinja2 | 69 +++++++++++++++++++ tildes/tildes/templates/messages.jinja2 | 2 +- .../templates/notifications_unread.jinja2 | 2 +- tildes/tildes/templates/settings.jinja2 | 2 +- tildes/tildes/templates/user.jinja2 | 37 +--------- tildes/tildes/views/user.py | 13 ---- 9 files changed, 87 insertions(+), 52 deletions(-) create mode 100644 tildes/tildes/templates/base_user_menu.jinja2 create mode 100644 tildes/tildes/templates/macros/user_menu.jinja2 diff --git a/tildes/scss/modules/_nav.scss b/tildes/scss/modules/_nav.scss index 2c552bd..415a09e 100644 --- a/tildes/scss/modules/_nav.scss +++ b/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; + } } } diff --git a/tildes/tildes/templates/base_user_menu.jinja2 b/tildes/tildes/templates/base_user_menu.jinja2 new file mode 100644 index 0000000..003be42 --- /dev/null +++ b/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 %} diff --git a/tildes/tildes/templates/invite.jinja2 b/tildes/tildes/templates/invite.jinja2 index 7ae3d49..4689995 100644 --- a/tildes/tildes/templates/invite.jinja2 +++ b/tildes/tildes/templates/invite.jinja2 @@ -1,4 +1,4 @@ -{% extends 'base_no_sidebar.jinja2' %} +{% extends 'base_user_menu.jinja2' %} {% block title %}Invite someone{% endblock %} diff --git a/tildes/tildes/templates/macros/user_menu.jinja2 b/tildes/tildes/templates/macros/user_menu.jinja2 new file mode 100644 index 0000000..761a85a --- /dev/null +++ b/tildes/tildes/templates/macros/user_menu.jinja2 @@ -0,0 +1,69 @@ +{% macro render_user_menu() %} + {% set route = request.matched_route.name %} + +

User menu

+ +{% endmacro %} diff --git a/tildes/tildes/templates/messages.jinja2 b/tildes/tildes/templates/messages.jinja2 index d9df80b..8877a6d 100644 --- a/tildes/tildes/templates/messages.jinja2 +++ b/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 %} diff --git a/tildes/tildes/templates/notifications_unread.jinja2 b/tildes/tildes/templates/notifications_unread.jinja2 index 7ae6a63..b580f1f 100644 --- a/tildes/tildes/templates/notifications_unread.jinja2 +++ b/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 %} diff --git a/tildes/tildes/templates/settings.jinja2 b/tildes/tildes/templates/settings.jinja2 index 49175a8..e8264f6 100644 --- a/tildes/tildes/templates/settings.jinja2 +++ b/tildes/tildes/templates/settings.jinja2 @@ -1,4 +1,4 @@ -{% extends 'base_no_sidebar.jinja2' %} +{% extends 'base_user_menu.jinja2' %} {% block title %}User settings{% endblock %} diff --git a/tildes/tildes/templates/user.jinja2 b/tildes/tildes/templates/user.jinja2 index 1bb53d6..1e3a1f1 100644 --- a/tildes/tildes/templates/user.jinja2 +++ b/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 %} -

User menu

- + {{ super() }}
{% endif %} diff --git a/tildes/tildes/views/user.py b/tildes/tildes/views/user.py index 7627861..3b3da0b 100644 --- a/tildes/tildes/views/user.py +++ b/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, }