Add user icon to various pages to identify which account you're using

This commit is contained in:
Jason McBrayer 2018-07-18 13:33:16 -04:00
parent 2e7ffff2b1
commit 6b3b46dff0
6 changed files with 76 additions and 27 deletions

View File

@ -48,6 +48,11 @@ figure.media-left p.image a img
border-radius: 5px; border-radius: 5px;
} }
img.avatar
{
border-radius: 5px;
}
.active-context { .active-context {
background-color: #FFF8DC; background-color: #FFF8DC;
} }

View File

@ -5,7 +5,14 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}brutaldon{% endblock %}</title> <title>
{% block title %}
{% if own_acct %}
brutaldon ({{ own_acct.username }})
{% else %}
brutaldon
{% endif %}
{% endblock %}</title>
{% if not fullbrutalism %} {% if not fullbrutalism %}
<link rel="stylesheet" <link rel="stylesheet"
href="{% static 'css/bulma.min.css' %}"> href="{% static 'css/bulma.min.css' %}">
@ -24,8 +31,14 @@
<nav class="navbar" role="navigation" aria-label="main navigation"> <nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand"> <div class="navbar-brand">
<a class="navbar-item" href="{% url "home" %}"> <a class="navbar-item" href="{% url "home" %}">
<img src="{% static "images/brutaldon.png" %}" {% if own_acct %}
width="32" height="32" alt="Brutaldon"> <img src="{{ own_acct.avatar_static }}"
class="image is-32x32"
alt="Brutaldon ({{ own_acct.username }})">
{% else %}
<img src="{% static "images/brutaldon.png" %}"
class="image is-32x32" alt="Brutaldon">
{% endif %}
</a> </a>
</div> </div>
<div class="navbar-menu is-active" id="navMenu"> <div class="navbar-menu is-active" id="navMenu">

View File

@ -14,8 +14,9 @@
</div> </div>
<div class="field has-addons"> <div class="field has-addons">
<div class="control"> <div class="control level is-mobile">
<input type="submit" class="button is-primary" <img class="image avatar is-48x48 level-item" src="{{ own_acct.avatar_static }}" alt="">
<input type="submit" class="button is-primary level-item"
name="toot" value="Toot"> name="toot" value="Toot">
</div> </div>
</div> </div>

View File

@ -113,9 +113,11 @@
{{ form.errors }} {{ form.errors }}
</div> </div>
<div class="field"> <div class="field has-addons">
<div class="control"> <div class="control level is-mobile">
<input type="submit" class="button is-primary" <img class="image avatar is-48x48 level-item" src="{{ own_acct.avatar_static }}"
alt="">
<input type="submit" class="button is-primary level-item"
name="toot" value="Toot"> name="toot" value="Toot">
</div> </div>
</div> </div>

View File

@ -39,6 +39,11 @@
value="Log in" class="button is-primary" > value="Log in" class="button is-primary" >
</div> </div>
</form> </form>
{% if form.errors %}
<p class="error">
{{ form.non_field_errors | escape }}
</p>
{% endif %}
<div class="notification"> <div class="notification">
<button class="delete"></button> <button class="delete"></button>

View File

