diff --git a/brutaldon/templates/filters/edit.html b/brutaldon/templates/filters/edit.html new file mode 100644 index 0000000..1af053b --- /dev/null +++ b/brutaldon/templates/filters/edit.html @@ -0,0 +1,79 @@ +{% extends "base.html" %} +{% load widget_tweaks %} + +{% block content %} + +
+

Edit Filter

+ +
+ {% csrf_token %} + +
+ {{ form.non_field_errors }} +
+ +
+ +
+ {% render_field form.phrase class+="input" %} +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ +
+ +
+
+ {% render_field form.expires_in class+="select" %} + + + +
+
+
+ +
+ +
+ +
+
+ + +{% endblock %} diff --git a/brutaldon/templates/filters/list.html b/brutaldon/templates/filters/list.html index ef328ec..0539a17 100644 --- a/brutaldon/templates/filters/list.html +++ b/brutaldon/templates/filters/list.html @@ -23,7 +23,12 @@ {{ context }} {% endfor %} - Edit filter + + + + Edit filter + + ', views.delete_filter, name='delete_filter'), + path('filters/edit/', views.edit_filter, name='edit_filter'), path('', views.home, name=''), ] diff --git a/brutaldon/views.py b/brutaldon/views.py index 01a2935..7fd8c02 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -975,10 +975,7 @@ def list_filters(request): @br_login_required def create_filter(request): - try: - account, mastodon = get_usercontext(request) - except NotLoggedInException: - return redirect(about) + account, mastodon = get_usercontext(request) if request.method == 'POST': form = FilterForm(request.POST) if form.is_valid(): @@ -1028,3 +1025,48 @@ def delete_filter(request, id): "own_acct": request.session["user"], "confirm_page": True, "preferences": account.preferences}) + +@br_login_required +def edit_filter(request, id): + account, mastodon = get_usercontext(request) + filter = mastodon.filter(id) + + contexts = [] + if request.method == 'POST': + form = FilterForm(request.POST) + if form.is_valid(): + if form.cleaned_data['context_home']: + contexts.append('home') + if form.cleaned_data['context_public']: + contexts.append('public') + if form.cleaned_data['context_notes']: + contexts.append('notifications') + if form.cleaned_data['context_thread']: + contexts.append('thread') + expires = form.cleaned_data['expires_in'] + if expires == "": + expires = None + mastodon.filter_update(id, form.cleaned_data['phrase'], + contexts, + whole_word=form.cleaned_data['whole_word'], + expires_in=expires) + return redirect(list_filters) + else: + return render(request, 'filters/edit.html', + { 'form': form, + 'account': account, + 'filter': filter, + 'preferences': account.preferences}) + else: + contexts = [] + form = FilterForm({'phrase': filter.phrase, + 'context_home': "home" in filter.context, + 'context_public': "public" in filter.context, + 'context_notes': "notifications" in filter.context, + 'context_thread': "thread" in filter.context, + 'whole_word': filter.whole_word}) + return render(request, 'filters/edit.html', + { 'form': form, + 'account': account, + 'filter': filter, + 'preferences': account.preferences})