From 3bfbc3025584c4b88bda446a1ff321b9d8102d09 Mon Sep 17 00:00:00 2001 From: Jason McBrayer Date: Fri, 15 Feb 2019 17:10:26 -0500 Subject: [PATCH] Add filter deletion --- brutaldon/forms.py | 10 ++++---- brutaldon/templates/filters/delete.html | 31 +++++++++++++++++++++++++ brutaldon/templates/filters/list.html | 19 +++++++++++++-- brutaldon/urls.py | 1 + brutaldon/views.py | 21 +++++++++++++++-- 5 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 brutaldon/templates/filters/delete.html diff --git a/brutaldon/forms.py b/brutaldon/forms.py index 2d9536f..f280853 100644 --- a/brutaldon/forms.py +++ b/brutaldon/forms.py @@ -57,11 +57,11 @@ class PostForm(forms.Form): class FilterForm(forms.Form): phrase = forms.CharField(label=_("Word or phrase to filter")) - context_home = forms.BooleanField(label=_("In home timeline"), required=False) - context_public = forms.BooleanField(label=_("In public timelines"), required=False) - context_notes = forms.BooleanField(label=_("In notifications"), required=False) - context_thread = forms.BooleanField(label=_("In thread contexts"), required=False) - whole_word = forms.BooleanField(label=_("Whole words only"), required=False) + context_home = forms.BooleanField(label=_("In home timeline"), required=False, initial=True) + context_public = forms.BooleanField(label=_("In public timelines"), required=False, initial=True) + context_notes = forms.BooleanField(label=_("In notifications"), required=False, initial=True) + context_thread = forms.BooleanField(label=_("In thread contexts"), required=False, initial=True) + whole_word = forms.BooleanField(label=_("Whole words only"), required=False, initial=True) expires_in = forms.TypedChoiceField(label=_("Expires in"), choices=(("", "Never"), ("1800", "30 minutes"), diff --git a/brutaldon/templates/filters/delete.html b/brutaldon/templates/filters/delete.html new file mode 100644 index 0000000..8f2b060 --- /dev/null +++ b/brutaldon/templates/filters/delete.html @@ -0,0 +1,31 @@ +{% extends "base.html" %} +{% load widget_tweaks %} + +{% block content %} +

Delete that filter?

+ +
+

Phrase: {{ filter.phrase }}

+

Context: {{ filter.context|join:", " }}

+

Whole word? {{ filter.whole_word }}

+
+ +
+
+ {% csrf_token %} +
+
+
+ +
+
+
+
+ +
+
+
+
+
+{% endblock %} diff --git a/brutaldon/templates/filters/list.html b/brutaldon/templates/filters/list.html index a1d8ae9..ef328ec 100644 --- a/brutaldon/templates/filters/list.html +++ b/brutaldon/templates/filters/list.html @@ -12,10 +12,11 @@ Filter contexts + {% for filter in filters %} - + {{ filter.phrase }} {% for context in filter.context %} @@ -23,7 +24,21 @@ {% endfor %} Edit filter - Delete filter + + + + Delete filter + + + + {% endfor %} diff --git a/brutaldon/urls.py b/brutaldon/urls.py index f241ec4..285bda2 100644 --- a/brutaldon/urls.py +++ b/brutaldon/urls.py @@ -62,5 +62,6 @@ urlpatterns = [ path('emoji', views.emoji_reference, name='emoji'), path('filters/list', views.list_filters, name='list_filters'), path('filters/create', views.create_filter, name='create_filter'), + path('filters/delete/', views.delete_filter, name='delete_filter'), path('', views.home, name=''), ] diff --git a/brutaldon/views.py b/brutaldon/views.py index 5d7a67a..334edb1 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -786,7 +786,7 @@ def delete(request, id): return redirect('home') if not request.POST.get('cancel', None): mastodon.status_delete(id) - if request.POST.get('ic-request') or request.DELETE.get('ic-request'): + if request.POST.get('ic-request'): return HttpResponse("") return redirect(home) else: @@ -989,7 +989,6 @@ def create_filter(request): expires = form.cleaned_data['expires_in'] if expires == "": expires = None - set_trace() mastodon.filter_create(form.cleaned_data['phrase'], contexts, whole_word=form.cleaned_data['whole_word'], @@ -1006,3 +1005,21 @@ def create_filter(request): { 'form': form, 'account': account, 'preferences': account.preferences}) + +@br_login_required +def delete_filter(request, id): + account, mastodon = get_usercontext(request) + filter = mastodon.filter(id) + + if request.method == 'POST' or request.method == 'DELETE': + if not request.POST.get('cancel', None): + mastodon.filter_delete(filter.id) + if request.POST.get("ic-request"): + return HttpResponse("") + return redirect(list_filters) + else: + return render(request, "filters/delete.html", + {"filter": filter, + "own_acct": request.session["user"], + "confirm_page": True, + "preferences": account.preferences})