implementing a feed for logged in users

main
lza_menace 3 years ago
parent bbaea9cc13
commit 531522e95f

@ -12,3 +12,4 @@ requests
SQLAlchemy
WTForms
quart
monero

@ -74,6 +74,7 @@ class BackerProfile(pw.Model):
recurring emails and/or notifications. For now.
"""
id = pw.AutoField()
user = pw.ForeignKeyField(User, backref='backer_profile')
register_date = pw.DateTimeField(default=datetime.now)
last_login_date = pw.DateTimeField(default=datetime.now)
email = pw.CharField(unique=True, null=True)

@ -1,8 +1,30 @@
from quart import Blueprint, render_template
from flask_login import current_user
from xmrbackers.models import CreatorProfile, Subscription, TextPost
bp = Blueprint('meta', 'meta')
@bp.route('/')
async def index():
return await render_template('index.html')
feed = None
if current_user.is_authenticated:
backer = current_user.backer_profile.first()
new_creators = CreatorProfile.select().where(
CreatorProfile.verified == True
).order_by(CreatorProfile.create_date.desc()).execute()
active_subscriptions = Subscription.select().where(
Subscription.active == True,
Subscription.backer == backer
).order_by(Subscription.subscribe_date.desc()).execute()
new_posts = TextPost.select().where(
TextPost.hidden == False,
TextPost.creator in [c.creator for c in active_subscriptions]
).order_by(TextPost.post_date.desc()).execute()
feed = {
'new_creators': [i.user.username for i in new_creators],
'new_posts': [i.title for i in new_posts],
'active_subscriptions': [i.id for i in active_subscriptions]
}
return await render_template('index.html', feed=feed)

@ -8,6 +8,13 @@
{% include 'includes/header.html' %}
{% if feed %}
{% for k in feed %}
<h2>{{ k }}</h2>
<p>{{ feed[k]}}</p>
{% endfor %}
{% else %}
<section id="banner">
<div class="content">
<header>
@ -17,6 +24,8 @@
</div>
</section>
{% endif %}
{% include 'includes/footer.html' %}
</div>

Loading…
Cancel
Save