mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-03 00:31:25 -08:00
Merge remote-tracking branch 'origin/main'
# Conflicts: # app/user/forms.py
This commit is contained in:
commit
a60f2767a4
20 changed files with 203 additions and 66 deletions
|
@ -125,7 +125,17 @@ class AddUserForm(FlaskForm):
|
|||
verified = BooleanField(_l('Email address is verified'))
|
||||
banned = BooleanField(_l('Banned'))
|
||||
newsletter = BooleanField(_l('Subscribe to email newsletter'))
|
||||
ignore_bots = BooleanField(_l('Hide posts by bots'))
|
||||
hide_type_choices = [(0, _l('Show')),
|
||||
(1, _l('Hide completely')),
|
||||
(2, _l('Blur')),
|
||||
(3, _l('Make semi-transparent'))]
|
||||
ignore_bots = SelectField(_l('Hide posts by bots'), choices=hide_type_choices,
|
||||
default=0, coerce=int, render_kw={'class': 'form-select'})
|
||||
hide_nsfw = SelectField(_l('Show NSFW posts'), choices=hide_type_choices, default=1,
|
||||
coerce=int, render_kw={'class': 'form-select'})
|
||||
hide_nsfl = SelectField(_l('Show NSFL posts'), choices=hide_type_choices, default=1,
|
||||
coerce=int, render_kw={'class': 'form-select'})
|
||||
|
||||
nsfw = BooleanField(_l('Show NSFW posts'))
|
||||
nsfl = BooleanField(_l('Show NSFL posts'))
|
||||
role_options = [(2, _l('User')),
|
||||
|
@ -178,6 +188,14 @@ class EditUserForm(FlaskForm):
|
|||
bot = BooleanField(_l('This profile is a bot'))
|
||||
verified = BooleanField(_l('Email address is verified'))
|
||||
banned = BooleanField(_l('Banned'))
|
||||
hide_type_choices = [(0, _l('Show')),
|
||||
(1, _l('Hide completely')),
|
||||
(2, _l('Blur')),
|
||||
(3, _l('Make semi-transparent'))]
|
||||
hide_nsfw = SelectField(_l('Show NSFW posts'), choices=hide_type_choices, default=1,
|
||||
coerce=int, render_kw={'class': 'form-select'})
|
||||
hide_nsfl = SelectField(_l('Show NSFL posts'), choices=hide_type_choices, default=1,
|
||||
coerce=int, render_kw={'class': 'form-select'})
|
||||
role_options = [(2, _l('User')),
|
||||
(3, _l('Staff')),
|
||||
(4, _l('Admin')),
|
||||
|
|
|
@ -743,6 +743,8 @@ def admin_user_edit(user_id):
|
|||
if form.validate_on_submit():
|
||||
user.bot = form.bot.data
|
||||
user.banned = form.banned.data
|
||||
user.hide_nsfw = form.hide_nsfw.data
|
||||
user.hide_nsfl = form.hide_nsfl.data
|
||||
if form.verified.data and not user.verified:
|
||||
finalize_user_setup(user)
|
||||
user.verified = form.verified.data
|
||||
|
@ -774,6 +776,8 @@ def admin_user_edit(user_id):
|
|||
form.bot.data = user.bot
|
||||
form.verified.data = user.verified
|
||||
form.banned.data = user.banned
|
||||
form.hide_nsfw.data = user.hide_nsfw
|
||||
form.hide_nsfl.data = user.hide_nsfl
|
||||
if user.roles and user.roles.count() > 0:
|
||||
form.role.data = user.roles[0].id
|
||||
|
||||
|
@ -828,8 +832,8 @@ def admin_users_add():
|
|||
user.cover = file
|
||||
user.newsletter = form.newsletter.data
|
||||
user.ignore_bots = form.ignore_bots.data
|
||||
user.show_nsfw = form.nsfw.data
|
||||
user.show_nsfl = form.nsfl.data
|
||||
user.hide_nsfw = form.hide_nsfw.data
|
||||
user.hide_nsfl = form.hide_nsfl.data
|
||||
|
||||
user.instance_id = 1
|
||||
user.roles.append(Role.query.get(form.role.data))
|
||||
|
|
|
@ -330,11 +330,11 @@ def register(app):
|
|||
posts = Post.query.join(CommunityMember, Post.community_id == CommunityMember.community_id).filter(
|
||||
CommunityMember.is_banned == False)
|
||||
posts = posts.filter(CommunityMember.user_id == user.id)
|
||||
if user.ignore_bots:
|
||||
if user.ignore_bots == 1:
|
||||
posts = posts.filter(Post.from_bot == False)
|
||||
if user.show_nsfl is False:
|
||||
if user.hide_nsfl == 1:
|
||||
posts = posts.filter(Post.nsfl == False)
|
||||
if user.show_nsfw is False:
|
||||
if user.hide_nsfw == 1:
|
||||
posts = posts.filter(Post.nsfw == False)
|
||||
domains_ids = blocked_domains(user.id)
|
||||
if domains_ids:
|
||||
|
|
|
@ -201,11 +201,11 @@ def show_community(community: Community):
|
|||
posts = posts.filter(Post.from_bot == False, Post.nsfw == False, Post.nsfl == False, Post.deleted == False)
|
||||
content_filters = {}
|
||||
else:
|
||||
if current_user.ignore_bots:
|
||||
if current_user.ignore_bots == 1:
|
||||
posts = posts.filter(Post.from_bot == False)
|
||||
if current_user.show_nsfl is False:
|
||||
if current_user.hide_nsfl == 1:
|
||||
posts = posts.filter(Post.nsfl == False)
|
||||
if current_user.show_nsfw is False:
|
||||
if current_user.hide_nsfw == 1:
|
||||
posts = posts.filter(Post.nsfw == False)
|
||||
content_filters = user_filters_posts(current_user.id)
|
||||
posts = posts.filter(Post.deleted == False)
|
||||
|
|
|
@ -24,7 +24,7 @@ def show_domain(domain_id):
|
|||
if domain.banned:
|
||||
domain = None
|
||||
if domain:
|
||||
if current_user.is_anonymous or current_user.ignore_bots:
|
||||
if current_user.is_anonymous or current_user.ignore_bots == 1:
|
||||
posts = Post.query.join(Community, Community.id == Post.community_id).\
|
||||
filter(Post.from_bot == False, Post.domain_id == domain.id, Community.banned == False, Post.deleted == False).\
|
||||
order_by(desc(Post.posted_at))
|
||||
|
|
|
@ -97,11 +97,11 @@ def home_page(type, sort):
|
|||
posts = posts.join(Community, Community.id == Post.community_id)
|
||||
posts = posts.filter(Community.show_all == True, Post.deleted == False)
|
||||
|
||||
if current_user.ignore_bots:
|
||||
if current_user.ignore_bots == 1:
|
||||
posts = posts.filter(Post.from_bot == False)
|
||||
if current_user.show_nsfl is False:
|
||||
if current_user.hide_nsfl == 1:
|
||||
posts = posts.filter(Post.nsfl == False)
|
||||
if current_user.show_nsfw is False:
|
||||
if current_user.hide_nsfw == 1:
|
||||
posts = posts.filter(Post.nsfw == False)
|
||||
|
||||
domains_ids = blocked_domains(current_user.id)
|
||||
|
@ -211,9 +211,9 @@ def list_communities():
|
|||
banned_from = communities_banned_from(current_user.id)
|
||||
if banned_from:
|
||||
communities = communities.filter(Community.id.not_in(banned_from))
|
||||
if not current_user.show_nsfw:
|
||||
if current_user.hide_nsfw == 1:
|
||||
communities = communities.filter(Community.nsfw == False)
|
||||
if not current_user.show_nsfl:
|
||||
if current_user.hide_nsfl == 1:
|
||||
communities = communities.filter(Community.nsfl == False)
|
||||
else:
|
||||
communities = communities.filter(and_(Community.nsfw == False, Community.nsfl == False))
|
||||
|
@ -263,9 +263,9 @@ def list_local_communities():
|
|||
banned_from = communities_banned_from(current_user.id)
|
||||
if banned_from:
|
||||
communities = communities.filter(Community.id.not_in(banned_from))
|
||||
if not current_user.show_nsfw:
|
||||
if current_user.hide_nsfw == 1:
|
||||
communities = communities.filter(Community.nsfw == False)
|
||||
if not current_user.show_nsfl:
|
||||
if current_user.hide_nsfl == 1:
|
||||
communities = communities.filter(Community.nsfl == False)
|
||||
else:
|
||||
communities = communities.filter(and_(Community.nsfw == False, Community.nsfl == False))
|
||||
|
@ -440,11 +440,11 @@ def test():
|
|||
posts = Post.query.join(CommunityMember, Post.community_id == CommunityMember.community_id).filter(
|
||||
CommunityMember.is_banned == False)
|
||||
posts = posts.filter(CommunityMember.user_id == user.id)
|
||||
if user.ignore_bots:
|
||||
if user.ignore_bots == 1:
|
||||
posts = posts.filter(Post.from_bot == False)
|
||||
if user.show_nsfl is False:
|
||||
if user.hide_nsfl == 1:
|
||||
posts = posts.filter(Post.nsfl == False)
|
||||
if user.show_nsfw is False:
|
||||
if user.hide_nsfw == 1:
|
||||
posts = posts.filter(Post.nsfw == False)
|
||||
domains_ids = blocked_domains(user.id)
|
||||
if domains_ids:
|
||||
|
|
|
@ -585,8 +585,8 @@ class User(UserMixin, db.Model):
|
|||
about_html = db.Column(db.Text) # html
|
||||
keywords = db.Column(db.String(256))
|
||||
matrix_user_id = db.Column(db.String(256))
|
||||
show_nsfw = db.Column(db.Boolean, default=False)
|
||||
show_nsfl = db.Column(db.Boolean, default=False)
|
||||
hide_nsfw = db.Column(db.Integer, default=1)
|
||||
hide_nsfl = db.Column(db.Integer, default=1)
|
||||
created = db.Column(db.DateTime, default=utcnow)
|
||||
last_seen = db.Column(db.DateTime, default=utcnow, index=True)
|
||||
avatar_id = db.Column(db.Integer, db.ForeignKey('file.id'), index=True)
|
||||
|
@ -606,7 +606,7 @@ class User(UserMixin, db.Model):
|
|||
searchable = db.Column(db.Boolean, default=True)
|
||||
indexable = db.Column(db.Boolean, default=False)
|
||||
bot = db.Column(db.Boolean, default=False)
|
||||
ignore_bots = db.Column(db.Boolean, default=False)
|
||||
ignore_bots = db.Column(db.Integer, default=0)
|
||||
unread_notifications = db.Column(db.Integer, default=0)
|
||||
ip_address = db.Column(db.String(50))
|
||||
instance_id = db.Column(db.Integer, db.ForeignKey('instance.id'), index=True)
|
||||
|
|
|
@ -16,7 +16,7 @@ def post_replies(post_id: int, sort_by: str, show_first: int = 0) -> List[PostRe
|
|||
instance_ids = blocked_instances(current_user.id)
|
||||
if instance_ids:
|
||||
comments = comments.filter(or_(PostReply.instance_id.not_in(instance_ids), PostReply.instance_id == None))
|
||||
if current_user.ignore_bots:
|
||||
if current_user.ignore_bots == 1:
|
||||
comments = comments.filter(PostReply.from_bot == False)
|
||||
blocked_accounts = blocked_users(current_user.id)
|
||||
if blocked_accounts:
|
||||
|
|
|
@ -30,11 +30,11 @@ def run_search():
|
|||
|
||||
posts = Post.query.search(q)
|
||||
if current_user.is_authenticated:
|
||||
if current_user.ignore_bots:
|
||||
if current_user.ignore_bots == 1:
|
||||
posts = posts.filter(Post.from_bot == False)
|
||||
if current_user.show_nsfl is False:
|
||||
if current_user.hide_nsfl == 1:
|
||||
posts = posts.filter(Post.nsfl == False)
|
||||
if current_user.show_nsfw is False:
|
||||
if current_user.hide_nsfw == 1:
|
||||
posts = posts.filter(Post.nsfw == False)
|
||||
domains_ids = blocked_domains(current_user.id)
|
||||
if domains_ids:
|
||||
|
|
|
@ -26,7 +26,7 @@ def show_tag(tag):
|
|||
join(post_tag, post_tag.c.post_id == Post.id).filter(post_tag.c.tag_id == tag.id). \
|
||||
filter(Community.banned == False, Post.deleted == False)
|
||||
|
||||
if current_user.is_anonymous or current_user.ignore_bots:
|
||||
if current_user.is_anonymous or current_user.ignore_bots == 1:
|
||||
posts = posts.filter(Post.from_bot == False)
|
||||
|
||||
if current_user.is_authenticated:
|
||||
|
@ -75,7 +75,7 @@ def show_tag_rss(tag):
|
|||
join(post_tag, post_tag.c.post_id == Post.id).filter(post_tag.c.tag_id == tag.id). \
|
||||
filter(Community.banned == False, Post.deleted == False)
|
||||
|
||||
if current_user.is_anonymous or current_user.ignore_bots:
|
||||
if current_user.is_anonymous or current_user.ignore_bots == 1:
|
||||
posts = posts.filter(Post.from_bot == False)
|
||||
posts = posts.order_by(desc(Post.posted_at)).limit(100).all()
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
{{ render_field(form.verified) }}
|
||||
{{ render_field(form.banned) }}
|
||||
<p>receive newsletter: {{ user.newsletter }}</p>
|
||||
<p>view nsfw: {{ user.show_nsfw }}</p>
|
||||
<p>view nsfl: {{ user.show_nsfl }}</p>
|
||||
{{ render_field(form.hide_nsfw) }}
|
||||
{{ render_field(form.hide_nsfl) }}
|
||||
<p>searchable: {{ user.searchable }}</p>
|
||||
<p>indexable: {{ user.indexable }}</p>
|
||||
{{ render_field(form.role) }}
|
||||
|
@ -50,4 +50,4 @@
|
|||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -86,7 +86,11 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
{% for community in communities.items -%}
|
||||
<tr class="">
|
||||
{% set content_blocked = (current_user.hide_nsfw == 3 and community.nsfw)
|
||||
or (current_user.hide_nsfl == 3 and community.nsfl) -%}
|
||||
{% set blur_content = (current_user.hide_nsfw == 2 and community.nsfw)
|
||||
or (current_user.hide_nsfl == 2 and community.nsfl) -%}
|
||||
<tr class="{{ 'blocked' if content_blocked }}{{ 'blur' if blur_content }}">
|
||||
<td width="70">{% if current_user.is_authenticated -%}
|
||||
{% if community_membership(current_user, community) in [SUBSCRIPTION_MEMBER, SUBSCRIPTION_MODERATOR, SUBSCRIPTION_OWNER] -%}
|
||||
<a class="btn btn-primary btn-sm" href="/community/{{ community.link() }}/unsubscribe" rel="nofollow" aria-label="{{ _('Leave %(name)s', name=community.display_name()) }}">{{ _('Leave') }}</a>
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
{% set content_blocked = post.blocked_by_content_filter(content_filters) -%}
|
||||
{% set content_blocked = post.blocked_by_content_filter(content_filters)
|
||||
or (current_user.hide_nsfw == 3 and post.nsfw)
|
||||
or (current_user.hide_nsfl == 3 and post.nsfl)
|
||||
or (current_user.ignore_bots == 3 and post.from_bot) -%}
|
||||
{% set blur_content = (current_user.hide_nsfw == 2 and post.nsfw)
|
||||
or (current_user.hide_nsfl == 2 and post.nsfl)
|
||||
or (current_user.ignore_bots == 2 and post.from_bot) -%}
|
||||
{% if content_blocked and content_blocked == '-1' -%}
|
||||
{# do nothing - blocked by keyword filter #}
|
||||
{% else -%}
|
||||
<div class="post_teaser type_{{ post.type }}{{ ' reported' if post.reports > 0 and current_user.is_authenticated and post.community.is_moderator() }}{{ ' blocked' if content_blocked }}"
|
||||
<div class="post_teaser type_{{ post.type }}{{ ' reported' if post.reports > 0 and current_user.is_authenticated and post.community.is_moderator() }}{{ ' blocked' if content_blocked }}{{ ' blur' if blur_content }}"
|
||||
{% if content_blocked -%} title="{{ _('Filtered: ') }}{{ content_blocked }}"{% endif -%} tabindex="0">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
{# do not use any back ticks in the HTML produced by this template - javascript needs to load it as a string. See community.html #}
|
||||
{% set content_blocked = post.blocked_by_content_filter(content_filters) %}
|
||||
{% set content_blocked = post.blocked_by_content_filter(content_filters)
|
||||
or (current_user.hide_nsfw == 3 and post.nsfw)
|
||||
or (current_user.hide_nsfl == 3 and post.nsfl)
|
||||
or (current_user.ignore_bots == 3 and post.from_bot) -%}
|
||||
{% set blur_content = (current_user.hide_nsfw == 2 and post.nsfw)
|
||||
or (current_user.hide_nsfl == 2 and post.nsfl)
|
||||
or (current_user.ignore_bots == 2 and post.from_bot) -%}
|
||||
{% if content_blocked and content_blocked == '-1' %}
|
||||
{# do nothing - blocked by keyword filter #}
|
||||
{% else %}
|
||||
{% set post_title = post.title.replace('`', "'") %}
|
||||
<div class="item{{ ' reported' if post.reports > 0 and current_user.is_authenticated and post.community.is_moderator() }}{{ ' blocked' if content_blocked }}"
|
||||
<div class="item{{ ' reported' if post.reports > 0 and current_user.is_authenticated and post.community.is_moderator() }}{{ ' blocked' if content_blocked }}{{ ' blur' if blur_content }}"
|
||||
{% if content_blocked %} title="{{ _('Filtered: ') }}{{ content_blocked }}"{% endif %}>
|
||||
{% if post.image_id %}
|
||||
<div class="masonry_thumb" title="{{ post_title }}">
|
||||
|
|
|
@ -25,13 +25,6 @@
|
|||
{{ render_field(form.newsletter) }}
|
||||
{{ render_field(form.email_unread) }}
|
||||
<h5> Visibility </h5>
|
||||
{{ render_field(form.ignore_bots) }}
|
||||
{{ render_field(form.reply_collapse_threshold) }}
|
||||
<small class="field_hint">{{ _('Collapse replies with a score at or below this level - click to view.') }}</small>
|
||||
{{ render_field(form.reply_hide_threshold) }}
|
||||
<small class="field_hint">{{ _('Hide replies with a score at or below this level.') }}</small>
|
||||
{{ render_field(form.nsfw) }}
|
||||
{{ render_field(form.nsfl) }}
|
||||
{{ render_field(form.searchable) }}
|
||||
{{ render_field(form.indexable) }}
|
||||
<h5> Preferences </h5>
|
||||
|
|
|
@ -18,10 +18,24 @@
|
|||
</nav>
|
||||
<h1>{{ _('Filters') }}</h1>
|
||||
{% include "user/_user_nav.html" %}
|
||||
<form method='post' enctype="multipart/form-data" role="form">
|
||||
{{ form.csrf_token() }}
|
||||
<h5> Visibility </h5>
|
||||
{{ render_field(form.ignore_bots) }}
|
||||
{{ render_field(form.hide_nsfw) }}
|
||||
{{ render_field(form.hide_nsfl) }}
|
||||
{{ render_field(form.reply_collapse_threshold) }}
|
||||
<small class="field_hint">{{ _('Collapse replies with a score at or below this level - click to view.') }}</small>
|
||||
{{ render_field(form.reply_hide_threshold) }}
|
||||
<small class="field_hint">{{ _('Hide replies with a score at or below this level.') }}</small>
|
||||
{{ render_field(form.submit) }}
|
||||
</form>
|
||||
<hr />
|
||||
|
||||
<h5>Keyword Filters</h5>
|
||||
<div class="rh_action_buttons">
|
||||
<a class="btn btn-primary" href="{{ url_for('user.user_settings_filters_add') }}">{{ _('Add filter') }}</a>
|
||||
</div>
|
||||
|
||||
<p class="card-text">{{ _('Filters can hide posts that contain keywords you specify, either by making them less noticeable or invisible.') }}</p>
|
||||
{% if filters %}
|
||||
<table class="table table-striped" role="table">
|
||||
|
@ -48,6 +62,7 @@
|
|||
{% else %}
|
||||
<p>{{ _('No filters defined yet.') }}</p>
|
||||
{% endif %}
|
||||
|
||||
<h5>Blocks</h5>
|
||||
<p class="card-text">Manage what users, communities, domains or instances you want to block. Blocking them means you will no longer see any posts associated with them.</p>
|
||||
<nav id="block_chooser">
|
||||
|
@ -138,4 +153,4 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -57,11 +57,11 @@ def show_topic(topic_path):
|
|||
posts = posts.filter(Post.from_bot == False, Post.nsfw == False, Post.nsfl == False, Post.deleted == False)
|
||||
content_filters = {}
|
||||
else:
|
||||
if current_user.ignore_bots:
|
||||
if current_user.ignore_bots == 1:
|
||||
posts = posts.filter(Post.from_bot == False)
|
||||
if current_user.show_nsfl is False:
|
||||
if current_user.hide_nsfl == 1:
|
||||
posts = posts.filter(Post.nsfl == False)
|
||||
if current_user.show_nsfw is False:
|
||||
if current_user.hide_nsfw == 1:
|
||||
posts = posts.filter(Post.nsfw == False)
|
||||
posts = posts.filter(Post.deleted == False)
|
||||
content_filters = user_filters_posts(current_user.id)
|
||||
|
|
|
@ -89,7 +89,23 @@ class ReportUserForm(FlaskForm):
|
|||
return ', '.join(result)
|
||||
|
||||
|
||||
class FilterEditForm(FlaskForm):
|
||||
class FilterForm(FlaskForm):
|
||||
hide_type_choices = [(0, _l('Show')),
|
||||
(1, _l('Hide completely')),
|
||||
(2, _l('Blur')),
|
||||
(3, _l('Make semi-transparent'))]
|
||||
ignore_bots = SelectField(_l('Hide posts by bots'), choices=hide_type_choices,
|
||||
default=0, coerce=int, render_kw={'class': 'form-select'})
|
||||
hide_nsfw = SelectField(_l('Show NSFW posts'), choices=hide_type_choices,
|
||||
default=1, coerce=int, render_kw={'class': 'form-select'})
|
||||
hide_nsfl = SelectField(_l('Show NSFL posts'), choices=hide_type_choices,
|
||||
default=1, coerce=int, render_kw={'class': 'form-select'})
|
||||
reply_collapse_threshold = IntegerField(_l('Reply collapse threshold'))
|
||||
reply_hide_threshold = IntegerField(_l('Reply hide threshold'))
|
||||
submit = SubmitField(_l('Save settings'))
|
||||
|
||||
|
||||
class KeywordFilterEditForm(FlaskForm):
|
||||
title = StringField(_l('Name'), validators=[DataRequired(), Length(min=3, max=50)])
|
||||
filter_home = BooleanField(_l('Home feed'), default=True)
|
||||
filter_posts = BooleanField(_l('Posts in communities'))
|
||||
|
|
|
@ -17,8 +17,8 @@ from app.models import Post, Community, CommunityMember, User, PostReply, PostVo
|
|||
Instance, Report, UserBlock, CommunityBan, CommunityJoinRequest, CommunityBlock, Filter, Domain, DomainBlock, \
|
||||
InstanceBlock, NotificationSubscription, PostBookmark, PostReplyBookmark
|
||||
from app.user import bp
|
||||
from app.user.forms import ProfileForm, SettingsForm, DeleteAccountForm, ReportUserForm, FilterEditForm, \
|
||||
RemoteFollowForm
|
||||
from app.user.forms import ProfileForm, SettingsForm, DeleteAccountForm, ReportUserForm, \
|
||||
FilterForm, KeywordFilterEditForm, RemoteFollowForm
|
||||
from app.user.utils import purge_user_then_delete, unsubscribe_from_community
|
||||
from app.utils import get_setting, render_template, markdown_to_html, user_access, markdown_to_text, shorten_string, \
|
||||
is_image_url, ensure_directory_exists, gibberish, file_get_contents, community_membership, user_filters_home, \
|
||||
|
@ -228,9 +228,6 @@ def change_settings():
|
|||
if form.validate_on_submit():
|
||||
propagate_indexable = form.indexable.data != current_user.indexable
|
||||
current_user.newsletter = form.newsletter.data
|
||||
current_user.ignore_bots = form.ignore_bots.data
|
||||
current_user.show_nsfw = form.nsfw.data
|
||||
current_user.show_nsfl = form.nsfl.data
|
||||
current_user.searchable = form.searchable.data
|
||||
current_user.indexable = form.indexable.data
|
||||
current_user.default_sort = form.default_sort.data
|
||||
|
@ -238,8 +235,6 @@ def change_settings():
|
|||
current_user.email_unread = form.email_unread.data
|
||||
current_user.markdown_editor = form.markdown_editor.data
|
||||
current_user.interface_language = form.interface_language.data
|
||||
current_user.reply_collapse_threshold = form.reply_collapse_threshold.data
|
||||
current_user.reply_hide_threshold = form.reply_hide_threshold.data
|
||||
session['ui_language'] = form.interface_language.data
|
||||
import_file = request.files['import_file']
|
||||
if propagate_indexable:
|
||||
|
@ -270,17 +265,12 @@ def change_settings():
|
|||
elif request.method == 'GET':
|
||||
form.newsletter.data = current_user.newsletter
|
||||
form.email_unread.data = current_user.email_unread
|
||||
form.ignore_bots.data = current_user.ignore_bots
|
||||
form.nsfw.data = current_user.show_nsfw
|
||||
form.nsfl.data = current_user.show_nsfl
|
||||
form.searchable.data = current_user.searchable
|
||||
form.indexable.data = current_user.indexable
|
||||
form.default_sort.data = current_user.default_sort
|
||||
form.theme.data = current_user.theme
|
||||
form.markdown_editor.data = current_user.markdown_editor
|
||||
form.interface_language.data = current_user.interface_language
|
||||
form.reply_collapse_threshold.data = current_user.reply_collapse_threshold
|
||||
form.reply_hide_threshold.data = current_user.reply_hide_threshold
|
||||
|
||||
return render_template('user/edit_settings.html', title=_('Edit profile'), form=form, user=current_user,
|
||||
moderating_communities=moderating_communities(current_user.get_id()),
|
||||
|
@ -751,9 +741,26 @@ def import_settings_task(user_id, filename):
|
|||
db.session.commit()
|
||||
|
||||
|
||||
@bp.route('/user/settings/filters', methods=['GET'])
|
||||
@bp.route('/user/settings/filters', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def user_settings_filters():
|
||||
form = FilterForm()
|
||||
if form.validate_on_submit():
|
||||
current_user.ignore_bots = form.ignore_bots.data
|
||||
current_user.hide_nsfw = form.hide_nsfw.data
|
||||
current_user.hide_nsfl = form.hide_nsfl.data
|
||||
current_user.reply_collapse_threshold = form.reply_collapse_threshold.data
|
||||
current_user.reply_hide_threshold = form.reply_hide_threshold.data
|
||||
db.session.commit()
|
||||
|
||||
flash(_('Your changes have been saved.'), 'success')
|
||||
return redirect(url_for('user.user_settings_filters'))
|
||||
elif request.method == 'GET':
|
||||
form.ignore_bots.data = current_user.ignore_bots
|
||||
form.hide_nsfw.data = current_user.hide_nsfw
|
||||
form.hide_nsfl.data = current_user.hide_nsfl
|
||||
form.reply_collapse_threshold.data = current_user.reply_collapse_threshold
|
||||
form.reply_hide_threshold.data = current_user.reply_hide_threshold
|
||||
filters = Filter.query.filter_by(user_id=current_user.id).order_by(Filter.title).all()
|
||||
blocked_users = User.query.filter_by(deleted=False).join(UserBlock, UserBlock.blocked_id == User.id).\
|
||||
filter(UserBlock.blocker_id == current_user.id).order_by(User.user_name).all()
|
||||
|
@ -763,7 +770,7 @@ def user_settings_filters():
|
|||
filter(DomainBlock.user_id == current_user.id).order_by(Domain.name).all()
|
||||
blocked_instances = Instance.query.join(InstanceBlock, InstanceBlock.instance_id == Instance.id).\
|
||||
filter(InstanceBlock.user_id == current_user.id).order_by(Instance.domain).all()
|
||||
return render_template('user/filters.html', filters=filters, user=current_user,
|
||||
return render_template('user/filters.html', form=form, filters=filters, user=current_user,
|
||||
blocked_users=blocked_users, blocked_communities=blocked_communities,
|
||||
blocked_domains=blocked_domains, blocked_instances=blocked_instances,
|
||||
moderating_communities=moderating_communities(current_user.get_id()),
|
||||
|
@ -775,7 +782,7 @@ def user_settings_filters():
|
|||
@bp.route('/user/settings/filters/add', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def user_settings_filters_add():
|
||||
form = FilterEditForm()
|
||||
form = KeywordFilterEditForm()
|
||||
form.filter_replies.render_kw = {'disabled': True}
|
||||
if form.validate_on_submit():
|
||||
content_filter = Filter(title=form.title.data, filter_home=form.filter_home.data, filter_posts=form.filter_posts.data,
|
||||
|
@ -804,7 +811,7 @@ def user_settings_filters_edit(filter_id):
|
|||
content_filter = Filter.query.get_or_404(filter_id)
|
||||
if current_user.id != content_filter.user_id:
|
||||
abort(401)
|
||||
form = FilterEditForm()
|
||||
form = KeywordFilterEditForm()
|
||||
form.filter_replies.render_kw = {'disabled': True}
|
||||
if form.validate_on_submit():
|
||||
content_filter.title = form.title.data
|
||||
|
|
68
migrations/versions/5bee0ac7d99f_filter_options.py
Normal file
68
migrations/versions/5bee0ac7d99f_filter_options.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
"""filter options
|
||||
|
||||
Revision ID: 5bee0ac7d99f
|
||||
Revises: 363f2f07ff30
|
||||
Create Date: 2024-06-28 13:48:47.692409
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '5bee0ac7d99f'
|
||||
down_revision = '363f2f07ff30'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('user', schema=None) as batch_op:
|
||||
batch_op.execute('UPDATE "user" SET show_nsfw = NOT show_nsfw')
|
||||
batch_op.alter_column('show_nsfw', new_column_name='hide_nsfw')
|
||||
batch_op.alter_column('hide_nsfw',
|
||||
existing_type=sa.BOOLEAN(),
|
||||
type_=sa.Integer(),
|
||||
existing_nullable=True,
|
||||
postgresql_using='hide_nsfw::integer')
|
||||
batch_op.execute('UPDATE "user" SET show_nsfl = NOT show_nsfl')
|
||||
batch_op.alter_column('show_nsfl', new_column_name='hide_nsfl')
|
||||
batch_op.alter_column('hide_nsfl',
|
||||
existing_type=sa.BOOLEAN(),
|
||||
type_=sa.Integer(),
|
||||
existing_nullable=True,
|
||||
postgresql_using='hide_nsfl::integer')
|
||||
batch_op.alter_column('ignore_bots',
|
||||
existing_type=sa.BOOLEAN(),
|
||||
type_=sa.Integer(),
|
||||
existing_nullable=True,
|
||||
postgresql_using='ignore_bots::integer')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('user', schema=None) as batch_op:
|
||||
batch_op.alter_column('ignore_bots',
|
||||
existing_type=sa.Integer(),
|
||||
type_=sa.BOOLEAN(),
|
||||
existing_nullable=True,
|
||||
postgresql_using='ignore_bots::boolean')
|
||||
batch_op.execute('UPDATE "user" SET hide_nsfl = CASE WHEN hide_nsfl = 1 THEN 0 ELSE 1 END')
|
||||
batch_op.alter_column('hide_nsfl', new_column_name='show_nsfl')
|
||||
batch_op.alter_column('show_nsfl',
|
||||
existing_type=sa.Integer(),
|
||||
type_=sa.BOOLEAN(),
|
||||
existing_nullable=True,
|
||||
postgresql_using='show_nsfl::boolean')
|
||||
batch_op.execute('UPDATE "user" SET hide_nsfw = CASE WHEN hide_nsfw = 1 THEN 0 ELSE 1 END')
|
||||
batch_op.alter_column('hide_nsfw', new_column_name='show_nsfw')
|
||||
batch_op.alter_column('show_nsfw',
|
||||
existing_type=sa.Integer(),
|
||||
type_=sa.BOOLEAN(),
|
||||
existing_nullable=True,
|
||||
postgresql_using='show_nsfw::boolean')
|
||||
|
||||
# ### end Alembic commands ###
|
Loading…
Add table
Reference in a new issue