2018-08-22 15:21:09 +02:00
|
|
|
from django.http import HttpResponse, Http404, HttpResponseRedirect
|
2018-08-16 19:10:45 +02:00
|
|
|
from django.conf import settings as django_settings
|
2018-04-24 00:16:22 +02:00
|
|
|
from django.shortcuts import render, redirect
|
2018-08-22 15:21:09 +02:00
|
|
|
from django.urls import reverse
|
2018-08-10 02:58:05 +02:00
|
|
|
from django.views.decorators.cache import never_cache, cache_page
|
2018-05-14 21:35:10 +02:00
|
|
|
from django.urls import reverse
|
2018-05-18 15:22:27 +02:00
|
|
|
from django.core.files.uploadhandler import TemporaryFileUploadHandler
|
2018-08-28 18:22:20 +02:00
|
|
|
from brutaldon.forms import LoginForm, OAuthLoginForm, PreferencesForm, PostForm
|
|
|
|
from brutaldon.models import Client, Account, Preference, Theme
|
2018-09-05 01:19:35 +02:00
|
|
|
from mastodon import Mastodon, AttribAccessDict, MastodonError, MastodonAPIError
|
2018-04-24 20:49:43 +02:00
|
|
|
from urllib import parse
|
2018-06-09 19:49:04 +02:00
|
|
|
from pdb import set_trace
|
2018-08-29 16:50:54 +02:00
|
|
|
from bs4 import BeautifulSoup
|
2018-08-31 21:55:05 +02:00
|
|
|
from time import sleep
|
2018-04-24 00:16:22 +02:00
|
|
|
|
2018-04-26 02:51:12 +02:00
|
|
|
class NotLoggedInException(Exception):
|
|
|
|
pass
|
|
|
|
|
2018-08-28 18:22:20 +02:00
|
|
|
def get_usercontext(request):
|
|
|
|
if is_logged_in(request):
|
2018-05-14 21:35:10 +02:00
|
|
|
try:
|
|
|
|
client = Client.objects.get(api_base_id=request.session['instance'])
|
|
|
|
user = Account.objects.get(username=request.session['username'])
|
|
|
|
except (Client.DoesNotExist, Client.MultipleObjectsReturned,
|
|
|
|
Account.DoesNotExist, Account.MultipleObjectsReturned):
|
|
|
|
raise NotLoggedInException()
|
2018-08-28 18:22:20 +02:00
|
|
|
mastodon = Mastodon(
|
|
|
|
client_id = client.client_id,
|
|
|
|
client_secret = client.client_secret,
|
|
|
|
access_token = user.access_token,
|
|
|
|
api_base_url = client.api_base_id,
|
|
|
|
ratelimit_method="throw")
|
|
|
|
return user, mastodon
|
|
|
|
else:
|
|
|
|
return None, None
|
2018-04-26 05:07:58 +02:00
|
|
|
|
2018-08-22 15:21:09 +02:00
|
|
|
def is_logged_in(request):
|
2018-08-28 18:22:20 +02:00
|
|
|
return request.session.has_key('user')
|
2018-08-22 15:21:09 +02:00
|
|
|
|
|
|
|
def br_login_required(function=None, home_url=None, redirect_field_name=None):
|
|
|
|
"""Check that the user is logged in to a Mastodon instance.
|
|
|
|
|
|
|
|
This decorator ensures that the view functions it is called on can be
|
|
|
|
accessed only by logged in users. When an instanceless user accesses
|
|
|
|
such a protected view, they are redirected to the address specified in
|
|
|
|
the field named in `next_field` or, lacking such a value, the URL in
|
|
|
|
`home_url`, or the `ANONYMOUS_HOME_URL` setting.
|
|
|
|
"""
|
|
|
|
if home_url is None:
|
|
|
|
home_url = django_settings.ANONYMOUS_HOME_URL
|
|
|
|
|
|
|
|
def _dec(view_func):
|
|
|
|
def _view(request, *args, **kwargs):
|
|
|
|
if not is_logged_in(request):
|
|
|
|
url = None
|
|
|
|
if redirect_field_name and redirect_field_name in request.REQUEST:
|
|
|
|
url = request.REQUEST[redirect_field_name]
|
|
|
|
if not url:
|
|
|
|
url = home_url
|
|
|
|
if not url:
|
|
|
|
url = "/"
|
|
|
|
return HttpResponseRedirect(url)
|
|
|
|
else:
|
|
|
|
return view_func(request, *args, **kwargs)
|
|
|
|
|
|
|
|
_view.__name__ = view_func.__name__
|
|
|
|
_view.__dict__ = view_func.__dict__
|
|
|
|
_view.__doc__ = view_func.__doc__
|
|
|
|
|
|
|
|
return _view
|
|
|
|
|
|
|
|
if function is None:
|
|
|
|
return _dec
|
|
|
|
else:
|
|
|
|
return _dec(function)
|
|
|
|
|
2018-05-18 15:22:27 +02:00
|
|
|
def timeline(request, timeline='home', timeline_name='Home', max_id=None, since_id=None):
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-05-18 15:22:27 +02:00
|
|
|
data = mastodon.timeline(timeline, limit=100, max_id=max_id, since_id=since_id)
|
2018-05-22 14:57:45 +02:00
|
|
|
form = PostForm(initial={'visibility': request.session['user'].source.privacy})
|
2018-05-18 15:22:27 +02:00
|
|
|
try:
|
|
|
|
prev = data[0]._pagination_prev
|
|
|
|
if len(mastodon.timeline(since_id=prev['since_id'])) == 0:
|
|
|
|
prev = None
|
2018-08-16 18:59:16 +02:00
|
|
|
except (IndexError, AttributeError):
|
2018-05-18 15:22:27 +02:00
|
|
|
prev = None
|
|
|
|
try:
|
|
|
|
next = data[-1]._pagination_next
|
2018-08-16 18:59:16 +02:00
|
|
|
except (IndexError, AttributeError):
|
2018-05-18 15:22:27 +02:00
|
|
|
next = None
|
2018-08-17 20:50:37 +02:00
|
|
|
|
|
|
|
# This filtering has to be done *after* getting next/prev links
|
2018-08-28 18:22:20 +02:00
|
|
|
if account.preferences.filter_replies:
|
2018-08-17 20:50:37 +02:00
|
|
|
data = [x for x in data if not x.in_reply_to_id]
|
2018-08-28 18:22:20 +02:00
|
|
|
if account.preferences.filter_boosts:
|
2018-08-17 20:50:37 +02:00
|
|
|
data = [x for x in data if not x.reblog]
|
2018-05-18 15:22:27 +02:00
|
|
|
return render(request, 'main/%s_timeline.html' % timeline,
|
|
|
|
{'toots': data, 'form': form, 'timeline': timeline,
|
|
|
|
'timeline_name': timeline_name,
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences,
|
2018-05-18 15:22:27 +02:00
|
|
|
'prev': prev, 'next': next})
|
2018-04-24 00:16:22 +02:00
|
|
|
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-05-18 15:22:27 +02:00
|
|
|
def home(request, next=None, prev=None):
|
|
|
|
return timeline(request, 'home', 'Home', max_id=next, since_id=prev)
|
2018-04-26 02:06:10 +02:00
|
|
|
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-05-18 15:22:27 +02:00
|
|
|
def local(request, next=None, prev=None):
|
|
|
|
return timeline(request, 'local', 'Local', max_id=next, since_id=prev)
|
2018-04-26 02:06:10 +02:00
|
|
|
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-05-18 15:22:27 +02:00
|
|
|
def fed(request, next=None, prev=None):
|
|
|
|
return timeline(request, 'public', 'Federated', max_id=next, since_id=prev)
|
2018-04-24 00:16:22 +02:00
|
|
|
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-05-07 01:46:51 +02:00
|
|
|
def tag(request, tag):
|
|
|
|
try:
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-05-07 01:46:51 +02:00
|
|
|
except NotLoggedInException:
|
|
|
|
return redirect(login)
|
|
|
|
data = mastodon.timeline_hashtag(tag)
|
|
|
|
return render(request, 'main/timeline.html',
|
2018-06-09 01:02:46 +02:00
|
|
|
{'toots': data, 'timeline_name': '#'+tag,
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences})
|
2018-05-07 01:46:51 +02:00
|
|
|
|
2018-05-09 03:47:17 +02:00
|
|
|
@never_cache
|
2018-04-24 00:16:22 +02:00
|
|
|
def login(request):
|
2018-05-14 21:35:10 +02:00
|
|
|
# User posts instance name in form.
|
|
|
|
# POST page redirects user to instance, where they log in.
|
|
|
|
# Instance redirects user to oauth_after_login view.
|
|
|
|
# oauth_after_login view saves credential in session, then redirects to home.
|
|
|
|
if request.method == "GET":
|
|
|
|
form = OAuthLoginForm()
|
|
|
|
return render(request, 'setup/login-oauth.html', {'form': form})
|
|
|
|
elif request.method == "POST":
|
|
|
|
form = OAuthLoginForm(request.POST)
|
|
|
|
redirect_uris = request.build_absolute_uri(reverse('oauth_callback'))
|
|
|
|
if form.is_valid():
|
|
|
|
api_base_url = form.cleaned_data['instance']
|
|
|
|
tmp_base = parse.urlparse(api_base_url.lower())
|
|
|
|
if tmp_base.netloc == '':
|
|
|
|
api_base_url = parse.urlunparse(('https', tmp_base.path,
|
|
|
|
'','','',''))
|
2018-08-28 19:41:21 +02:00
|
|
|
request.session['instance_hostname'] = tmp_base.path
|
2018-05-14 21:35:10 +02:00
|
|
|
else:
|
|
|
|
api_base_url = api_base_url.lower()
|
2018-08-28 19:41:21 +02:00
|
|
|
request.session['instance_hostname'] = tmp_base.netloc
|
2018-05-14 21:35:10 +02:00
|
|
|
|
|
|
|
request.session['instance'] = api_base_url
|
|
|
|
try:
|
|
|
|
client = Client.objects.get(api_base_id=api_base_url)
|
|
|
|
except (Client.DoesNotExist, Client.MultipleObjectsReturned):
|
2018-08-27 16:46:53 +02:00
|
|
|
(client_id, client_secret) = Mastodon.create_app('brutaldon',
|
2018-05-14 21:35:10 +02:00
|
|
|
api_base_url=api_base_url,
|
2018-08-27 16:41:55 +02:00
|
|
|
redirect_uris=redirect_uris,
|
|
|
|
scopes=['read', 'write', 'follow'])
|
2018-05-14 21:35:10 +02:00
|
|
|
client = Client(
|
|
|
|
api_base_id = api_base_url,
|
|
|
|
client_id=client_id,
|
|
|
|
client_secret = client_secret)
|
|
|
|
client.save()
|
|
|
|
|
|
|
|
request.session['client_id'] = client.client_id
|
|
|
|
request.session['client_secret'] = client.client_secret
|
|
|
|
|
|
|
|
mastodon = Mastodon(
|
|
|
|
client_id = client.client_id,
|
|
|
|
client_secret = client.client_secret,
|
|
|
|
api_base_url = api_base_url)
|
2018-08-27 17:12:21 +02:00
|
|
|
return redirect(mastodon.auth_request_url(redirect_uris=redirect_uris,
|
|
|
|
scopes=['read', 'write', 'follow']))
|
2018-05-14 21:35:10 +02:00
|
|
|
else:
|
|
|
|
return render(request, 'setup/login.html', {'form': form})
|
|
|
|
|
|
|
|
else:
|
|
|
|
return redirect(login)
|
|
|
|
|
|
|
|
@never_cache
|
|
|
|
def oauth_callback(request):
|
|
|
|
code = request.GET.get('code', '')
|
|
|
|
mastodon = Mastodon(client_id=request.session['client_id'],
|
|
|
|
client_secret=request.session['client_secret'],
|
|
|
|
api_base_url=request.session['instance'])
|
|
|
|
redirect_uri = request.build_absolute_uri(reverse('oauth_callback'))
|
|
|
|
access_token = mastodon.log_in(code=code,
|
2018-08-27 16:53:35 +02:00
|
|
|
redirect_uri=redirect_uri,
|
|
|
|
scopes=['read', 'write', 'follow'])
|
2018-05-14 21:35:10 +02:00
|
|
|
request.session['access_token'] = access_token
|
2018-05-21 02:28:53 +02:00
|
|
|
user = mastodon.account_verify_credentials()
|
2018-08-28 18:22:20 +02:00
|
|
|
try:
|
2018-08-29 14:46:31 +02:00
|
|
|
account = Account.objects.get(username=user.username + '@' +
|
|
|
|
request.session['instance_hostname'])
|
2018-08-28 18:22:20 +02:00
|
|
|
account.access_token = access_token
|
|
|
|
if not account.preferences:
|
|
|
|
preferences = Preference(theme = Theme.objects.get(id=1))
|
|
|
|
preferences.save()
|
|
|
|
account.preferences = preferences
|
|
|
|
else:
|
|
|
|
request.session['timezone'] = account.preferences.timezone
|
|
|
|
account.save()
|
|
|
|
except (Account.DoesNotExist, Account.MultipleObjectsReturned):
|
|
|
|
preferences = Preference(theme = Theme.objects.get(id=1))
|
|
|
|
preferences.save()
|
2018-08-29 14:18:16 +02:00
|
|
|
account = Account(username=user.username + '@' + request.session['instance_hostname'],
|
2018-08-28 18:22:20 +02:00
|
|
|
access_token = access_token,
|
|
|
|
client = Client.objects.get(api_base_id=request.session['instance']),
|
|
|
|
preferences = preferences)
|
2018-08-29 14:34:05 +02:00
|
|
|
account.save()
|
2018-05-22 14:57:45 +02:00
|
|
|
request.session['user'] = user
|
2018-08-28 19:41:21 +02:00
|
|
|
request.session['username'] = user.username + '@' + request.session['instance_hostname']
|
2018-05-14 21:35:10 +02:00
|
|
|
return redirect(home)
|
|
|
|
|
|
|
|
|
|
|
|
@never_cache
|
|
|
|
def old_login(request):
|
2018-04-24 00:16:22 +02:00
|
|
|
if request.method == "GET":
|
|
|
|
form = LoginForm()
|
|
|
|
return render(request, 'setup/login.html', {'form': form})
|
|
|
|
elif request.method == "POST":
|
|
|
|
form = LoginForm(request.POST)
|
|
|
|
if form.is_valid():
|
2018-04-24 20:49:43 +02:00
|
|
|
api_base_url = form.cleaned_data['instance']
|
|
|
|
tmp_base = parse.urlparse(api_base_url.lower())
|
|
|
|
if tmp_base.netloc == '':
|
|
|
|
api_base_url = parse.urlunparse(('https', tmp_base.path,
|
|
|
|
'','','',''))
|
2018-08-28 19:41:21 +02:00
|
|
|
request.session['instance_hostname'] = tmp_base.path
|
2018-04-24 20:49:43 +02:00
|
|
|
else:
|
|
|
|
api_base_url = api_base_url.lower()
|
2018-08-28 19:41:21 +02:00
|
|
|
request.session['instance_hostname'] = tmp_base.netloc
|
2018-04-24 20:49:43 +02:00
|
|
|
|
|
|
|
request.session['instance'] = api_base_url
|
2018-08-28 18:22:20 +02:00
|
|
|
email = form.cleaned_data['email']
|
2018-04-24 00:16:22 +02:00
|
|
|
password = form.cleaned_data['password']
|
|
|
|
|
2018-04-24 20:49:43 +02:00
|
|
|
try:
|
|
|
|
client = Client.objects.get(api_base_id=api_base_url)
|
|
|
|
except (Client.DoesNotExist, Client.MultipleObjectsReturned):
|
2018-08-27 16:46:53 +02:00
|
|
|
(client_id, client_secret) = Mastodon.create_app('brutaldon',
|
|
|
|
api_base_url=api_base_url,
|
|
|
|
scopes=['read', 'write', 'follow'])
|
2018-04-24 20:49:43 +02:00
|
|
|
client = Client(
|
|
|
|
api_base_id = api_base_url,
|
|
|
|
client_id=client_id,
|
|
|
|
client_secret = client_secret)
|
|
|
|
client.save()
|
2018-04-24 00:16:22 +02:00
|
|
|
|
|
|
|
mastodon = Mastodon(
|
2018-04-24 20:49:43 +02:00
|
|
|
client_id = client.client_id,
|
|
|
|
client_secret = client.client_secret,
|
2018-04-24 00:16:22 +02:00
|
|
|
api_base_url = api_base_url)
|
2018-04-24 20:49:43 +02:00
|
|
|
|
|
|
|
try:
|
2018-08-28 18:22:20 +02:00
|
|
|
account = Account.objects.get(email=email, client_id=client.id)
|
2018-04-24 20:49:43 +02:00
|
|
|
except (Account.DoesNotExist, Account.MultipleObjectsReturned):
|
2018-08-28 18:22:20 +02:00
|
|
|
preferences = Preference(theme = Theme.objects.get(id=1))
|
|
|
|
preferences.save()
|
2018-04-24 20:49:43 +02:00
|
|
|
account = Account(
|
2018-08-28 18:22:20 +02:00
|
|
|
email = email,
|
2018-05-01 02:32:50 +02:00
|
|
|
access_token = "",
|
2018-08-28 18:22:20 +02:00
|
|
|
client = client,
|
|
|
|
preferences = preferences)
|
2018-05-01 02:32:50 +02:00
|
|
|
try:
|
2018-08-28 18:48:52 +02:00
|
|
|
access_token = mastodon.log_in(email,
|
2018-08-27 16:53:35 +02:00
|
|
|
password,
|
|
|
|
scopes=['read', 'write', 'follow'])
|
2018-05-01 02:32:50 +02:00
|
|
|
account.access_token = access_token
|
2018-05-21 02:28:53 +02:00
|
|
|
user = mastodon.account_verify_credentials()
|
2018-05-22 14:57:45 +02:00
|
|
|
request.session['user'] = user
|
2018-08-28 19:41:21 +02:00
|
|
|
request.session['username'] = user.username + '@' + request.session['instance_hostname']
|
|
|
|
account.username = request.session['username']
|
2018-08-28 18:22:20 +02:00
|
|
|
request.session['timezone'] = account.preferences.timezone;
|
|
|
|
account.save()
|
2018-05-01 02:32:50 +02:00
|
|
|
return redirect(home)
|
2018-08-28 18:22:20 +02:00
|
|
|
|
2018-07-18 19:33:16 +02:00
|
|
|
except Exception as ex:
|
|
|
|
form.add_error('', ex)
|
2018-05-01 02:32:50 +02:00
|
|
|
return render(request, 'setup/login.html', {'form': form})
|
2018-04-24 00:16:22 +02:00
|
|
|
else:
|
2018-04-24 20:49:43 +02:00
|
|
|
return render(request, 'setup/login.html', {'form': form})
|
2018-04-24 00:16:22 +02:00
|
|
|
|
2018-05-09 03:47:17 +02:00
|
|
|
@never_cache
|
2018-04-25 01:20:22 +02:00
|
|
|
def logout(request):
|
2018-04-25 23:02:59 +02:00
|
|
|
request.session.flush()
|
2018-06-01 15:22:17 +02:00
|
|
|
return redirect(about)
|
2018-04-25 01:20:22 +02:00
|
|
|
|
2018-04-24 00:16:22 +02:00
|
|
|
def error(request):
|
2018-04-25 01:20:22 +02:00
|
|
|
return render(request, 'error.html', { 'error': "Not logged in yet."})
|
|
|
|
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-06-24 20:19:35 +02:00
|
|
|
def note(request, next=None, prev=None):
|
|
|
|
try:
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-06-24 20:19:35 +02:00
|
|
|
except NotLoggedInException:
|
|
|
|
return redirect(about)
|
|
|
|
notes = mastodon.notifications(limit=100, max_id=next, since_id=prev)
|
|
|
|
try:
|
|
|
|
prev = notes[0]._pagination_prev
|
2018-06-24 21:09:09 +02:00
|
|
|
if len(mastodon.notifications(since_id=prev['since_id'])) == 0:
|
2018-06-24 20:19:35 +02:00
|
|
|
prev = None
|
2018-08-16 18:59:16 +02:00
|
|
|
except (IndexError, AttributeError):
|
2018-06-24 20:19:35 +02:00
|
|
|
prev = None
|
|
|
|
try:
|
|
|
|
next = notes[-1]._pagination_next
|
2018-08-16 18:59:16 +02:00
|
|
|
except (IndexError, AttributeError):
|
2018-06-24 20:19:35 +02:00
|
|
|
next = None
|
2018-04-26 04:50:13 +02:00
|
|
|
return render(request, 'main/notifications.html',
|
2018-04-26 05:07:58 +02:00
|
|
|
{'notes': notes,'timeline': 'Notifications',
|
2018-06-24 20:19:35 +02:00
|
|
|
'timeline_name': 'Notifications',
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences,
|
2018-06-24 20:33:44 +02:00
|
|
|
'prev': prev, 'next': next})
|
2018-04-25 01:20:22 +02:00
|
|
|
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-04-27 00:49:43 +02:00
|
|
|
def thread(request, id):
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-04-27 00:49:43 +02:00
|
|
|
context = mastodon.status_context(id)
|
|
|
|
toot = mastodon.status(id)
|
|
|
|
return render(request, 'main/thread.html',
|
|
|
|
{'context': context, 'toot': toot,
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences})
|
2018-04-27 00:49:43 +02:00
|
|
|
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-06-24 23:19:39 +02:00
|
|
|
def user(request, username, prev=None, next=None):
|
2018-06-24 23:07:43 +02:00
|
|
|
try:
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-06-24 23:07:43 +02:00
|
|
|
except NotLoggedInException:
|
|
|
|
return redirect(about)
|
2018-05-09 03:47:17 +02:00
|
|
|
try:
|
|
|
|
user_dict = mastodon.account_search(username)[0]
|
2018-08-16 18:59:16 +02:00
|
|
|
except (IndexError, AttributeError):
|
2018-05-09 03:47:17 +02:00
|
|
|
raise Http404("The user %s could not be found." % username)
|
2018-07-23 19:37:24 +02:00
|
|
|
data = mastodon.account_statuses(user_dict.id, max_id=next, since_id=prev)
|
2018-06-12 00:16:32 +02:00
|
|
|
relationship = mastodon.account_relationships(user_dict.id)[0]
|
2018-06-24 23:07:43 +02:00
|
|
|
try:
|
|
|
|
prev = data[0]._pagination_prev
|
|
|
|
if len(mastodon.account_statuses(user_dict.id,
|
|
|
|
since_id=prev['since_id'])) == 0:
|
|
|
|
prev = None
|
2018-08-16 18:59:16 +02:00
|
|
|
except (IndexError, AttributeError):
|
2018-06-24 23:07:43 +02:00
|
|
|
prev = None
|
|
|
|
try:
|
|
|
|
next = data[-1]._pagination_next
|
2018-08-16 18:59:16 +02:00
|
|
|
except (IndexError, AttributeError):
|
2018-06-24 23:07:43 +02:00
|
|
|
next = None
|
2018-06-24 23:13:31 +02:00
|
|
|
return render(request, 'main/user.html',
|
2018-05-09 03:47:17 +02:00
|
|
|
{'toots': data, 'user': user_dict,
|
2018-06-12 00:16:32 +02:00
|
|
|
'relationship': relationship,
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences,
|
2018-06-24 23:07:43 +02:00
|
|
|
'prev': prev, 'next': next})
|
2018-05-09 03:47:17 +02:00
|
|
|
|
|
|
|
|
2018-05-01 15:28:57 +02:00
|
|
|
@never_cache
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-04-25 22:45:46 +02:00
|
|
|
def settings(request):
|
2018-08-28 18:22:20 +02:00
|
|
|
account = Account.objects.get(username=request.session['username'])
|
2018-04-25 22:45:46 +02:00
|
|
|
if request.method == 'POST':
|
2018-08-28 18:22:20 +02:00
|
|
|
form = PreferencesForm(request.POST)
|
2018-04-25 22:45:46 +02:00
|
|
|
if form.is_valid():
|
2018-08-28 18:22:20 +02:00
|
|
|
account.preferences.theme =form.cleaned_data['theme']
|
|
|
|
account.preferences.filter_replies = form.cleaned_data['filter_replies']
|
|
|
|
account.preferences.filter_boosts = form.cleaned_data['filter_boosts']
|
|
|
|
account.preferences.timezone = form.cleaned_data['timezone']
|
|
|
|
request.session['timezone'] = account.preferences.timezone
|
|
|
|
account.preferences.save()
|
|
|
|
account.save()
|
2018-04-25 22:45:46 +02:00
|
|
|
return redirect(home)
|
|
|
|
else:
|
2018-04-26 05:07:58 +02:00
|
|
|
return render(request, 'setup/settings.html',
|
2018-08-28 18:22:20 +02:00
|
|
|
{'form' : form, 'account': account})
|
2018-04-25 22:45:46 +02:00
|
|
|
else:
|
2018-08-28 18:22:20 +02:00
|
|
|
request.session['timezone'] = account.preferences.timezone
|
|
|
|
form = PreferencesForm(instance=account.preferences)
|
2018-04-26 05:07:58 +02:00
|
|
|
return render(request, 'setup/settings.html',
|
2018-07-18 19:33:16 +02:00
|
|
|
{ 'form': form,
|
2018-08-28 18:22:20 +02:00
|
|
|
'account': account,
|
|
|
|
'preferences': account.preferences})
|
2018-04-26 05:07:58 +02:00
|
|
|
|
2018-05-01 15:28:57 +02:00
|
|
|
@never_cache
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-06-12 01:19:22 +02:00
|
|
|
def toot(request, mention=None):
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-04-27 20:12:29 +02:00
|
|
|
if request.method == 'GET':
|
2018-06-12 01:19:22 +02:00
|
|
|
if mention:
|
|
|
|
if not mention.startswith('@'):
|
|
|
|
mention = '@'+mention
|
|
|
|
form = PostForm(initial={'visibility': request.session['user'].source.privacy,
|
|
|
|
'status': mention + '\n' })
|
|
|
|
else:
|
|
|
|
form = PostForm(initial={'visibility': request.session['user'].source.privacy})
|
2018-04-30 14:58:10 +02:00
|
|
|
return render(request, 'main/post.html',
|
2018-04-27 20:12:29 +02:00
|
|
|
{'form': form,
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences})
|
2018-04-27 20:12:29 +02:00
|
|
|
elif request.method == 'POST':
|
|
|
|
form = PostForm(request.POST, request.FILES)
|
|
|
|
if form.is_valid():
|
2018-05-01 20:44:56 +02:00
|
|
|
# create media objects
|
|
|
|
media_objects = []
|
|
|
|
for index in range(1,5):
|
|
|
|
if 'media_file_'+str(index) in request.FILES:
|
|
|
|
media_objects.append(
|
|
|
|
mastodon.media_post(request.FILES['media_file_'+str(index)]
|
|
|
|
.temporary_file_path(),
|
|
|
|
description=request.POST.get('media_text_'
|
|
|
|
+str(index),
|
|
|
|
None)))
|
2018-05-22 14:57:45 +02:00
|
|
|
if form.cleaned_data['visibility'] == '':
|
|
|
|
form.cleaned_data['visibility'] = request.session['user'].source.privacy
|
2018-09-05 01:19:35 +02:00
|
|
|
try:
|
|
|
|
mastodon.status_post(status=form.cleaned_data['status'],
|
|
|
|
visibility=form.cleaned_data['visibility'],
|
|
|
|
spoiler_text=form.cleaned_data['spoiler_text'],
|
|
|
|
media_ids=media_objects)
|
|
|
|
except MastodonAPIError as error:
|
|
|
|
form.add_error("", "%s" % error.args[-1])
|
|
|
|
return render(request, 'main/post.html',
|
|
|
|
{'form': form,
|
|
|
|
'own_acct': request.session['user'],
|
|
|
|
'preferences': account.preferences})
|
2018-04-27 20:12:29 +02:00
|
|
|
return redirect(home)
|
|
|
|
else:
|
2018-04-30 14:58:10 +02:00
|
|
|
return render(request, 'main/post.html',
|
2018-04-27 20:12:29 +02:00
|
|
|
{'form': form,
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences})
|
2018-04-27 20:12:29 +02:00
|
|
|
else:
|
|
|
|
return redirect(toot)
|
2018-04-30 20:31:59 +02:00
|
|
|
|
2018-08-24 02:58:07 +02:00
|
|
|
@br_login_required
|
|
|
|
def redraft(request, id):
|
|
|
|
if request.method == 'GET':
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-08-24 02:58:07 +02:00
|
|
|
toot = mastodon.status(id)
|
2018-08-24 14:38:42 +02:00
|
|
|
toot_content = BeautifulSoup(toot.content).get_text("\n")
|
|
|
|
form = PostForm({'status': toot_content,
|
2018-08-24 02:58:07 +02:00
|
|
|
'visibility': toot.visibility,
|
|
|
|
'spoiler_text': toot.spoiler_text,
|
2018-08-24 14:38:42 +02:00
|
|
|
'media_text_1': safe_get_attachment(toot, 0).description,
|
|
|
|
'media_text_2': safe_get_attachment(toot, 1).description,
|
|
|
|
'media_text_3': safe_get_attachment(toot, 2).description,
|
|
|
|
'media_text_4': safe_get_attachment(toot, 3).description,
|
2018-08-24 02:58:07 +02:00
|
|
|
})
|
|
|
|
return render(request, 'main/redraft.html',
|
|
|
|
{'toot': toot, 'form': form, 'redraft':True,
|
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences})
|
2018-08-24 02:58:07 +02:00
|
|
|
elif request.method == 'POST':
|
|
|
|
form = PostForm(request.POST, request.FILES)
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-08-24 02:58:07 +02:00
|
|
|
toot = mastodon.status(id)
|
|
|
|
if form.is_valid():
|
2018-08-24 14:38:42 +02:00
|
|
|
media_objects = []
|
|
|
|
for index in range(1,5):
|
|
|
|
if 'media_file_'+str(index) in request.FILES:
|
|
|
|
media_objects.append(
|
|
|
|
mastodon.media_post(request.FILES['media_file_'+str(index)]
|
|
|
|
.temporary_file_path(),
|
|
|
|
description=request.POST.get('media_text_'
|
|
|
|
+str(index),
|
|
|
|
None)))
|
|
|
|
if form.cleaned_data['visibility'] == '':
|
|
|
|
form.cleaned_data['visibility'] = request.session['user'].source.privacy
|
2018-09-05 16:01:00 +02:00
|
|
|
try:
|
|
|
|
mastodon.status_post(status=form.cleaned_data['status'],
|
|
|
|
visibility=form.cleaned_data['visibility'],
|
|
|
|
spoiler_text=form.cleaned_data['spoiler_text'],
|
|
|
|
media_ids=media_objects,
|
|
|
|
in_reply_to_id=toot.in_reply_to_id)
|
|
|
|
mastodon.status_delete(id)
|
|
|
|
except MastodonAPIError as error:
|
|
|
|
form.add_error("", "%s" % error.args[-1])
|
|
|
|
return render(request, 'main/redraft.html',
|
|
|
|
{'toot': toot, 'form': form, 'redraft': True,
|
|
|
|
'own_acct': request.session['user'],
|
|
|
|
'preferences': account.preferences})
|
2018-08-24 02:58:07 +02:00
|
|
|
return redirect(home)
|
|
|
|
else:
|
|
|
|
return render(request, 'main/redraft.html',
|
|
|
|
{'toot': toot, 'form': form, 'redraft': True,
|
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences})
|
2018-08-24 02:58:07 +02:00
|
|
|
else:
|
|
|
|
return redirect(redraft, id)
|
|
|
|
|
|
|
|
def safe_get_attachment(toot, index):
|
|
|
|
"""Get an attachment from a toot, without crashing if it isn't there."""
|
|
|
|
try:
|
|
|
|
return toot.media_attachments[index]
|
|
|
|
except IndexError:
|
2018-08-24 14:38:42 +02:00
|
|
|
adict = AttribAccessDict()
|
|
|
|
adict.id, adict.type, adict.description = "", "unknown", ""
|
|
|
|
adict.url, adict.remote_url, adict.preview_url = '', '', ''
|
|
|
|
adict.text_url = ''
|
|
|
|
return adict
|
2018-08-24 02:58:07 +02:00
|
|
|
|
|
|
|
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-04-30 20:31:59 +02:00
|
|
|
def reply(request, id):
|
|
|
|
if request.method == 'GET':
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-04-30 20:31:59 +02:00
|
|
|
toot = mastodon.status(id)
|
|
|
|
context = mastodon.status_context(id)
|
2018-06-13 19:42:40 +02:00
|
|
|
if toot.account.acct != request.session['user'].acct:
|
|
|
|
initial_text = '@' + toot.account.acct + " "
|
|
|
|
else:
|
|
|
|
initial_text = ""
|
2018-06-04 15:09:34 +02:00
|
|
|
for mention in [x for x in toot.mentions if x.acct != request.session['user'].acct]:
|
2018-05-01 15:34:14 +02:00
|
|
|
initial_text +=('@' + mention.acct + " ")
|
2018-06-22 14:40:46 +02:00
|
|
|
if initial_text != "":
|
|
|
|
initial_text += "\n"
|
2018-05-01 15:34:14 +02:00
|
|
|
form = PostForm({'status': initial_text,
|
|
|
|
'visibility': toot.visibility,
|
|
|
|
'spoiler_text': toot.spoiler_text})
|
2018-04-30 20:31:59 +02:00
|
|
|
return render(request, 'main/reply.html',
|
|
|
|
{'context': context, 'toot': toot, 'form': form, 'reply':True,
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences})
|
2018-04-30 20:31:59 +02:00
|
|
|
elif request.method == 'POST':
|
|
|
|
form = PostForm(request.POST, request.FILES)
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-09-05 16:01:00 +02:00
|
|
|
toot = mastodon.status(id)
|
|
|
|
context = mastodon.status_context(id)
|
2018-04-30 20:31:59 +02:00
|
|
|
if form.is_valid():
|
2018-05-01 20:44:56 +02:00
|
|
|
# create media objects
|
|
|
|
media_objects = []
|
|
|
|
for index in range(1,5):
|
|
|
|
if 'media_file_'+str(index) in request.FILES:
|
|
|
|
media_objects.append(
|
|
|
|
mastodon.media_post(request.FILES['media_file_'+str(index)]
|
|
|
|
.temporary_file_path(),
|
|
|
|
description=request.POST.get('media_text_'
|
|
|
|
+str(index),
|
|
|
|
None)))
|
2018-09-05 16:01:00 +02:00
|
|
|
try:
|
|
|
|
mastodon.status_post(status=form.cleaned_data['status'],
|
|
|
|
visibility=form.cleaned_data['visibility'],
|
|
|
|
spoiler_text=form.cleaned_data['spoiler_text'],
|
|
|
|
media_ids=media_objects,
|
|
|
|
in_reply_to_id=id)
|
|
|
|
except MastodonAPIError as error:
|
|
|
|
form.add_error("", "%s" % error.args[-1])
|
|
|
|
return render(request, 'main/reply.html',
|
|
|
|
{'context': context, 'toot': toot, 'form': form, 'reply': True,
|
|
|
|
'own_acct': request.session['user'],
|
|
|
|
'preferences': account.preferences})
|
2018-04-30 20:31:59 +02:00
|
|
|
return redirect(thread, id)
|
|
|
|
else:
|
|
|
|
return render(request, 'main/reply.html',
|
|
|
|
{'context': context, 'toot': toot, 'form': form, 'reply': True,
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences})
|
2018-04-30 20:31:59 +02:00
|
|
|
else:
|
|
|
|
return redirect(reply, id)
|
2018-05-01 00:40:41 +02:00
|
|
|
|
2018-05-01 15:28:57 +02:00
|
|
|
@never_cache
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-05-01 00:40:41 +02:00
|
|
|
def fav(request, id):
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-05-01 00:40:41 +02:00
|
|
|
toot = mastodon.status(id)
|
|
|
|
if request.method == 'POST':
|
2018-05-01 14:39:48 +02:00
|
|
|
if not request.POST.get('cancel', None):
|
2018-05-01 00:53:11 +02:00
|
|
|
if toot.favourited:
|
|
|
|
mastodon.status_unfavourite(id)
|
|
|
|
else:
|
|
|
|
mastodon.status_favourite(id)
|
2018-08-30 22:42:01 +02:00
|
|
|
if request.POST.get('ic-request'):
|
|
|
|
toot['favourited'] = not toot['favourited']
|
|
|
|
return render(request, 'intercooler/fav.html',
|
|
|
|
{"toot": toot,
|
|
|
|
'own_acct': request.session['user'],
|
|
|
|
"preferences": account.preferences})
|
|
|
|
else:
|
|
|
|
return redirect(thread, id)
|
2018-05-01 00:40:41 +02:00
|
|
|
else:
|
2018-05-04 16:58:37 +02:00
|
|
|
return render(request, 'main/fav.html',
|
2018-07-18 19:33:16 +02:00
|
|
|
{"toot": toot,
|
|
|
|
'own_acct': request.session['user'],
|
|
|
|
"confirm_page": True,
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences})
|
2018-05-01 00:49:06 +02:00
|
|
|
|
2018-05-01 16:32:21 +02:00
|
|
|
@never_cache
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-05-01 00:49:06 +02:00
|
|
|
def boost(request, id):
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-05-01 00:49:06 +02:00
|
|
|
toot = mastodon.status(id)
|
|
|
|
if request.method == 'POST':
|
2018-05-01 14:39:48 +02:00
|
|
|
if not request.POST.get('cancel', None):
|
2018-05-01 00:53:11 +02:00
|
|
|
if toot.reblogged:
|
|
|
|
mastodon.status_unreblog(id)
|
|
|
|
else:
|
|
|
|
mastodon.status_reblog(id)
|
2018-08-30 22:42:01 +02:00
|
|
|
if request.POST.get('ic-request'):
|
|
|
|
toot['reblogged'] = not toot['reblogged']
|
|
|
|
return render(request, 'intercooler/boost.html',
|
|
|
|
{"toot": toot,
|
|
|
|
'own_acct': request.session['user'],
|
|
|
|
"preferences": account.preferences})
|
|
|
|
else:
|
|
|
|
return redirect(thread, id)
|
2018-05-01 00:49:06 +02:00
|
|
|
else:
|
2018-05-04 16:58:37 +02:00
|
|
|
return render(request, 'main/boost.html',
|
2018-07-18 19:33:16 +02:00
|
|
|
{"toot": toot,
|
|
|
|
'own_acct': request.session['user'],
|
|
|
|
'confirm_page': True,
|
2018-08-28 18:22:20 +02:00
|
|
|
"preferences": account.preferences})
|
2018-05-22 15:41:11 +02:00
|
|
|
|
|
|
|
@never_cache
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-05-22 15:41:11 +02:00
|
|
|
def delete(request, id):
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-05-22 15:41:11 +02:00
|
|
|
toot = mastodon.status(id)
|
|
|
|
if request.method == 'POST':
|
|
|
|
if toot.account.acct != request.session['user'].acct:
|
|
|
|
return redirect('home')
|
|
|
|
if not request.POST.get('cancel', None):
|
|
|
|
mastodon.status_delete(id)
|
|
|
|
return redirect(home)
|
|
|
|
else:
|
|
|
|
return render(request, 'main/delete.html',
|
2018-07-18 19:33:16 +02:00
|
|
|
{"toot": toot,
|
|
|
|
'own_acct': request.session['user'],
|
|
|
|
'confirm_page': True,
|
2018-08-28 18:22:20 +02:00
|
|
|
"preferences": account.preferences})
|
2018-05-26 19:28:13 +02:00
|
|
|
|
2018-06-11 20:34:38 +02:00
|
|
|
@never_cache
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-06-11 20:34:38 +02:00
|
|
|
def follow(request, id):
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-06-12 01:09:12 +02:00
|
|
|
try:
|
|
|
|
user_dict = mastodon.account(id)
|
|
|
|
relationship = mastodon.account_relationships(user_dict.id)[0]
|
2018-08-16 18:59:16 +02:00
|
|
|
except (IndexError, AttributeError):
|
2018-06-12 01:09:12 +02:00
|
|
|
raise Http404("The user could not be found.")
|
|
|
|
if request.method == 'POST':
|
|
|
|
if not request.POST.get('cancel', None):
|
|
|
|
if relationship.requested or relationship.following:
|
|
|
|
mastodon.account_unfollow(id)
|
|
|
|
else:
|
|
|
|
mastodon.account_follow(id)
|
2018-08-31 21:55:05 +02:00
|
|
|
if request.POST.get('ic-request'):
|
|
|
|
sleep(1) # This is annoying, but the next call will return Requested instead of Following in some cases
|
|
|
|
relationship = mastodon.account_relationships(user_dict.id)[0]
|
|
|
|
return render(request, 'intercooler/follow.html',
|
|
|
|
{"user": user_dict, "relationship": relationship,
|
|
|
|
'own_acct': request.session['user'],
|
|
|
|
'preferences': account.preferences})
|
|
|
|
else:
|
2018-06-12 01:09:12 +02:00
|
|
|
return redirect(user, user_dict.acct)
|
|
|
|
else:
|
|
|
|
return render(request, 'main/follow.html',
|
2018-06-12 01:38:49 +02:00
|
|
|
{"user": user_dict, "relationship": relationship,
|
|
|
|
"confirm_page": True,
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences})
|
2018-06-11 20:34:38 +02:00
|
|
|
|
|
|
|
@never_cache
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-06-11 20:34:38 +02:00
|
|
|
def block(request, id):
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-06-12 01:38:49 +02:00
|
|
|
try:
|
|
|
|
user_dict = mastodon.account(id)
|
|
|
|
relationship = mastodon.account_relationships(user_dict.id)[0]
|
2018-08-16 18:59:16 +02:00
|
|
|
except (IndexError, AttributeError):
|
2018-06-12 01:38:49 +02:00
|
|
|
raise Http404("The user could not be found.")
|
|
|
|
if request.method == 'POST':
|
|
|
|
if not request.POST.get('cancel', None):
|
|
|
|
if relationship.blocking:
|
|
|
|
mastodon.account_unblock(id)
|
|
|
|
else:
|
|
|
|
mastodon.account_block(id)
|
2018-09-03 01:52:48 +02:00
|
|
|
if request.POST.get('ic-request'):
|
|
|
|
relationship['blocking'] = not relationship['blocking']
|
|
|
|
return render(request, 'intercooler/block.html',
|
|
|
|
{"user": user_dict,
|
|
|
|
"relationship": relationship,
|
|
|
|
})
|
|
|
|
else:
|
|
|
|
return redirect(user, user_dict.acct)
|
2018-06-12 01:38:49 +02:00
|
|
|
else:
|
|
|
|
return render(request, 'main/block.html',
|
|
|
|
{"user": user_dict, "relationship": relationship,
|
|
|
|
"confirm_page": True,
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences})
|
2018-06-12 01:38:49 +02:00
|
|
|
|
2018-06-11 20:34:38 +02:00
|
|
|
@never_cache
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-06-11 20:34:38 +02:00
|
|
|
def mute(request, id):
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-06-12 01:38:49 +02:00
|
|
|
try:
|
|
|
|
user_dict = mastodon.account(id)
|
|
|
|
relationship = mastodon.account_relationships(user_dict.id)[0]
|
2018-08-16 18:59:16 +02:00
|
|
|
except (IndexError, AttributeError):
|
2018-06-12 01:38:49 +02:00
|
|
|
raise Http404("The user could not be found.")
|
|
|
|
if request.method == 'POST':
|
|
|
|
if not request.POST.get('cancel', None):
|
|
|
|
if relationship.muting:
|
|
|
|
mastodon.account_unmute(id)
|
|
|
|
else:
|
|
|
|
mastodon.account_mute(id)
|
2018-09-03 01:47:21 +02:00
|
|
|
if request.POST.get('ic-request'):
|
|
|
|
relationship['muting'] = not relationship['muting']
|
|
|
|
return render(request, 'intercooler/mute.html',
|
|
|
|
{"user": user_dict,
|
|
|
|
"relationship": relationship,
|
|
|
|
})
|
|
|
|
else:
|
|
|
|
return redirect(user, user_dict.acct)
|
2018-06-12 01:38:49 +02:00
|
|
|
else:
|
|
|
|
return render(request, 'main/mute.html',
|
|
|
|
{"user": user_dict, "relationship": relationship,
|
|
|
|
"confirm_page": True,
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
'preferences': account.preferences})
|
2018-06-12 01:38:49 +02:00
|
|
|
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-06-06 00:36:44 +02:00
|
|
|
def search(request):
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-06-09 01:03:02 +02:00
|
|
|
return render(request, 'main/search.html',
|
2018-08-28 18:22:20 +02:00
|
|
|
{"preferences": account.preferences,
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session['user'],
|
|
|
|
})
|
2018-06-06 00:36:44 +02:00
|
|
|
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-06-06 00:36:44 +02:00
|
|
|
def search_results(request):
|
|
|
|
if request.method == 'GET':
|
|
|
|
query = request.GET.get('q', '')
|
|
|
|
elif request.method == 'POST':
|
|
|
|
query = request.POST.get('q', '')
|
|
|
|
else:
|
|
|
|
query = ''
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-06-06 00:36:44 +02:00
|
|
|
results = mastodon.search(query)
|
2018-06-09 01:03:02 +02:00
|
|
|
return render(request, 'main/search_results.html',
|
2018-06-06 00:36:44 +02:00
|
|
|
{"results": results,
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session['user'],
|
2018-08-28 18:22:20 +02:00
|
|
|
"preferences": account.preferences})
|
2018-06-06 00:36:44 +02:00
|
|
|
|
2018-05-26 19:28:13 +02:00
|
|
|
def about(request):
|
2018-08-16 19:10:45 +02:00
|
|
|
version = django_settings.BRUTALDON_VERSION
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
|
|
|
if account:
|
|
|
|
preferences = account.preferences
|
|
|
|
else:
|
|
|
|
preferences = None
|
2018-05-27 19:43:20 +02:00
|
|
|
return render(request, 'about.html',
|
2018-08-28 18:22:20 +02:00
|
|
|
{"preferences": preferences,
|
2018-08-16 19:10:45 +02:00
|
|
|
"version": version,
|
2018-07-18 19:33:16 +02:00
|
|
|
'own_acct': request.session.get('user', None),
|
|
|
|
})
|
2018-05-26 19:28:13 +02:00
|
|
|
def privacy(request):
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-05-27 19:43:20 +02:00
|
|
|
return render(request, 'privacy.html',
|
2018-08-28 18:22:20 +02:00
|
|
|
{"preferences": preferences,
|
2018-08-22 15:27:45 +02:00
|
|
|
'own_acct' : request.session.get('user', None)})
|
2018-08-10 01:39:23 +02:00
|
|
|
|
|
|
|
@cache_page(60 * 30)
|
2018-08-22 15:21:09 +02:00
|
|
|
@br_login_required
|
2018-08-10 01:39:23 +02:00
|
|
|
def emoji_reference(request):
|
2018-08-28 18:22:20 +02:00
|
|
|
account, mastodon = get_usercontext(request)
|
2018-08-10 01:39:23 +02:00
|
|
|
emojos = mastodon.custom_emojis()
|
|
|
|
return render(request, 'main/emoji.html',
|
2018-08-28 18:22:20 +02:00
|
|
|
{"preferences": account.preferences,
|
2018-08-17 03:19:03 +02:00
|
|
|
"emojos": sorted(emojos, key=lambda x: x['shortcode']),
|
2018-08-10 01:39:23 +02:00
|
|
|
'own_acct' : request.session['user']})
|