From 93fbba1d1eff140d956676aca0951b79c645f1a1 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Fri, 28 Jun 2024 15:04:06 +0000 Subject: [PATCH] rename show_ filters into hide_ and migrate db for filter changes --- app/admin/forms.py | 8 +-- app/admin/routes.py | 12 ++-- app/cli.py | 4 +- app/community/routes.py | 4 +- app/main/routes.py | 16 ++--- app/models.py | 4 +- app/search/routes.py | 4 +- app/templates/admin/edit_user.html | 4 +- app/templates/user/filters.html | 6 +- app/topic/routes.py | 4 +- app/user/forms.py | 4 +- app/user/routes.py | 8 +-- .../versions/5bee0ac7d99f_filter_options.py | 68 +++++++++++++++++++ 13 files changed, 107 insertions(+), 39 deletions(-) create mode 100644 migrations/versions/5bee0ac7d99f_filter_options.py diff --git a/app/admin/forms.py b/app/admin/forms.py index 8a08f153..5c67e68d 100644 --- a/app/admin/forms.py +++ b/app/admin/forms.py @@ -131,9 +131,9 @@ class AddUserForm(FlaskForm): (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'}) - show_nsfw = SelectField(_l('Show NSFW posts'), choices=hide_type_choices, default=1, + hide_nsfw = SelectField(_l('Show NSFW posts'), choices=hide_type_choices, default=1, coerce=int, render_kw={'class': 'form-select'}) - show_nsfl = SelectField(_l('Show NSFL posts'), choices=hide_type_choices, default=1, + 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')) @@ -192,9 +192,9 @@ class EditUserForm(FlaskForm): (1, _l('Hide completely')), (2, _l('Blur')), (3, _l('Make semi-transparent'))] - show_nsfw = SelectField(_l('Show NSFW posts'), choices=hide_type_choices, default=1, + hide_nsfw = SelectField(_l('Show NSFW posts'), choices=hide_type_choices, default=1, coerce=int, render_kw={'class': 'form-select'}) - show_nsfl = SelectField(_l('Show NSFL posts'), choices=hide_type_choices, default=1, + 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')), diff --git a/app/admin/routes.py b/app/admin/routes.py index ccfb54ac..e88a4f3f 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -743,8 +743,8 @@ def admin_user_edit(user_id): if form.validate_on_submit(): user.bot = form.bot.data user.banned = form.banned.data - user.show_nsfw = form.show_nsfw.data - user.show_nsfl = form.show_nsfl.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 @@ -776,8 +776,8 @@ def admin_user_edit(user_id): form.bot.data = user.bot form.verified.data = user.verified form.banned.data = user.banned - form.show_nsfw.data = user.show_nsfw - form.show_nsfl.data = user.show_nsfl + 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 @@ -832,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.show_nsfw.data - user.show_nsfl = form.show_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)) diff --git a/app/cli.py b/app/cli.py index 6d610f9c..1006e6ea 100644 --- a/app/cli.py +++ b/app/cli.py @@ -332,9 +332,9 @@ def register(app): posts = posts.filter(CommunityMember.user_id == user.id) if user.ignore_bots == 1: posts = posts.filter(Post.from_bot == False) - if user.show_nsfl == 1: + if user.hide_nsfl == 1: posts = posts.filter(Post.nsfl == False) - if user.show_nsfw == 1: + if user.hide_nsfw == 1: posts = posts.filter(Post.nsfw == False) domains_ids = blocked_domains(user.id) if domains_ids: diff --git a/app/community/routes.py b/app/community/routes.py index 1d51014c..750347a3 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -203,9 +203,9 @@ def show_community(community: Community): else: if current_user.ignore_bots == 1: posts = posts.filter(Post.from_bot == False) - if current_user.show_nsfl == 1: + if current_user.hide_nsfl == 1: posts = posts.filter(Post.nsfl == False) - if current_user.show_nsfw == 1: + 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) diff --git a/app/main/routes.py b/app/main/routes.py index 070ceb47..a5287fc2 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -99,9 +99,9 @@ def home_page(type, sort): if current_user.ignore_bots == 1: posts = posts.filter(Post.from_bot == False) - if current_user.show_nsfl == 1: + if current_user.hide_nsfl == 1: posts = posts.filter(Post.nsfl == False) - if current_user.show_nsfw == 1: + 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 current_user.show_nsfw == 1: + if current_user.hide_nsfw == 1: communities = communities.filter(Community.nsfw == False) - if current_user.show_nsfl == 1: + 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 current_user.show_nsfw == 1: + if current_user.hide_nsfw == 1: communities = communities.filter(Community.nsfw == False) - if current_user.show_nsfl == 1: + if current_user.hide_nsfl == 1: communities = communities.filter(Community.nsfl == False) else: communities = communities.filter(and_(Community.nsfw == False, Community.nsfl == False)) @@ -442,9 +442,9 @@ def test(): posts = posts.filter(CommunityMember.user_id == user.id) if user.ignore_bots == 1: posts = posts.filter(Post.from_bot == False) - if user.show_nsfl == 1: + if user.hide_nsfl == 1: posts = posts.filter(Post.nsfl == False) - if user.show_nsfw == 1: + if user.hide_nsfw == 1: posts = posts.filter(Post.nsfw == False) domains_ids = blocked_domains(user.id) if domains_ids: diff --git a/app/models.py b/app/models.py index 6032d4ea..5fc77836 100644 --- a/app/models.py +++ b/app/models.py @@ -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.Integer, default=1) - show_nsfl = db.Column(db.Integer, default=1) + 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) diff --git a/app/search/routes.py b/app/search/routes.py index 23f27e30..7010f37e 100644 --- a/app/search/routes.py +++ b/app/search/routes.py @@ -32,9 +32,9 @@ def run_search(): if current_user.is_authenticated: if current_user.ignore_bots == 1: posts = posts.filter(Post.from_bot == False) - if current_user.show_nsfl == 1: + if current_user.hide_nsfl == 1: posts = posts.filter(Post.nsfl == False) - if current_user.show_nsfw == 1: + if current_user.hide_nsfw == 1: posts = posts.filter(Post.nsfw == False) domains_ids = blocked_domains(current_user.id) if domains_ids: diff --git a/app/templates/admin/edit_user.html b/app/templates/admin/edit_user.html index e276c43f..1e01e49b 100644 --- a/app/templates/admin/edit_user.html +++ b/app/templates/admin/edit_user.html @@ -27,8 +27,8 @@ {{ render_field(form.verified) }} {{ render_field(form.banned) }}

receive newsletter: {{ user.newsletter }}

- {{ render_field(form.show_nsfw) }} - {{ render_field(form.show_nsfl) }} + {{ render_field(form.hide_nsfw) }} + {{ render_field(form.hide_nsfl) }}

searchable: {{ user.searchable }}

indexable: {{ user.indexable }}

{{ render_field(form.role) }} diff --git a/app/templates/user/filters.html b/app/templates/user/filters.html index cb4ae52f..ca881b01 100644 --- a/app/templates/user/filters.html +++ b/app/templates/user/filters.html @@ -22,8 +22,8 @@ {{ form.csrf_token() }}
Visibility
{{ render_field(form.ignore_bots) }} - {{ render_field(form.show_nsfw) }} - {{ render_field(form.show_nsfl) }} + {{ render_field(form.hide_nsfw) }} + {{ render_field(form.hide_nsfl) }} {{ render_field(form.submit) }}
@@ -149,4 +149,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/topic/routes.py b/app/topic/routes.py index 91430832..5bd2ab51 100644 --- a/app/topic/routes.py +++ b/app/topic/routes.py @@ -59,9 +59,9 @@ def show_topic(topic_path): else: if current_user.ignore_bots == 1: posts = posts.filter(Post.from_bot == False) - if current_user.show_nsfl == 1: + if current_user.hide_nsfl == 1: posts = posts.filter(Post.nsfl == False) - if current_user.show_nsfw == 1: + 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) diff --git a/app/user/forms.py b/app/user/forms.py index c7448b58..69fc7ed7 100644 --- a/app/user/forms.py +++ b/app/user/forms.py @@ -93,9 +93,9 @@ class FilterForm(FlaskForm): (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'}) - show_nsfw = SelectField(_l('Show NSFW posts'), choices=hide_type_choices, + hide_nsfw = SelectField(_l('Show NSFW posts'), choices=hide_type_choices, default=1, coerce=int, render_kw={'class': 'form-select'}) - show_nsfl = SelectField(_l('Show NSFL posts'), choices=hide_type_choices, + hide_nsfl = SelectField(_l('Show NSFL posts'), choices=hide_type_choices, default=1, coerce=int, render_kw={'class': 'form-select'}) submit = SubmitField(_l('Save settings')) diff --git a/app/user/routes.py b/app/user/routes.py index b2f738ae..1d866e29 100644 --- a/app/user/routes.py +++ b/app/user/routes.py @@ -751,16 +751,16 @@ 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 + current_user.hide_nsfw = form.hide_nsfw.data + current_user.hide_nsfl = form.hide_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 + form.hide_nsfw.data = current_user.hide_nsfw + form.hide_nsfl.data = current_user.hide_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() diff --git a/migrations/versions/5bee0ac7d99f_filter_options.py b/migrations/versions/5bee0ac7d99f_filter_options.py new file mode 100644 index 00000000..6d9b4901 --- /dev/null +++ b/migrations/versions/5bee0ac7d99f_filter_options.py @@ -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 ###