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

Filters

+ + + + + + + + + + + {% for filter in filters %} + + + + + + + {% endfor %} + +
PhraseFilter contexts
{{ filter.phrase }} + {% for context in filter.context %} + {{ context }} + {% endfor %} + Edit filterDelete filter
+ +

+ + Create filter + +

+ +{% endblock %} diff --git a/brutaldon/templates/setup/settings.html b/brutaldon/templates/setup/settings.html index 9449d2c..9a364f3 100644 --- a/brutaldon/templates/setup/settings.html +++ b/brutaldon/templates/setup/settings.html @@ -109,5 +109,10 @@ value="Save" class="button is-primary" > +

Filters and Lists

+
+

List filters

+
+ {% endblock %} diff --git a/brutaldon/urls.py b/brutaldon/urls.py index 56a975f..f241ec4 100644 --- a/brutaldon/urls.py +++ b/brutaldon/urls.py @@ -60,5 +60,7 @@ urlpatterns = [ path('search', views.search, name='search'), path('search_results', views.search_results, name='search_results'), 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('', views.home, name=''), ] diff --git a/brutaldon/views.py b/brutaldon/views.py index 6b4de25..900b381 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -6,7 +6,7 @@ from django.views.decorators.cache import never_cache, cache_page from django.urls import reverse from django.core.files.uploadhandler import TemporaryFileUploadHandler from django.utils.translation import gettext as _ -from brutaldon.forms import LoginForm, OAuthLoginForm, PreferencesForm, PostForm +from brutaldon.forms import LoginForm, OAuthLoginForm, PreferencesForm, PostForm, FilterForm from brutaldon.models import Client, Account, Preference, Theme from mastodon import Mastodon, AttribAccessDict, MastodonError, MastodonAPIError from urllib import parse @@ -956,3 +956,54 @@ def emoji_reference(request): "emojos": sorted(emojos, key=lambda x: x['shortcode']), "notifications": notifications, 'own_acct' : request.session['user']}) + + +@br_login_required +def list_filters(request): + try: + account, mastodon = get_usercontext(request) + except NotLoggedInException: + return redirect(about) + filters = mastodon.filters() + return render(request, 'filters/list.html', + {'account': account, + 'preferences': account.preferences, + 'filters': filters }) + +@br_login_required +def create_filter(request): + try: + account, mastodon = get_usercontext(request) + except NotLoggedInException: + return redirect(about) + if request.method == 'POST': + form = FilterForm(request.POST) + if form.is_valid(): + contexts = [] + if form.cleaned_data['context_home']: + contexts += 'home' + if form.cleaned_data['context_public']: + contexts += 'public' + if form.cleaned_data['context_notes']: + contexts += 'notifications' + if form.cleaned_data['context_thread']: + contexts += 'thread' + expires = form.cleaned_data['expires_in'] + if expires == "": + expires = None + mastodon.filter_create(form.cleaned_data['phrase'], + contexts, + whole_word=form.cleaned_data['whole_word'], + expires_in=expires) + return redirect(list_filters) + else: + return render(request, 'filters/create.html', + { 'form': form, + 'account': account, + 'preferences': account.preferences}) + else: + form = FilterForm() + return render(request, 'filters/create.html', + { 'form': form, + 'account': account, + 'preferences': account.preferences})