rename show_ filters into hide_ and migrate db for filter changes

This commit is contained in:
Hendrik Langer 2024-06-28 15:04:06 +00:00
parent a7fa609ddf
commit 93fbba1d1e
13 changed files with 107 additions and 39 deletions

View file

@ -131,9 +131,9 @@ class AddUserForm(FlaskForm):
(3, _l('Make semi-transparent'))] (3, _l('Make semi-transparent'))]
ignore_bots = SelectField(_l('Hide posts by bots'), choices=hide_type_choices, ignore_bots = SelectField(_l('Hide posts by bots'), choices=hide_type_choices,
default=0, coerce=int, render_kw={'class': 'form-select'}) 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'}) 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'}) coerce=int, render_kw={'class': 'form-select'})
nsfw = BooleanField(_l('Show NSFW posts')) nsfw = BooleanField(_l('Show NSFW posts'))
@ -192,9 +192,9 @@ class EditUserForm(FlaskForm):
(1, _l('Hide completely')), (1, _l('Hide completely')),
(2, _l('Blur')), (2, _l('Blur')),
(3, _l('Make semi-transparent'))] (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'}) 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'}) coerce=int, render_kw={'class': 'form-select'})
role_options = [(2, _l('User')), role_options = [(2, _l('User')),
(3, _l('Staff')), (3, _l('Staff')),

View file

@ -743,8 +743,8 @@ def admin_user_edit(user_id):
if form.validate_on_submit(): if form.validate_on_submit():
user.bot = form.bot.data user.bot = form.bot.data
user.banned = form.banned.data user.banned = form.banned.data
user.show_nsfw = form.show_nsfw.data user.hide_nsfw = form.hide_nsfw.data
user.show_nsfl = form.show_nsfl.data user.hide_nsfl = form.hide_nsfl.data
if form.verified.data and not user.verified: if form.verified.data and not user.verified:
finalize_user_setup(user) finalize_user_setup(user)
user.verified = form.verified.data user.verified = form.verified.data
@ -776,8 +776,8 @@ def admin_user_edit(user_id):
form.bot.data = user.bot form.bot.data = user.bot
form.verified.data = user.verified form.verified.data = user.verified
form.banned.data = user.banned form.banned.data = user.banned
form.show_nsfw.data = user.show_nsfw form.hide_nsfw.data = user.hide_nsfw
form.show_nsfl.data = user.show_nsfl form.hide_nsfl.data = user.hide_nsfl
if user.roles and user.roles.count() > 0: if user.roles and user.roles.count() > 0:
form.role.data = user.roles[0].id form.role.data = user.roles[0].id
@ -832,8 +832,8 @@ def admin_users_add():
user.cover = file user.cover = file
user.newsletter = form.newsletter.data user.newsletter = form.newsletter.data
user.ignore_bots = form.ignore_bots.data user.ignore_bots = form.ignore_bots.data
user.show_nsfw = form.show_nsfw.data user.hide_nsfw = form.hide_nsfw.data
user.show_nsfl = form.show_nsfl.data user.hide_nsfl = form.hide_nsfl.data
user.instance_id = 1 user.instance_id = 1
user.roles.append(Role.query.get(form.role.data)) user.roles.append(Role.query.get(form.role.data))

View file

@ -332,9 +332,9 @@ def register(app):
posts = posts.filter(CommunityMember.user_id == user.id) posts = posts.filter(CommunityMember.user_id == user.id)
if user.ignore_bots == 1: if user.ignore_bots == 1:
posts = posts.filter(Post.from_bot == False) posts = posts.filter(Post.from_bot == False)
if user.show_nsfl == 1: if user.hide_nsfl == 1:
posts = posts.filter(Post.nsfl == False) posts = posts.filter(Post.nsfl == False)
if user.show_nsfw == 1: if user.hide_nsfw == 1:
posts = posts.filter(Post.nsfw == False) posts = posts.filter(Post.nsfw == False)
domains_ids = blocked_domains(user.id) domains_ids = blocked_domains(user.id)
if domains_ids: if domains_ids:

View file

@ -203,9 +203,9 @@ def show_community(community: Community):
else: else:
if current_user.ignore_bots == 1: if current_user.ignore_bots == 1:
posts = posts.filter(Post.from_bot == False) 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) 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.nsfw == False)
content_filters = user_filters_posts(current_user.id) content_filters = user_filters_posts(current_user.id)
posts = posts.filter(Post.deleted == False) posts = posts.filter(Post.deleted == False)

