Add filter deletion

This commit is contained in:
Jason McBrayer 2019-02-15 17:10:26 -05:00
parent 221f03957e
commit 3bfbc30255
5 changed files with 73 additions and 9 deletions

View File

@ -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"),

View File

@ -0,0 +1,31 @@
{% extends "base.html" %}
{% load widget_tweaks %}
{% block content %}
<h1 class="title">Delete that filter?</h1>
<div class="container">
<p class="label">Phrase: {{ filter.phrase }}</p>
<p class="label">Context: {{ filter.context|join:", " }}</p>
<p class="label">Whole word? {{ filter.whole_word }}</p>
</div>
<div class="container">
<form method="POST" action="{% url "delete_filter" filter.id %}">
{% csrf_token %}
<div class="level is-mobile">
<div class="level-left">
<div class="level-item">
<input class="button" type="submit" name="cancel" value="Cancel">
</div>
</div>
<div class="level-right">
<div class="level-item">
<input class="button is-primary" type="submit" name="delete"
value="Delete">
</div>
</div>
</div>
</form>
</div>
{% endblock %}

View File

@ -12,10 +12,11 @@
<th>Filter contexts</th>
<th></th>
<th></th>
<th></th>
</thead>
<tbody>
{% for filter in filters %}
<tr>
<tr id="filter-{{ filter.id }}">
<td>{{ filter.phrase }}</td>
<td>
{% for context in filter.context %}
@ -23,7 +24,21 @@
{% endfor %}
</td>
<td>Edit filter</td>
<td>Delete filter</td>
<td>
<a href="{% url "delete_filter" filter.id %}"
ic-delete-from="{% url "delete_filter" filter.id %}",
ic-indicator="#filter-spinner-{{ filter.id }}"
ic-confirm="Really delete that filter?"
ic-success-action="fadeOut;remove"
ic-action-target="#filter-{{ filter.id }}">
<span class="fa fa-times"></span>
Delete filter
</td>
<td>
<i id="filter-spinner-{{filter.id}}"
class="fa fa-spinner fa-spin"
style="display:none"></i>
</td>
</tr>
{% endfor %}
</tbody>

View File

@ -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/<id>', views.delete_filter, name='delete_filter'),
path('', views.home, name=''),
]

View File

@ -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})