From f75bdec75645e6e3b1b3e000f900ec3ef8dcab20 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 5 Dec 2020 01:51:50 +0000 Subject: [PATCH] Add settings template --- app/blueprints/api/tokens.py | 3 +- app/blueprints/users/profile.py | 17 +- app/templates/admin/audit.html | 4 +- app/templates/api/list_tokens.html | 23 +- app/templates/macros/reviews.html | 2 +- app/templates/macros/threads.html | 4 +- app/templates/notifications/list.html | 4 +- .../packages/review_create_edit.html | 2 +- app/templates/threads/new.html | 2 +- app/templates/users/profile.html | 2 +- app/templates/users/profile_edit.html | 310 +++++++++--------- app/templates/users/settings_base.html | 30 ++ 12 files changed, 215 insertions(+), 188 deletions(-) create mode 100644 app/templates/users/settings_base.html diff --git a/app/blueprints/api/tokens.py b/app/blueprints/api/tokens.py index 49993741..9c341185 100644 --- a/app/blueprints/api/tokens.py +++ b/app/blueprints/api/tokens.py @@ -25,6 +25,7 @@ from wtforms.validators import * from app.models import db, User, APIToken, Package, Permission from app.utils import randomString from . import bp +from ..users.profile import get_setting_tabs class CreateAPIToken(FlaskForm): @@ -50,7 +51,7 @@ def list_tokens(username): if not user.checkPerm(current_user, Permission.CREATE_TOKEN): abort(403) - return render_template("api/list_tokens.html", user=user) + return render_template("api/list_tokens.html", user=user, tabs=get_setting_tabs(), current_tab="api_tokens") @bp.route("/users//tokens/new/", methods=["GET", "POST"]) diff --git a/app/blueprints/users/profile.py b/app/blueprints/users/profile.py index 65927391..d232d621 100644 --- a/app/blueprints/users/profile.py +++ b/app/blueprints/users/profile.py @@ -76,6 +76,21 @@ def profile(username): user=user, packages=packages, topics_to_add=topics_to_add) +def get_setting_tabs(): + return [ + { + "id": "edit_profile", + "title": "Edit Profile", + "url": url_for("users.profile_edit", username=current_user.username) + }, + { + "id": "api_tokens", + "title": "API Tokens", + "url": url_for("api.list_tokens", username=current_user.username) + }, + ] + + @bp.route("/users//edit/", methods=["GET", "POST"]) def profile_edit(username): user : User = User.query.filter_by(username=username).first() @@ -139,7 +154,7 @@ def profile_edit(username): return redirect(url_for("users.profile", username=username)) # Process GET or invalid POST - return render_template("users/profile_edit.html", user=user, form=form) + return render_template("users/profile_edit.html", user=user, form=form, tabs=get_setting_tabs(), current_tab="edit_profile") @bp.route("/users//check/", methods=["POST"]) diff --git a/app/templates/admin/audit.html b/app/templates/admin/audit.html index bf3bee41..c3915482 100644 --- a/app/templates/admin/audit.html +++ b/app/templates/admin/audit.html @@ -31,7 +31,7 @@ Audit Log
@@ -53,7 +53,7 @@ Audit Log
diff --git a/app/templates/api/list_tokens.html b/app/templates/api/list_tokens.html index b2be8ce6..16da6576 100644 --- a/app/templates/api/list_tokens.html +++ b/app/templates/api/list_tokens.html @@ -1,23 +1,22 @@ -{% extends "base.html" %} +{% extends "users/settings_base.html" %} {% block title %} - {{ _("List tokens for %(username)s", username=user.username) }} + {{ _("API Tokens | %(username)s", username=user.username) }} {% endblock %} - -{% block content %} +{% block pane %} Create -

{{ self.title() }}

+

{{ _("API Tokens") }}