View file

@ -99,9 +99,9 @@ def home_page(type, sort):
if current_user.ignore_bots == 1: if current_user.ignore_bots == 1:
posts = posts.filter(Post.from_bot == False) 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) 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.nsfw == False)
domains_ids = blocked_domains(current_user.id) domains_ids = blocked_domains(current_user.id)
@ -211,9 +211,9 @@ def list_communities():
banned_from = communities_banned_from(current_user.id) banned_from = communities_banned_from(current_user.id)
if banned_from: if banned_from:
communities = communities.filter(Community.id.not_in(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) communities = communities.filter(Community.nsfw == False)
if current_user.show_nsfl == 1: if current_user.hide_nsfl == 1:
communities = communities.filter(Community.nsfl == False) communities = communities.filter(Community.nsfl == False)
else: else:
communities = communities.filter(and_(Community.nsfw == False, Community.nsfl == False)) 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) banned_from = communities_banned_from(current_user.id)
if banned_from: if banned_from:
communities = communities.filter(Community.id.not_in(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) communities = communities.filter(Community.nsfw == False)
if current_user.show_nsfl == 1: if current_user.hide_nsfl == 1:
communities = communities.filter(Community.nsfl == False) communities = communities.filter(Community.nsfl == False)
else: else:
communities = communities.filter(and_(Community.nsfw == False, Community.nsfl == False)) communities = communities.filter(and_(Community.nsfw == False, Community.nsfl == False))
@ -442,9 +442,9 @@ def test():
posts = posts.filter(CommunityMember.user_id == user.id) posts = posts.filter(CommunityMember.user_id == user.id)
if user.ignore_bots == 1: if user.ignore_bots == 1:
posts = posts.filter(Post.from_bot == False) posts = posts.filter(Post.from_bot == False)
if user.show_nsfl == 1: if user.hide_nsfl == 1:
posts = posts.filter(Post.nsfl == False) posts = posts.filter(Post.nsfl == False)
if user.show_nsfw == 1: if user.hide_nsfw == 1:
posts = posts.filter(Post.nsfw == False) posts = posts.filter(Post.nsfw == False)
domains_ids = blocked_domains(user.id) domains_ids = blocked_domains(user.id)
if domains_ids: if domains_ids:

View file

@ -585,8 +585,8 @@ class User(UserMixin, db.Model):
about_html = db.Column(db.Text) # html about_html = db.Column(db.Text) # html
keywords = db.Column(db.String(256)) keywords = db.Column(db.String(256))
matrix_user_id = db.Column(db.String(256)) matrix_user_id = db.Column(db.String(256))
show_nsfw = db.Column(db.Integer, default=1) hide_nsfw = db.Column(db.Integer, default=1)
show_nsfl = db.Column(db.Integer, default=1) hide_nsfl = db.Column(db.Integer, default=1)
created = db.Column(db.DateTime, default=utcnow) created = db.Column(db.DateTime, default=utcnow)
last_seen = db.Column(db.DateTime, default=utcnow, index=True) last_seen = db.Column(db.DateTime, default=utcnow, index=True)
avatar_id = db.Column(db.Integer, db.ForeignKey('file.id'), index=True) avatar_id = db.Column(db.Integer, db.ForeignKey('file.id'), index=True)

View file

@ -32,9 +32,9 @@ def run_search():
if current_user.is_authenticated: if current_user.is_authenticated:
if current_user.ignore_bots == 1: if current_user.ignore_bots == 1:
posts = posts.filter(Post.from_bot == False) 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) 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.nsfw == False)
domains_ids = blocked_domains(current_user.id) domains_ids = blocked_domains(current_user.id)
if domains_ids: if domains_ids:

