Add options to filter replies and boosts out of timelines

This commit is contained in:
Jason McBrayer 2018-08-17 14:50:37 -04:00
parent 72912c1e58
commit 66861e7abd
3 changed files with 30 additions and 0 deletions

View File

@ -25,6 +25,16 @@ class SettingsForm(forms.Form):
help_text= help_text=
"""FULLBRUTALISM mode strips away most of the niceties of modern web design when """FULLBRUTALISM mode strips away most of the niceties of modern web design when
brutaldon is viewed in a graphical browser. It has no effect in text-only browsers.""") brutaldon is viewed in a graphical browser. It has no effect in text-only browsers.""")
filter_replies = forms.BooleanField(label="Filter replies from home timeline?",
required=False,
help_text=
"""Should replies be filtered out of your home timeline, giving you only pure,
top-level posts?""")
filter_boosts = forms.BooleanField(label="Filter boosts from home timeline?",
required=False,
help_text=
"""Should replies be filtered out of your home timeline, giving you only pure,
Original Content?""")
class PostForm(forms.Form): class PostForm(forms.Form):

View File

@ -11,6 +11,18 @@
{{ form.fullbrutalism.label }} {{ form.fullbrutalism.label }}
</label> </label>
</div> </div>
<div class="field">
<label class="label checkbox">
{% render_field form.filter_replies %}
{{ form.filter_replies.label }}
</label>
</div>
<div class="field">
<label class="label checkbox">
{% render_field form.filter_boosts %}
{{ form.filter_boosts.label }}
</label>
</div>
<div class="field"> <div class="field">
<input type="submit" name="submit" <input type="submit" name="submit"
value="Save" class="button is-primary" > value="Save" class="button is-primary" >

View File

@ -87,6 +87,12 @@ def timeline(request, timeline='home', timeline_name='Home', max_id=None, since_
next = data[-1]._pagination_next next = data[-1]._pagination_next
except (IndexError, AttributeError): except (IndexError, AttributeError):
next = None next = None
# This filtering has to be done *after* getting next/prev links
if request.session.get('filter_replies', False):
data = [x for x in data if not x.in_reply_to_id]
if request.session.get('filter_boosts', False):
data = [x for x in data if not x.reblog]
return render(request, 'main/%s_timeline.html' % timeline, return render(request, 'main/%s_timeline.html' % timeline,
{'toots': data, 'form': form, 'timeline': timeline, {'toots': data, 'form': form, 'timeline': timeline,
'timeline_name': timeline_name, 'timeline_name': timeline_name,
@ -313,6 +319,8 @@ def settings(request):
form = SettingsForm(request.POST) form = SettingsForm(request.POST)
if form.is_valid(): if form.is_valid():
request.session['fullbrutalism'] = form.cleaned_data['fullbrutalism'] request.session['fullbrutalism'] = form.cleaned_data['fullbrutalism']
request.session['filter_replies'] = form.cleaned_data['filter_replies']
request.session['filter_boosts'] = form.cleaned_data['filter_boosts']
return redirect(home) return redirect(home)
else: else:
return render(request, 'setup/settings.html', return render(request, 'setup/settings.html',