feat/show replies
This commit is contained in:
parent
e361d8cb43
commit
10aae23726
3 changed files with 50 additions and 14 deletions
|
@ -11,6 +11,13 @@ body {
|
||||||
border-top: 1px solid #393f4f;
|
border-top: 1px solid #393f4f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.reply {
|
||||||
|
padding-left: 30px;
|
||||||
|
border-left: 3px solid;
|
||||||
|
border-radius: 3px 0 0 3px;
|
||||||
|
background: #f2f0ea;
|
||||||
|
}
|
||||||
|
|
||||||
.meta .time {
|
.meta .time {
|
||||||
float: right;
|
float: right;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% for toot in toots %}
|
{% for toot in toots recursive%}
|
||||||
<div class="toot">
|
<div class="toot">
|
||||||
<div class="status">
|
<div class="status">
|
||||||
<div class="meta">
|
<div class="meta">
|
||||||
|
@ -73,6 +73,9 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{%- if toot.reply -%}
|
||||||
|
<div class="reply">{{ loop(toot.reply) }}</div>
|
||||||
|
{%- endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
<div class="pagination d-flex justify-content-center">
|
<div class="pagination d-flex justify-content-center">
|
||||||
|
|
|
@ -11,13 +11,17 @@ from mastodon import Mastodon
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
from datetime import timezone
|
from datetime import timezone
|
||||||
|
|
||||||
@app.context_processor
|
# @app.context_processor
|
||||||
def inject_setting():
|
# def inject_setting():
|
||||||
settings = Settings.query.first()
|
# settings = Settings.query.first()
|
||||||
return settings.__dict__
|
# return settings.__dict__
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def index():
|
def index():
|
||||||
|
settings = Settings.query.first()
|
||||||
|
if settings == None:
|
||||||
|
return redirect(url_for('settings'))
|
||||||
|
else:
|
||||||
page = request.args.get('page', 1, type=int)
|
page = request.args.get('page', 1, type=int)
|
||||||
toots_ = Toot.query.order_by(Toot.created_at.desc()).paginate(page, per_page=50)
|
toots_ = Toot.query.order_by(Toot.created_at.desc()).paginate(page, per_page=50)
|
||||||
toots = process_toot(toots_)
|
toots = process_toot(toots_)
|
||||||
|
@ -45,6 +49,25 @@ def search():
|
||||||
return render_template('view.html', toots=toots, pagination=toots_, path=path)
|
return render_template('view.html', toots=toots, pagination=toots_, path=path)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/context/<int:toot_id>', methods=['GET', 'POST'])
|
||||||
|
def context(toot_id):
|
||||||
|
def get_reply(reply_id):
|
||||||
|
toots = Toot.query.order_by(Toot.created_at.desc()).filter_by(in_reply_to_id=reply_id).all()
|
||||||
|
toots = process_toot(toots)
|
||||||
|
|
||||||
|
for i in toots:
|
||||||
|
if i.in_reply_to_id != None:
|
||||||
|
i.reply = get_reply(i.id)
|
||||||
|
|
||||||
|
return toots
|
||||||
|
|
||||||
|
toot = []
|
||||||
|
toot.append(Toot.query.get_or_404(toot_id))
|
||||||
|
toot = process_toot(toot)
|
||||||
|
toot[0].reply = get_reply(toot_id)
|
||||||
|
|
||||||
|
return render_template('view.html', toots=toot,)
|
||||||
|
|
||||||
@app.route('/settings', methods=['GET', 'POST'])
|
@app.route('/settings', methods=['GET', 'POST'])
|
||||||
def settings():
|
def settings():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
@ -129,7 +152,10 @@ def process_toot(toots_):
|
||||||
user_timezone = pytz.timezone(settings.timezone)
|
user_timezone = pytz.timezone(settings.timezone)
|
||||||
fmt = '%Y-%m-%d %H:%M:%S'
|
fmt = '%Y-%m-%d %H:%M:%S'
|
||||||
|
|
||||||
for toot_ in toots_.items:
|
if hasattr(toots_, 'items'):
|
||||||
|
toots_ = toots_.items
|
||||||
|
|
||||||
|
for toot_ in toots_:
|
||||||
toot = SimpleNamespace(**toot_.__dict__)
|
toot = SimpleNamespace(**toot_.__dict__)
|
||||||
|
|
||||||
toot.created_at = toot.created_at.replace(tzinfo=timezone.utc)
|
toot.created_at = toot.created_at.replace(tzinfo=timezone.utc)
|
||||||
|
|
Loading…
Reference in a new issue