diff --git a/app/templates/user/edit_settings.html b/app/templates/user/edit_settings.html
index 2ae7dad2..ee077220 100644
--- a/app/templates/user/edit_settings.html
+++ b/app/templates/user/edit_settings.html
@@ -25,13 +25,10 @@
{{ render_field(form.newsletter) }}
{{ render_field(form.email_unread) }}
Visibility
- {{ render_field(form.ignore_bots) }}
{{ render_field(form.reply_collapse_threshold) }}
{{ _('Collapse replies with a score at or below this level - click to view.') }}
{{ render_field(form.reply_hide_threshold) }}
{{ _('Hide replies with a score at or below this level.') }}
- {{ render_field(form.nsfw) }}
- {{ render_field(form.nsfl) }}
{{ render_field(form.searchable) }}
{{ render_field(form.indexable) }}
Preferences
diff --git a/app/templates/user/filters.html b/app/templates/user/filters.html
index cb37eaab..cb4ae52f 100644
--- a/app/templates/user/filters.html
+++ b/app/templates/user/filters.html
@@ -18,10 +18,20 @@
{{ _('Filters') }}
{% include "user/_user_nav.html" %}
+
+
+
+ Keyword Filters
-
{{ _('Filters can hide posts that contain keywords you specify, either by making them less noticeable or invisible.') }}
{% if filters %}
@@ -48,6 +58,7 @@
{% else %}
{{ _('No filters defined yet.') }}
{% endif %}
+
Blocks
Manage what users, communities, domains or instances you want to block. Blocking them means you will no longer see any posts associated with them.
diff --git a/app/user/forms.py b/app/user/forms.py
index 76df4941..0d1db99b 100644
--- a/app/user/forms.py
+++ b/app/user/forms.py
@@ -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'))
diff --git a/app/user/routes.py b/app/user/routes.py
index 4eb92f6d..b2f738ae 100644
--- a/app/user/routes.py
+++ b/app/user/routes.py
@@ -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