- + {% endblock %} diff --git a/app/templates/macros/reviews.html b/app/templates/macros/reviews.html index e6aa7e95..ea3ce1d9 100644 --- a/app/templates/macros/reviews.html +++ b/app/templates/macros/reviews.html @@ -4,7 +4,7 @@
  • diff --git a/app/templates/macros/threads.html b/app/templates/macros/threads.html index a69c4746..b0223488 100644 --- a/app/templates/macros/threads.html +++ b/app/templates/macros/threads.html @@ -5,7 +5,7 @@
  • @@ -59,7 +59,7 @@ {% if current_user.is_authenticated %}
    - +
    diff --git a/app/templates/notifications/list.html b/app/templates/notifications/list.html index d2503124..6d307951 100644 --- a/app/templates/notifications/list.html +++ b/app/templates/notifications/list.html @@ -22,7 +22,7 @@ Notifications
    @@ -39,7 +39,7 @@ Notifications
    {{ n.causer.display_name }}
    diff --git a/app/templates/packages/review_create_edit.html b/app/templates/packages/review_create_edit.html index eb4dff27..29bbab0e 100644 --- a/app/templates/packages/review_create_edit.html +++ b/app/templates/packages/review_create_edit.html @@ -16,7 +16,7 @@ {{ form.hidden_tag() }}
    - +
    diff --git a/app/templates/threads/new.html b/app/templates/threads/new.html index a586769f..dd60e90f 100644 --- a/app/templates/threads/new.html +++ b/app/templates/threads/new.html @@ -20,7 +20,7 @@
    - +
    diff --git a/app/templates/users/profile.html b/app/templates/users/profile.html index 3cb84624..4a12b71c 100644 --- a/app/templates/users/profile.html +++ b/app/templates/users/profile.html @@ -14,7 +14,7 @@
    - +

    diff --git a/app/templates/users/profile_edit.html b/app/templates/users/profile_edit.html index 19458d85..80df0860 100644 --- a/app/templates/users/profile_edit.html +++ b/app/templates/users/profile_edit.html @@ -1,176 +1,158 @@ -{% extends "base.html" %} +{% extends "users/settings_base.html" %} {% block title %} - Edit Profile | {{ user.username }} + {{ _("Edit Profile | %(username)s", username=user.username) }} {% endblock %} -{% block content %} +{% block pane %} +

    {{ _("Edit Profile") }}

    -

    - Editing {{ user.display_name }}'s profile -

    - -
    -
    -
    -

    {{ _("Profile Picture") }}

    -
    - -
    - {% if user.forums_username %} -
    - - -
    - {% endif %} - {% if user.email %} - - Gravatar - - {% else %} - - Gravatar - - {% endif %} -
    -
    +
    +

    {{ _("Profile Picture") }}

    +
    + - -
    -

    {{ _("Passwords and Security") }}

    - - {% if user == current_user %} - - - - - {% endif %} - {% if user.checkPerm(current_user, "CREATE_TOKEN") %} - - - - - {% endif %} -
    Password: - {% if user.password %} - Set | Change - {% else %} - Not set | Set - {% endif %} -
    API Tokens: - Manage - {{ user.tokens.count() }} -
    -
    - -
    -

    {{ _("Linked Accounts") }}

    - - - - - - - - - - - - {% if current_user.is_authenticated and current_user.rank.atLeast(current_user.rank.MODERATOR) %} - - - - - {% endif %} -
    Forums - {% if user.forums_username %} - - Connected - - {% elif user == current_user %} - None - {% endif %} -
    GitHub - {% if user.github_username %} -

    - Connected -

    - - {% if user == current_user %} -

    - View ContentDB's GitHub Permissions -

    - {% endif %} - {% elif user == current_user %} - Link Github - {% else %} - None - {% endif %} -
    Admin - {% if user.email %} - - Email - - {% else %} - - Email - - {% endif %} -
    -
    -
    - - {% from "macros/forms.html" import render_field, render_submit_field %} -
    -
    -
    Edit Details
    -
    -
    - {{ form.hidden_tag() }} - - {% if user.checkPerm(current_user, "CHANGE_USERNAMES") %} - {{ render_field(form.display_name, tabindex=230) }} - {{ render_field(form.forums_username, tabindex=230) }} - {{ render_field(form.github_username, tabindex=230) }} - {% endif %} - - {% if user.checkPerm(current_user, "CHANGE_PROFILE_URLS") %} - {{ render_field(form.website_url, tabindex=232) }} - {{ render_field(form.donate_url, tabindex=233) }} - {% endif %} - - {% if user.checkPerm(current_user, "CHANGE_EMAIL") %} - {{ render_field(form.email, tabindex=240) }} - We'll send you an email to verify it if changed. - {% endif %} - - {% if user.checkPerm(current_user, "CHANGE_RANK") %} - {{ render_field(form.rank, tabindex=250) }} - {% endif %} - -

    - {{ render_submit_field(form.submit, tabindex=280) }} -

    +
    + {% if user.forums_username %} + + + -
    + {% endif %} + {% if user.email %} + + Gravatar + + {% else %} + + Gravatar + + {% endif %}
    +
    +

    {{ _("Passwords and Security") }}

    + + {% if user == current_user %} + + + + + {% endif %} +
    Password: + {% if user.password %} + Set | Change + {% else %} + Not set | Set + {% endif %} +
    +
    + +
    +

    {{ _("Linked Accounts") }}

    + + + + + + + + + + + + {% if current_user.is_authenticated and current_user.rank.atLeast(current_user.rank.MODERATOR) %} + + + + + {% endif %} +
    Forums + {% if user.forums_username %} + + Connected + + {% elif user == current_user %} + None + {% endif %} +
    GitHub + {% if user.github_username %} +

    + Connected +

    + + {% if user == current_user %} +

    + View ContentDB's GitHub Permissions +

    + {% endif %} + {% elif user == current_user %} + Link Github + {% else %} + None + {% endif %} +
    Admin + {% if user.email %} + + Email + + {% else %} + + Email + + {% endif %} +
    +
    + +{% from "macros/forms.html" import render_field, render_submit_field %} +
    +
    Edit Details
    +
    +
    + {{ form.hidden_tag() }} + + {% if user.checkPerm(current_user, "CHANGE_USERNAMES") %} + {{ render_field(form.display_name, tabindex=230) }} + {{ render_field(form.forums_username, tabindex=230) }} + {{ render_field(form.github_username, tabindex=230) }} + {% endif %} + + {% if user.checkPerm(current_user, "CHANGE_PROFILE_URLS") %} + {{ render_field(form.website_url, tabindex=232) }} + {{ render_field(form.donate_url, tabindex=233) }} + {% endif %} + + {% if user.checkPerm(current_user, "CHANGE_EMAIL") %} + {{ render_field(form.email, tabindex=240) }} + We'll send you an email to verify it if changed. + {% endif %} + + {% if user.checkPerm(current_user, "CHANGE_RANK") %} + {{ render_field(form.rank, tabindex=250) }} + {% endif %} + +

    + {{ render_submit_field(form.submit, tabindex=280) }} +

    +
    +
    +
    + {% endblock %} diff --git a/app/templates/users/settings_base.html b/app/templates/users/settings_base.html new file mode 100644 index 00000000..115c6554 --- /dev/null +++ b/app/templates/users/settings_base.html @@ -0,0 +1,30 @@ +{% extends "base.html" %} + +{% block content %} +
    +
    +
    + + + + Profile picture + + + {{ user.display_name }} + + + + {% for item in tabs %} + + {{ item.title }} + + {% endfor %} +
    +
    +
    + {% block pane %} + {% endblock %} +
    +
    +{% endblock %}