feat/show replies

This commit is contained in:
SouthFox 2022-09-22 23:57:43 +08:00
parent e361d8cb43
commit 10aae23726
3 changed files with 50 additions and 14 deletions

View file

@ -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;

View file

@ -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,7 +73,10 @@
</div> </div>
</div> </div>
</div> </div>
{% endfor %} {%- if toot.reply -%}
<div class="reply">{{ loop(toot.reply) }}</div>
{%- endif %}
{% endfor %}
<div class="pagination d-flex justify-content-center"> <div class="pagination d-flex justify-content-center">
{% if pagination %} {% if pagination %}

View file

@ -11,21 +11,25 @@ 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():
page = request.args.get('page', 1, type=int) settings = Settings.query.first()
toots_ = Toot.query.order_by(Toot.created_at.desc()).paginate(page, per_page=50) if settings == None:
toots = process_toot(toots_) return redirect(url_for('settings'))
path=SimpleNamespace() else:
path.path = "index" page = request.args.get('page', 1, type=int)
path.args = {} toots_ = Toot.query.order_by(Toot.created_at.desc()).paginate(page, per_page=50)
toots = process_toot(toots_)
path=SimpleNamespace()
path.path = "index"
path.args = {}
return render_template('view.html', toots=toots, pagination=toots_, path=path) return render_template('view.html', toots=toots, pagination=toots_, path=path)
@app.route('/search', methods=['GET', 'POST']) @app.route('/search', methods=['GET', 'POST'])
def search(): def search():
@ -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)