View file

@ -27,8 +27,8 @@
{{ render_field(form.verified) }} {{ render_field(form.verified) }}
{{ render_field(form.banned) }} {{ render_field(form.banned) }}
<p>receive newsletter: {{ user.newsletter }}</p> <p>receive newsletter: {{ user.newsletter }}</p>
{{ render_field(form.show_nsfw) }} {{ render_field(form.hide_nsfw) }}
{{ render_field(form.show_nsfl) }} {{ render_field(form.hide_nsfl) }}
<p>searchable: {{ user.searchable }}</p> <p>searchable: {{ user.searchable }}</p>
<p>indexable: {{ user.indexable }}</p> <p>indexable: {{ user.indexable }}</p>
{{ render_field(form.role) }} {{ render_field(form.role) }}

View file

@ -22,8 +22,8 @@
{{ form.csrf_token() }} {{ form.csrf_token() }}
<h5> Visibility </h5> <h5> Visibility </h5>
{{ render_field(form.ignore_bots) }} {{ render_field(form.ignore_bots) }}
{{ render_field(form.show_nsfw) }} {{ render_field(form.hide_nsfw) }}
{{ render_field(form.show_nsfl) }} {{ render_field(form.hide_nsfl) }}
{{ render_field(form.submit) }} {{ render_field(form.submit) }}
</form> </form>
<hr /> <hr />
@ -149,4 +149,4 @@
</div> </div>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}

View file

@ -59,9 +59,9 @@ def show_topic(topic_path):
else: else:
if current_user.ignore_bots == 1: if current_user.ignore_bots == 1:
posts = posts.filter(Post.from_bot == False) 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) 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.nsfw == False)
posts = posts.filter(Post.deleted == False) posts = posts.filter(Post.deleted == False)
content_filters = user_filters_posts(current_user.id) content_filters = user_filters_posts(current_user.id)

View file

@ -93,9 +93,9 @@ class FilterForm(FlaskForm):
(3, _l('Make semi-transparent'))] (3, _l('Make semi-transparent'))]
ignore_bots = SelectField(_l('Hide posts by bots'), choices=hide_type_choices, ignore_bots = SelectField(_l('Hide posts by bots'), choices=hide_type_choices,
default=0, coerce=int, render_kw={'class': 'form-select'}) 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'}) 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'}) default=1, coerce=int, render_kw={'class': 'form-select'})
submit = SubmitField(_l('Save settings')) submit = SubmitField(_l('Save settings'))

View file

@ -751,16 +751,16 @@ def user_settings_filters():
form = FilterForm() form = FilterForm()
if form.validate_on_submit(): if form.validate_on_submit():
current_user.ignore_bots = form.ignore_bots.data current_user.ignore_bots = form.ignore_bots.data
current_user.show_nsfw = form.show_nsfw.data current_user.hide_nsfw = form.hide_nsfw.data
current_user.show_nsfl = form.show_nsfl.data current_user.hide_nsfl = form.hide_nsfl.data
db.session.commit() db.session.commit()
flash(_('Your changes have been saved.'), 'success') flash(_('Your changes have been saved.'), 'success')
return redirect(url_for('user.user_settings_filters')) return redirect(url_for('user.user_settings_filters'))
elif request.method == 'GET': elif request.method == 'GET':
form.ignore_bots.data = current_user.ignore_bots form.ignore_bots.data = current_user.ignore_bots
form.show_nsfw.data = current_user.show_nsfw form.hide_nsfw.data = current_user.hide_nsfw
form.show_nsfl.data = current_user.show_nsfl form.hide_nsfl.data = current_user.hide_nsfl
filters = Filter.query.filter_by(user_id=current_user.id).order_by(Filter.title).all() 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).\ 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() filter(UserBlock.blocker_id == current_user.id).order_by(User.user_name).all()

View 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 ###