diff --git a/requirements.txt b/requirements.txt index c6b34de..c800243 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,3 +12,4 @@ requests SQLAlchemy WTForms quart +monero diff --git a/xmrbackers/models.py b/xmrbackers/models.py index 68bd310..a92652b 100644 --- a/xmrbackers/models.py +++ b/xmrbackers/models.py @@ -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) diff --git a/xmrbackers/routes/meta.py b/xmrbackers/routes/meta.py index 36cd545..2234251 100644 --- a/xmrbackers/routes/meta.py +++ b/xmrbackers/routes/meta.py @@ -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) diff --git a/xmrbackers/templates/index.html b/xmrbackers/templates/index.html index 59179f7..cc6681e 100644 --- a/xmrbackers/templates/index.html +++ b/xmrbackers/templates/index.html @@ -8,6 +8,13 @@ {% include 'includes/header.html' %} + {% if feed %} + {% for k in feed %} +

{{ k }}

+

{{ feed[k]}}

+ {% endfor %} + {% else %} + + {% endif %} + {% include 'includes/footer.html' %}