mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
add blur and transparent options to the nsfw, nsfw and bots filter
This commit is contained in:
parent
ac12c60538
commit
a7fa609ddf
13 changed files with 67 additions and 41 deletions
|
@ -125,7 +125,17 @@ class AddUserForm(FlaskForm):
|
||||||
verified = BooleanField(_l('Email address is verified'))
|
verified = BooleanField(_l('Email address is verified'))
|
||||||
banned = BooleanField(_l('Banned'))
|
banned = BooleanField(_l('Banned'))
|
||||||
newsletter = BooleanField(_l('Subscribe to email newsletter'))
|
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'})
|
||||||
|
show_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,
|
||||||
|
coerce=int, render_kw={'class': 'form-select'})
|
||||||
|
|
||||||
nsfw = BooleanField(_l('Show NSFW posts'))
|
nsfw = BooleanField(_l('Show NSFW posts'))
|
||||||
nsfl = BooleanField(_l('Show NSFL posts'))
|
nsfl = BooleanField(_l('Show NSFL posts'))
|
||||||
role_options = [(2, _l('User')),
|
role_options = [(2, _l('User')),
|
||||||
|
@ -178,6 +188,14 @@ class EditUserForm(FlaskForm):
|
||||||
bot = BooleanField(_l('This profile is a bot'))
|
bot = BooleanField(_l('This profile is a bot'))
|
||||||
verified = BooleanField(_l('Email address is verified'))
|
verified = BooleanField(_l('Email address is verified'))
|
||||||
banned = BooleanField(_l('Banned'))
|
banned = BooleanField(_l('Banned'))
|
||||||
|
hide_type_choices = [(0, _l('Show')),
|
||||||
|
(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,
|
||||||
|
coerce=int, render_kw={'class': 'form-select'})
|
||||||
|
show_nsfl = SelectField(_l('Show NSFL posts'), choices=hide_type_choices, default=1,
|
||||||
|
coerce=int, render_kw={'class': 'form-select'})
|
||||||
role_options = [(2, _l('User')),
|
role_options = [(2, _l('User')),
|
||||||
(3, _l('Staff')),
|
(3, _l('Staff')),
|
||||||
(4, _l('Admin')),
|
(4, _l('Admin')),
|
||||||
|
|
|
@ -743,6 +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.show_nsfl = form.show_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
|
||||||
|
@ -774,6 +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.show_nsfl.data = user.show_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
|
||||||
|
|
||||||
|
@ -828,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.nsfw.data
|
user.show_nsfw = form.show_nsfw.data
|
||||||
user.show_nsfl = form.nsfl.data
|
user.show_nsfl = form.show_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))
|
||||||
|
|
|
@ -330,11 +330,11 @@ def register(app):
|
||||||
posts = Post.query.join(CommunityMember, Post.community_id == CommunityMember.community_id).filter(
|
posts = Post.query.join(CommunityMember, Post.community_id == CommunityMember.community_id).filter(
|
||||||
CommunityMember.is_banned == False)
|
CommunityMember.is_banned == False)
|
||||||
posts = posts.filter(CommunityMember.user_id == user.id)
|
posts = posts.filter(CommunityMember.user_id == user.id)
|
||||||
if user.ignore_bots:
|
if user.ignore_bots == 1:
|
||||||
posts = posts.filter(Post.from_bot == False)
|
posts = posts.filter(Post.from_bot == False)
|
||||||
if user.show_nsfl is False:
|
if user.show_nsfl == 1:
|
||||||
posts = posts.filter(Post.nsfl == False)
|
posts = posts.filter(Post.nsfl == False)
|
||||||
if user.show_nsfw is False:
|
if user.show_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:
|
||||||
|
|
|
@ -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)
|
posts = posts.filter(Post.from_bot == False, Post.nsfw == False, Post.nsfl == False, Post.deleted == False)
|
||||||
content_filters = {}
|
content_filters = {}
|
||||||
else:
|
else:
|
||||||
if current_user.ignore_bots:
|
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 is False:
|
if current_user.show_nsfl == 1:
|
||||||
posts = posts.filter(Post.nsfl == False)
|
posts = posts.filter(Post.nsfl == False)
|
||||||
if current_user.show_nsfw is False:
|
if current_user.show_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)
|
||||||
|
|
|
@ -24,7 +24,7 @@ def show_domain(domain_id):
|
||||||
if domain.banned:
|
if domain.banned:
|
||||||
domain = None
|
domain = None
|
||||||
if domain:
|
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).\
|
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).\
|
filter(Post.from_bot == False, Post.domain_id == domain.id, Community.banned == False, Post.deleted == False).\
|
||||||
order_by(desc(Post.posted_at))
|
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.join(Community, Community.id == Post.community_id)
|
||||||
posts = posts.filter(Community.show_all == True, Post.deleted == False)
|
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)
|
posts = posts.filter(Post.from_bot == False)
|
||||||
if current_user.show_nsfl is False:
|
if current_user.show_nsfl == 1:
|
||||||
posts = posts.filter(Post.nsfl == False)
|
posts = posts.filter(Post.nsfl == False)
|
||||||
if current_user.show_nsfw is False:
|
if current_user.show_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 not current_user.show_nsfw:
|
if current_user.show_nsfw == 1:
|
||||||
communities = communities.filter(Community.nsfw == False)
|
communities = communities.filter(Community.nsfw == False)
|
||||||
if not current_user.show_nsfl:
|
if current_user.show_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 not current_user.show_nsfw:
|
if current_user.show_nsfw == 1:
|
||||||
communities = communities.filter(Community.nsfw == False)
|
communities = communities.filter(Community.nsfw == False)
|
||||||
if not current_user.show_nsfl:
|
if current_user.show_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))
|
||||||
|
@ -440,11 +440,11 @@ def test():
|
||||||
posts = Post.query.join(CommunityMember, Post.community_id == CommunityMember.community_id).filter(
|
posts = Post.query.join(CommunityMember, Post.community_id == CommunityMember.community_id).filter(
|
||||||
CommunityMember.is_banned == False)
|
CommunityMember.is_banned == False)
|
||||||
posts = posts.filter(CommunityMember.user_id == user.id)
|
posts = posts.filter(CommunityMember.user_id == user.id)
|
||||||
if user.ignore_bots:
|
if user.ignore_bots == 1:
|
||||||
posts = posts.filter(Post.from_bot == False)
|
posts = posts.filter(Post.from_bot == False)
|
||||||
if user.show_nsfl is False:
|
if user.show_nsfl == 1:
|
||||||
posts = posts.filter(Post.nsfl == False)
|
posts = posts.filter(Post.nsfl == False)
|
||||||
if user.show_nsfw is False:
|
if user.show_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:
|
||||||
|
|
|
@ -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.Boolean, default=False)
|
show_nsfw = db.Column(db.Integer, default=1)
|
||||||
show_nsfl = db.Column(db.Boolean, default=False)
|
show_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)
|
||||||
|
@ -606,7 +606,7 @@ class User(UserMixin, db.Model):
|
||||||
searchable = db.Column(db.Boolean, default=True)
|
searchable = db.Column(db.Boolean, default=True)
|
||||||
indexable = db.Column(db.Boolean, default=False)
|
indexable = db.Column(db.Boolean, default=False)
|
||||||
bot = 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)
|
unread_notifications = db.Column(db.Integer, default=0)
|
||||||
ip_address = db.Column(db.String(50))
|
ip_address = db.Column(db.String(50))
|
||||||
instance_id = db.Column(db.Integer, db.ForeignKey('instance.id'), index=True)
|
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)
|
instance_ids = blocked_instances(current_user.id)
|
||||||
if instance_ids:
|
if instance_ids:
|
||||||
comments = comments.filter(or_(PostReply.instance_id.not_in(instance_ids), PostReply.instance_id == None))
|
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)
|
comments = comments.filter(PostReply.from_bot == False)
|
||||||
blocked_accounts = blocked_users(current_user.id)
|
blocked_accounts = blocked_users(current_user.id)
|
||||||
if blocked_accounts:
|
if blocked_accounts:
|
||||||
|
|
|
@ -30,11 +30,11 @@ def run_search():
|
||||||
|
|
||||||
posts = Post.query.search(q)
|
posts = Post.query.search(q)
|
||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
if current_user.ignore_bots:
|
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 is False:
|
if current_user.show_nsfl == 1:
|
||||||
posts = posts.filter(Post.nsfl == False)
|
posts = posts.filter(Post.nsfl == False)
|
||||||
if current_user.show_nsfw is False:
|
if current_user.show_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:
|
||||||
|
|
|
@ -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). \
|
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)
|
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.filter(Post.from_bot == False)
|
||||||
|
|
||||||
if current_user.is_authenticated:
|
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). \
|
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)
|
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.filter(Post.from_bot == False)
|
||||||
posts = posts.order_by(desc(Post.posted_at)).limit(100).all()
|
posts = posts.order_by(desc(Post.posted_at)).limit(100).all()
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
<p>view nsfw: {{ user.show_nsfw }}</p>
|
{{ render_field(form.show_nsfw) }}
|
||||||
<p>view nsfl: {{ user.show_nsfl }}</p>
|
{{ render_field(form.show_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) }}
|
||||||
|
|
|
@ -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)
|
posts = posts.filter(Post.from_bot == False, Post.nsfw == False, Post.nsfl == False, Post.deleted == False)
|
||||||
content_filters = {}
|
content_filters = {}
|
||||||
else:
|
else:
|
||||||
if current_user.ignore_bots:
|
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 is False:
|
if current_user.show_nsfl == 1:
|
||||||
posts = posts.filter(Post.nsfl == False)
|
posts = posts.filter(Post.nsfl == False)
|
||||||
if current_user.show_nsfw is False:
|
if current_user.show_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)
|
||||||
|
|
|
@ -35,9 +35,6 @@ class SettingsForm(FlaskForm):
|
||||||
interface_language = SelectField(_l('Interface language'), coerce=str, validators=[Optional()], render_kw={'class': 'form-select'})
|
interface_language = SelectField(_l('Interface language'), coerce=str, validators=[Optional()], render_kw={'class': 'form-select'})
|
||||||
newsletter = BooleanField(_l('Subscribe to email newsletter'))
|
newsletter = BooleanField(_l('Subscribe to email newsletter'))
|
||||||
email_unread = BooleanField(_l('Receive email about missed notifications'))
|
email_unread = BooleanField(_l('Receive email about missed notifications'))
|
||||||
ignore_bots = BooleanField(_l('Hide posts by bots'))
|
|
||||||
nsfw = BooleanField(_l('Show NSFW posts'))
|
|
||||||
nsfl = BooleanField(_l('Show NSFL posts'))
|
|
||||||
reply_collapse_threshold = IntegerField(_l('Reply collapse threshold'))
|
reply_collapse_threshold = IntegerField(_l('Reply collapse threshold'))
|
||||||
reply_hide_threshold = IntegerField(_l('Reply hide threshold'))
|
reply_hide_threshold = IntegerField(_l('Reply hide threshold'))
|
||||||
markdown_editor = BooleanField(_l('Use markdown editor GUI when writing'))
|
markdown_editor = BooleanField(_l('Use markdown editor GUI when writing'))
|
||||||
|
@ -90,9 +87,16 @@ class ReportUserForm(FlaskForm):
|
||||||
|
|
||||||
|
|
||||||
class FilterForm(FlaskForm):
|
class FilterForm(FlaskForm):
|
||||||
ignore_bots = BooleanField(_l('Hide posts by bots'))
|
hide_type_choices = [(0, _l('Show')),
|
||||||
show_nsfw = BooleanField(_l('Show NSFW posts'))
|
(1, _l('Hide completely')),
|
||||||
show_nsfl = BooleanField(_l('Show NSFL posts'))
|
(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'})
|
||||||
|
show_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, coerce=int, render_kw={'class': 'form-select'})
|
||||||
submit = SubmitField(_l('Save settings'))
|
submit = SubmitField(_l('Save settings'))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue