mirror of https://gitlab.com/brutaldon/brutaldon
List filters, create filters
Template still needs to be created for create filters, will need to update for list filters when views to edit and delete exist
This commit is contained in:
parent
6bbd211678
commit
dfccfab05b
|
@ -0,0 +1,38 @@
|
|||
{% extends "base.html" %}
|
||||
{% load widget_tweaks %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<h1 class="title">Filters</h1>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Phrase</th>
|
||||
<th>Filter contexts</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for filter in filters %}
|
||||
<tr>
|
||||
<td>{{ filter.phrase }}</td>
|
||||
<td>
|
||||
{% for context in filter.context %}
|
||||
{{ context }}
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td>Edit filter</td>
|
||||
<td>Delete filter</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p>
|
||||
<a class="button is-primary" href="{% url "create_filter" %}">
|
||||
Create filter
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -109,5 +109,10 @@
|
|||
value="Save" class="button is-primary" >
|
||||
</div>
|
||||
</form>
|
||||
<h2 class="subtitle">Filters and Lists</h2>
|
||||
<div class="section">
|
||||
<p><a href="{% url "list_filters" %}">List filters</a></p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -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=''),
|
||||
]
|
||||
|
|
|
@ -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})
|
||||
|
|
Loading…
Reference in New Issue