Browse Source

Add setting to open links in new tab (#34)

merge-requests/3/head
Ivan Fonseca 8 years ago
parent
commit
1ba3c54f67
No known key found for this signature in database GPG Key ID: 95A9C856EC788689
  1. 24
      tildes/alembic/versions/becc33b73339_add_setting_to_open_links_in_new_tabs.py
  2. 2
      tildes/tildes/models/user/user.py
  3. 15
      tildes/tildes/templates/macros/topics.jinja2
  4. 20
      tildes/tildes/templates/settings.jinja2
  5. 5
      tildes/tildes/templates/topic.jinja2
  6. 16
      tildes/tildes/views/api/web/user.py

24
tildes/alembic/versions/becc33b73339_add_setting_to_open_links_in_new_tabs.py

@ -0,0 +1,24 @@
"""Add setting to open links in new tabs
Revision ID: becc33b73339
Revises:
Create Date: 2018-07-19 02:56:06.160422
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'becc33b73339'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
op.add_column('users', sa.Column('open_links_new_tab', sa.Boolean(), server_default='false', nullable=False))
def downgrade():
op.drop_column('users', 'open_links_new_tab')

2
tildes/tildes/models/user/user.py

@ -82,6 +82,8 @@ 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(
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')
home_default_order: Optional[TopicSortOption] = Column(

15
tildes/tildes/templates/macros/topics.jinja2

@ -11,9 +11,15 @@
<div>
<h1 class="topic-title">
{% if topic.is_text_type %}
<a href="{{ topic.permalink }}">{{ topic.title }}</a>
<a
href="{{ topic.permalink }}"
{{ 'target=_blank' if request.user.open_links_new_tab }}
>{{ topic.title }}</a>
{% elif topic.is_link_type %}
<a href="{{ topic.link }}">{{ topic.title }}</a>
<a
href="{{ topic.link }}"
{{ 'target=_blank' if request.user.open_links_new_tab }}
>{{ topic.title }}</a>
{% endif %}
</h1>
<span class="topic-content-metadata">({{ topic.content_metadata_for_display }})</span>
@ -56,7 +62,10 @@
<footer class="topic-info">
<div class="topic-info-comments">
<a href="{{ topic.permalink }}">
<a
href="{{ topic.permalink }}"
{{ 'target=_blank' if request.user.open_links_new_tab }}
>
{% trans num_comments=topic.num_comments %}
{{ num_comments }} comment
{% pluralize %}

20
tildes/tildes/templates/settings.jinja2

@ -37,6 +37,26 @@
</div>
</form>
</li>
<li>
<form
name="open-links-new-tab"
autocomplete="off"
data-ic-patch-to="{{ request.route_url('ic_user', username=request.user.username) }}"
>
<div class="form-group">
<label class="form-checkbox">
<input
type="checkbox"
id="open_links_new_tab"
name="open_links_new_tab"
data-js-autosubmit-on-change
{% if request.user.open_links_new_tab %}checked{% endif %}
>
<i class="form-icon"></i> Open posts and external links in a new tab
</label>
</div>
</form>
</li>
<li><a href="/settings/password_change">Change your password</a></li>
<li>
<a href="/settings/account_recovery">Set up account recovery</a>

5
tildes/tildes/templates/topic.jinja2

@ -44,7 +44,10 @@
{% elif topic.is_link_type %}
<div class="topic-full-link">
<div class="topic-icon topic-icon-{{ topic.link_domain.replace('.', '_') }}"></div>
<a href="{{ topic.link }}">{{ topic.link }}</a>
<a
href="{{ topic.link }}"
{{ 'target=_blank' if request.user.open_links_new_tab }}
>{{ topic.link }}</a>
</div>
{% endif %}
{% endif %}

16
tildes/tildes/views/api/web/user.py

@ -104,6 +104,22 @@ def change_auto_mark_notifications(request: Request) -> Response:
return IC_NOOP
@ic_view_config(
route_name='user',
request_method='PATCH',
request_param='ic-trigger-name=open-links-new-tab',
permission='change_open_links_new_tab_setting',
)
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
return IC_NOOP
@ic_view_config(
route_name='user',
request_method='PATCH',

Loading…
Cancel
Save