move user visibility filters into filter settings

This commit is contained in:
Hendrik Langer 2024-06-28 10:45:19 +02:00
parent b621a9072f
commit ac12c60538
4 changed files with 39 additions and 17 deletions

View file

@ -25,13 +25,10 @@
{{ 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>

View file

@ -18,10 +18,20 @@
</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.show_nsfw) }}
{{ render_field(form.show_nsfl) }}
{{ 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 +58,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">

View file

@ -89,7 +89,14 @@ class ReportUserForm(FlaskForm):
return ', '.join(result)
class FilterEditForm(FlaskForm):
class FilterForm(FlaskForm):
ignore_bots = BooleanField(_l('Hide posts by bots'))
show_nsfw = BooleanField(_l('Show NSFW posts'))
show_nsfl = BooleanField(_l('Show NSFL posts'))
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'))

View file

@ -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
@ -270,9 +267,6 @@ 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
@ -751,9 +745,22 @@ 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.show_nsfw = form.show_nsfw.data
current_user.show_nsfl = form.show_nsfl.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.show_nsfw.data = current_user.show_nsfw
form.show_nsfl.data = current_user.show_nsfl
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