From b638f11137bb4084cdc3745d79f9bdab915c6137 Mon Sep 17 00:00:00 2001 From: Ivan Fonseca Date: Fri, 20 Jul 2018 20:12:07 -0400 Subject: [PATCH] Separate into settings for internal and external links --- ..._setting_for_opening_internal_external_.py | 26 +++++++++++ tildes/scss/modules/_settings.scss | 4 ++ tildes/tildes/models/user/user.py | 4 +- tildes/tildes/templates/macros/topics.jinja2 | 6 +-- tildes/tildes/templates/settings.jinja2 | 43 +++++++++++++------ tildes/tildes/templates/topic.jinja2 | 2 +- tildes/tildes/views/api/web/user.py | 6 ++- 7 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 tildes/alembic/versions/89d583f29f29_setting_for_opening_internal_external_.py diff --git a/tildes/alembic/versions/89d583f29f29_setting_for_opening_internal_external_.py b/tildes/alembic/versions/89d583f29f29_setting_for_opening_internal_external_.py new file mode 100644 index 0000000..dabd5b8 --- /dev/null +++ b/tildes/alembic/versions/89d583f29f29_setting_for_opening_internal_external_.py @@ -0,0 +1,26 @@ +"""Setting for opening internal & external links in new tabs + +Revision ID: 89d583f29f29 +Revises: becc33b73339 +Create Date: 2018-07-20 23:27:00.751921 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '89d583f29f29' +down_revision = 'becc33b73339' +branch_labels = None +depends_on = None + + +def upgrade(): + op.alter_column('users', 'open_links_new_tab', new_column_name='open_new_tab_external') + op.add_column('users', sa.Column('open_new_tab_internal', sa.Boolean(), server_default='false', nullable=False)) + + +def downgrade(): + op.alter_column('users', 'open_new_tab_external', new_column_name='open_links_new_tab') + op.drop_column('users', 'open_new_tab_internal') diff --git a/tildes/scss/modules/_settings.scss b/tildes/scss/modules/_settings.scss index a7f1417..3e226dd 100644 --- a/tildes/scss/modules/_settings.scss +++ b/tildes/scss/modules/_settings.scss @@ -4,4 +4,8 @@ li { margin-bottom: 1rem; } + + .sub li { + margin-bottom: unset; + } } diff --git a/tildes/tildes/models/user/user.py b/tildes/tildes/models/user/user.py index 9265bd6..73bf80f 100644 --- a/tildes/tildes/models/user/user.py +++ b/tildes/tildes/models/user/user.py @@ -82,7 +82,9 @@ class User(DatabaseModel): Boolean, nullable=False, server_default='false') auto_mark_notifications_read: bool = Column( Boolean, nullable=False, server_default='false') - open_links_new_tab: bool = Column( + open_new_tab_external: bool = Column( + Boolean, nullable=False, server_default='false') + open_new_tab_internal: bool = Column( Boolean, nullable=False, server_default='false') is_banned: bool = Column(Boolean, nullable=False, server_default='false') is_admin: bool = Column(Boolean, nullable=False, server_default='false') diff --git a/tildes/tildes/templates/macros/topics.jinja2 b/tildes/tildes/templates/macros/topics.jinja2 index f3b6dbc..daa1c06 100644 --- a/tildes/tildes/templates/macros/topics.jinja2 +++ b/tildes/tildes/templates/macros/topics.jinja2 @@ -13,12 +13,12 @@ {% if topic.is_text_type %} {{ topic.title }} {% elif topic.is_link_type %} {{ topic.title }} {% endif %} @@ -64,7 +64,7 @@
{% trans num_comments=topic.num_comments %} {{ num_comments }} comment diff --git a/tildes/tildes/templates/settings.jinja2 b/tildes/tildes/templates/settings.jinja2 index 08b1ecc..32fe3ca 100644 --- a/tildes/tildes/templates/settings.jinja2 +++ b/tildes/tildes/templates/settings.jinja2 @@ -38,23 +38,42 @@
  • +

    Open links in new tabs

    -
    - -
    +
      +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
  • Change your password
  • diff --git a/tildes/tildes/templates/topic.jinja2 b/tildes/tildes/templates/topic.jinja2 index 1ae61ca..645eb74 100644 --- a/tildes/tildes/templates/topic.jinja2 +++ b/tildes/tildes/templates/topic.jinja2 @@ -46,7 +46,7 @@ {{ topic.link }}
    {% endif %} diff --git a/tildes/tildes/views/api/web/user.py b/tildes/tildes/views/api/web/user.py index 5bc9a03..49d0f87 100644 --- a/tildes/tildes/views/api/web/user.py +++ b/tildes/tildes/views/api/web/user.py @@ -114,8 +114,10 @@ def change_open_links_new_tab(request: Request) -> Response: """Change the user's "open links in new tabs" setting.""" user = request.context - open_new_tab = bool(request.params.get('open_links_new_tab')) - user.open_links_new_tab = open_new_tab + external = bool(request.params.get('open_new_tab_external')) + internal = bool(request.params.get('open_new_tab_internal')) + user.open_new_tab_external = external + user.open_new_tab_internal = internal return IC_NOOP