Browse Source

Separate into settings for internal and external links

merge-requests/3/head
Ivan Fonseca 7 years ago
parent
commit
b638f11137
No known key found for this signature in database GPG Key ID: 95A9C856EC788689
  1. 26
      tildes/alembic/versions/89d583f29f29_setting_for_opening_internal_external_.py
  2. 4
      tildes/scss/modules/_settings.scss
  3. 4
      tildes/tildes/models/user/user.py
  4. 6
      tildes/tildes/templates/macros/topics.jinja2
  5. 43
      tildes/tildes/templates/settings.jinja2
  6. 2
      tildes/tildes/templates/topic.jinja2
  7. 6
      tildes/tildes/views/api/web/user.py

26
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')

4
tildes/scss/modules/_settings.scss

@ -4,4 +4,8 @@
li {
margin-bottom: 1rem;
}
.sub li {
margin-bottom: unset;
}
}

4
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')

6
tildes/tildes/templates/macros/topics.jinja2

@ -13,12 +13,12 @@
{% if topic.is_text_type %}
<a
href="{{ topic.permalink }}"
{% if request.user.open_links_new_tab %}target="_blank"{% endif %}
{% if request.user.open_new_tab_internal %}target="_blank"{% endif %}
>{{ topic.title }}</a>
{% elif topic.is_link_type %}
<a
href="{{ topic.link }}"
{% if request.user.open_links_new_tab %}target="_blank"{% endif %}
{% if request.user.open_new_tab_external %}target="_blank"{% endif %}
>{{ topic.title }}</a>
{% endif %}
</h1>
@ -64,7 +64,7 @@
<div class="topic-info-comments">
<a
href="{{ topic.permalink }}"
{% if request.user.open_links_new_tab %}target="_blank"{% endif %}
{% if request.user.open_new_tab_internal %}target="_blank"{% endif %}
>
{% trans num_comments=topic.num_comments %}
{{ num_comments }} comment

43
tildes/tildes/templates/settings.jinja2

@ -38,23 +38,42 @@
</form>
</li>
<li>
<h4>Open links in new tabs</h4>
<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>
<ul class="sub settings-list">
<li>
<div class="form-group">
<label class="form-checkbox">
<input
type="checkbox"
id="open_new_tab_external"
name="open_new_tab_external"
data-js-autosubmit-on-change
{% if request.user.open_new_tab_external %}checked{% endif %}
>
<i class="form-icon"></i> Topic links to other websites
</label>
</div>
</li>
<li>
<div class="form-group">
<label class="form-checkbox">
<input
type="checkbox"
id="open_new_tab_internal"
name="open_new_tab_internal"
data-js-autosubmit-on-change
{% if request.user.open_new_tab_internal %}checked{% endif %}
>
<i class="form-icon"></i> Links to text topics and comments
</label>
</div>
</li>
</ul>
</form>
</li>
<li><a href="/settings/password_change">Change your password</a></li>

2
tildes/tildes/templates/topic.jinja2

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

6
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

Loading…
Cancel
Save