@ -89,7 +89,7 @@ def timeline(request, timeline='home', timeline_name='Home', max_id=None, since_
return render(request, 'main/%s_timeline.html' % timeline, return render(request, 'main/%s_timeline.html' % timeline,
{'toots': data, 'form': form, 'timeline': timeline, {'toots': data, 'form': form, 'timeline': timeline,
'timeline_name': timeline_name, 'timeline_name': timeline_name,
'own_username': request.session['user'].acct, 'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request), 'fullbrutalism': fullbrutalism_p(request),
'prev': prev, 'next': next}) 'prev': prev, 'next': next})
@ -110,7 +110,7 @@ def tag(request, tag):
data = mastodon.timeline_hashtag(tag) data = mastodon.timeline_hashtag(tag)
return render(request, 'main/timeline.html', return render(request, 'main/timeline.html',
{'toots': data, 'timeline_name': '#'+tag, {'toots': data, 'timeline_name': '#'+tag,
'own_username': request.session['user'].acct, 'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)}) 'fullbrutalism': fullbrutalism_p(request)})
@never_cache @never_cache
@ -170,7 +170,7 @@ def oauth_callback(request):
redirect_uri = request.build_absolute_uri(reverse('oauth_callback')) redirect_uri = request.build_absolute_uri(reverse('oauth_callback'))
access_token = mastodon.log_in(code=code, access_token = mastodon.log_in(code=code,
redirect_uri=redirect_uri, redirect_uri=redirect_uri,
scopes=['read', 'write', 'follow']) scopes=['read', 'write', 'follow', 'push'])
request.session['access_token'] = access_token request.session['access_token'] = access_token
user = mastodon.account_verify_credentials() user = mastodon.account_verify_credentials()
request.session['user'] = user request.session['user'] = user
@ -222,7 +222,8 @@ def old_login(request):
client = client) client = client)
try: try:
access_token = mastodon.log_in(username, access_token = mastodon.log_in(username,
password) password,
scopes=['read', 'write', 'follow', 'push'])
account.access_token = access_token account.access_token = access_token
account.save() account.save()
request.session['username'] = username request.session['username'] = username
@ -230,8 +231,9 @@ def old_login(request):
request.session['user'] = user request.session['user'] = user
return redirect(home) return redirect(home)
except: except Exception as ex:
# FIXME: add the errors form.add_error('', ex)
return render(request, 'setup/login.html', {'form': form}) return render(request, 'setup/login.html', {'form': form})
else: else:
return render(request, 'setup/login.html', {'form': form}) return render(request, 'setup/login.html', {'form': form})
@ -263,7 +265,7 @@ def note(request, next=None, prev=None):
return render(request, 'main/notifications.html', return render(request, 'main/notifications.html',
{'notes': notes,'timeline': 'Notifications', {'notes': notes,'timeline': 'Notifications',
'timeline_name': 'Notifications', 'timeline_name': 'Notifications',
'own_username': request.session['user'].acct, 'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request), 'fullbrutalism': fullbrutalism_p(request),
'prev': prev, 'next': next}) 'prev': prev, 'next': next})
@ -273,7 +275,7 @@ def thread(request, id):
toot = mastodon.status(id) toot = mastodon.status(id)
return render(request, 'main/thread.html', return render(request, 'main/thread.html',
{'context': context, 'toot': toot, {'context': context, 'toot': toot,
'own_username': request.session['user'].acct, 'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)}) 'fullbrutalism': fullbrutalism_p(request)})
def user(request, username, prev=None, next=None): def user(request, username, prev=None, next=None):
@ -301,7 +303,7 @@ def user(request, username, prev=None, next=None):
return render(request, 'main/user.html', return render(request, 'main/user.html',
{'toots': data, 'user': user_dict, {'toots': data, 'user': user_dict,
'relationship': relationship, 'relationship': relationship,
'own_username': request.session['user'].acct, 'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request), 'fullbrutalism': fullbrutalism_p(request),
'prev': prev, 'next': next}) 'prev': prev, 'next': next})
@ -315,11 +317,15 @@ def settings(request):
return redirect(home) return redirect(home)
else: else:
return render(request, 'setup/settings.html', return render(request, 'setup/settings.html',
{'form' : form, 'fullbrutalism': fullbrutalism_p(request)}) {'form' : form,
'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)})
else: else:
form = SettingsForm(request.session) form = SettingsForm(request.session)
return render(request, 'setup/settings.html', return render(request, 'setup/settings.html',
{ 'form': form, 'fullbrutalism': fullbrutalism_p(request)}) { 'form': form,
'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)})
@never_cache @never_cache
def toot(request, mention=None): def toot(request, mention=None):
@ -333,6 +339,7 @@ def toot(request, mention=None):
form = PostForm(initial={'visibility': request.session['user'].source.privacy}) form = PostForm(initial={'visibility': request.session['user'].source.privacy})
return render(request, 'main/post.html', return render(request, 'main/post.html',
{'form': form, {'form': form,
'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)}) 'fullbrutalism': fullbrutalism_p(request)})
elif request.method == 'POST': elif request.method == 'POST':
form = PostForm(request.POST, request.FILES) form = PostForm(request.POST, request.FILES)
@ -359,6 +366,7 @@ def toot(request, mention=None):
else: else:
return render(request, 'main/post.html', return render(request, 'main/post.html',
{'form': form, {'form': form,
'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)}) 'fullbrutalism': fullbrutalism_p(request)})
else: else:
return redirect(toot) return redirect(toot)
@ -381,7 +389,7 @@ def reply(request, id):
'spoiler_text': toot.spoiler_text}) 'spoiler_text': toot.spoiler_text})
return render(request, 'main/reply.html', return render(request, 'main/reply.html',
{'context': context, 'toot': toot, 'form': form, 'reply':True, {'context': context, 'toot': toot, 'form': form, 'reply':True,
'own_username': request.session['user'].acct, 'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)}) 'fullbrutalism': fullbrutalism_p(request)})
elif request.method == 'POST': elif request.method == 'POST':
form = PostForm(request.POST, request.FILES) form = PostForm(request.POST, request.FILES)
@ -408,7 +416,7 @@ def reply(request, id):
context = mastodon.status_context(id) context = mastodon.status_context(id)
return render(request, 'main/reply.html', return render(request, 'main/reply.html',
{'context': context, 'toot': toot, 'form': form, 'reply': True, {'context': context, 'toot': toot, 'form': form, 'reply': True,
'own_username': request.session['user'].acct, 'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)}) 'fullbrutalism': fullbrutalism_p(request)})
else: else:
return redirect(reply, id) return redirect(reply, id)
@ -426,7 +434,9 @@ def fav(request, id):
return redirect(thread, id) return redirect(thread, id)
else: else:
return render(request, 'main/fav.html', return render(request, 'main/fav.html',
{"toot": toot, "confirm_page": True, {"toot": toot,
'own_acct': request.session['user'],
"confirm_page": True,
'fullbrutalism': fullbrutalism_p(request)}) 'fullbrutalism': fullbrutalism_p(request)})
@never_cache @never_cache
@ -442,7 +452,9 @@ def boost(request, id):
return redirect(thread, id) return redirect(thread, id)
else: else:
return render(request, 'main/boost.html', return render(request, 'main/boost.html',
{"toot": toot, 'confirm_page': True, {"toot": toot,
'own_acct': request.session['user'],
'confirm_page': True,
"fullbrutalism": fullbrutalism_p(request)}) "fullbrutalism": fullbrutalism_p(request)})
@never_cache @never_cache
@ -457,7 +469,9 @@ def delete(request, id):
return redirect(home) return redirect(home)
else: else:
return render(request, 'main/delete.html', return render(request, 'main/delete.html',
{"toot": toot, 'confirm_page': True, {"toot": toot,
'own_acct': request.session['user'],
'confirm_page': True,
"fullbrutalism": fullbrutalism_p(request)}) "fullbrutalism": fullbrutalism_p(request)})
@never_cache @never_cache
@ -479,6 +493,7 @@ def follow(request, id):
return render(request, 'main/follow.html', return render(request, 'main/follow.html',
{"user": user_dict, "relationship": relationship, {"user": user_dict, "relationship": relationship,
"confirm_page": True, "confirm_page": True,
'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)}) 'fullbrutalism': fullbrutalism_p(request)})
@never_cache @never_cache
@ -500,6 +515,7 @@ def block(request, id):
return render(request, 'main/block.html', return render(request, 'main/block.html',
{"user": user_dict, "relationship": relationship, {"user": user_dict, "relationship": relationship,
"confirm_page": True, "confirm_page": True,
'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)}) 'fullbrutalism': fullbrutalism_p(request)})
@ -522,12 +538,15 @@ def mute(request, id):
return render(request, 'main/mute.html', return render(request, 'main/mute.html',
{"user": user_dict, "relationship": relationship, {"user": user_dict, "relationship": relationship,
"confirm_page": True, "confirm_page": True,
'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)}) 'fullbrutalism': fullbrutalism_p(request)})
def search(request): def search(request):
return render(request, 'main/search.html', return render(request, 'main/search.html',
{"fullbrutalism": fullbrutalism_p(request)}) {"fullbrutalism": fullbrutalism_p(request),
'own_acct': request.session['user'],
})
def search_results(request): def search_results(request):
if request.method == 'GET': if request.method == 'GET':
@ -540,11 +559,15 @@ def search_results(request):
results = mastodon.search(query) results = mastodon.search(query)
return render(request, 'main/search_results.html', return render(request, 'main/search_results.html',
{"results": results, {"results": results,
'own_acct': request.session['user'],
"fullbrutalism": fullbrutalism_p(request)}) "fullbrutalism": fullbrutalism_p(request)})
def about(request): def about(request):
return render(request, 'about.html', return render(request, 'about.html',
{"fullbrutalism": fullbrutalism_p(request)}) {"fullbrutalism": fullbrutalism_p(request),
'own_acct': request.session.get('user', None),
})
def privacy(request): def privacy(request):
return render(request, 'privacy.html', return render(request, 'privacy.html',
{"fullbrutalism": fullbrutalism_p(request)}) {"fullbrutalism": fullbrutalism_p(request),
'own_acct' : request.session['user']})