commit 6fb63b1614bea44befce80b6d6ca72c1b0f859f2
parent acb3d5a00300f2e97c009a211f91f3cac4dd7e14
Author: parazyd <parazyd@dyne.org>
Date: Sun, 20 Jan 2019 15:26:24 +0100
Autofill some values if a user's logged in when writing a story.
Diffstat:
3 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/diaspora.py b/diaspora.py
@@ -47,6 +47,7 @@ class LoginUser(UserMixin):
"""
Class for a user
"""
+ # TODO: Find out if it's possible to do less SQL queries.
def __init__(self, uid):
""" Init """
self.uid = uid
@@ -58,6 +59,12 @@ class LoginUser(UserMixin):
return user['email']
@property
+ def name(self):
+ """ Name """
+ user = self.get_user()
+ return user['name']
+
+ @property
def is_admin(self):
""" Check capabilities """
user = self.get_user()
diff --git a/templates/view.html b/templates/view.html
@@ -11,6 +11,11 @@
<h1 class="cover-heading">{{ story['name'] }} in {{ story['disembarkname'] }}</h1>
<p>by {{ story['name'] }}, {{ story['date'] }} {{ story['time'] }}</p>
+ {% if current_user.is_admin %}
+ <hr style="width:100%; height: 2px;">
+ <a href="/edit?id={{ story['id'] }}" class="btn btn-sm btn-outline-secondary">Edit</a>
+ <a href="/dashboard?hideid={{ story['id'] }}" class="btn btn-sm btn-outline-secondary">Hide</a>
+ {% endif %}
<hr style="width: 100%; height: 2px;">
{{ story['story']|safe }}
diff --git a/templates/write.html b/templates/write.html
@@ -22,7 +22,11 @@
<form action="/write" method="POST" id="storyform">
<p class="lead">Name:<br>
+ {% if current_user.name %}
+ <input type="text" name="Name" required value="{{ current_user.name }}">
+ {% else %}
<input type="text" name="Name" required placeholder="Name">
+ {% endif %}
</p>
<p class="lead">Country of embarkment:<br>
@@ -44,7 +48,11 @@
</p>
<p class="lead">Email:<br>
+ {% if current_user.username %}
+ <input type="email" name="Email" value="{{ current_user.username }}">
+ {% else %}
<input type="email" name="Email" placeholder="Email (optional)">
+ {% endif %}
</p>
<input type="text" name="42" placeholder="Yeah sure" style="display: none;">