From 3a3037b82a482e90d30434534f12eb3512a28d5d Mon Sep 17 00:00:00 2001 From: lza_menace Date: Fri, 2 Jul 2021 09:35:58 -0700 Subject: [PATCH] setting up routes and templates for creators --- requirements.txt | 1 + xmrbackers/factory.py | 3 ++- xmrbackers/filters.py | 5 ++++ xmrbackers/models.py | 1 - xmrbackers/routes/creator.py | 25 ++++++++++++++++++++ xmrbackers/templates/creator/creator.html | 23 ++++++++++++++++++ xmrbackers/templates/creator/creators.html | 27 ++++++++++++++++++++++ xmrbackers/templates/includes/header.html | 2 ++ xmrbackers/templates/index.html | 6 ++++- 9 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 xmrbackers/routes/creator.py create mode 100644 xmrbackers/templates/creator/creator.html create mode 100644 xmrbackers/templates/creator/creators.html diff --git a/requirements.txt b/requirements.txt index c800243..5e78128 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,3 +13,4 @@ SQLAlchemy WTForms quart monero +arrow diff --git a/xmrbackers/factory.py b/xmrbackers/factory.py index bb4e902..b73ea54 100644 --- a/xmrbackers/factory.py +++ b/xmrbackers/factory.py @@ -20,12 +20,13 @@ def create_app(): app.config.from_envvar('QUART_SECRETS') @app.before_serving async def startup(): - from xmrbackers.routes import meta, api, auth + from xmrbackers.routes import meta, api, auth, creator from xmrbackers import filters await _setup_db(app) app.register_blueprint(meta.bp) app.register_blueprint(api.bp) app.register_blueprint(auth.bp) + app.register_blueprint(creator.bp) app.register_blueprint(filters.bp) login_manager = LoginManager(app) diff --git a/xmrbackers/filters.py b/xmrbackers/filters.py index cb015bd..8434efd 100644 --- a/xmrbackers/filters.py +++ b/xmrbackers/filters.py @@ -1,3 +1,4 @@ +import arrow from datetime import datetime from quart import Blueprint, current_app @@ -6,6 +7,10 @@ from quart import Blueprint, current_app bp = Blueprint('filters', 'filters') +@bp.app_template_filter('humanize') +def humanize(d): + return arrow.get(d).humanize() + @bp.app_template_filter('ts') def from_ts(v): return datetime.fromtimestamp(v) diff --git a/xmrbackers/models.py b/xmrbackers/models.py index a92652b..f782b01 100644 --- a/xmrbackers/models.py +++ b/xmrbackers/models.py @@ -55,7 +55,6 @@ class CreatorProfile(pw.Model): id = pw.AutoField() user = pw.ForeignKeyField(User) create_date = pw.DateTimeField(default=datetime.now) - last_login_date = pw.DateTimeField(default=datetime.now) wallet_address = pw.CharField(null=True) website = pw.CharField(null=True) twitter_handle = pw.CharField(null=True) diff --git a/xmrbackers/routes/creator.py b/xmrbackers/routes/creator.py new file mode 100644 index 0000000..6c7c43e --- /dev/null +++ b/xmrbackers/routes/creator.py @@ -0,0 +1,25 @@ +from quart import Blueprint, render_template, flash, redirect + +from xmrbackers.models import User, CreatorProfile + + +bp = Blueprint('creator', 'creator') + +@bp.route('/creators') +async def all(): + creators = CreatorProfile.select().order_by( + CreatorProfile.create_date.desc() + ) + return await render_template('creator/creators.html', creators=creators) + +@bp.route('/creator/') +async def show(username): + user = User.select().where(User.username == username) + creator = CreatorProfile.select().where( + CreatorProfile.user == user + ).first() + if creator: + return await render_template('creator/creator.html', creator=creator) + else: + flash('That creator does not exist.') + return redirect(url_for('meta.index')) diff --git a/xmrbackers/templates/creator/creator.html b/xmrbackers/templates/creator/creator.html new file mode 100644 index 0000000..a1005a2 --- /dev/null +++ b/xmrbackers/templates/creator/creator.html @@ -0,0 +1,23 @@ + + + + {% include 'includes/head.html' %} + + +
+ + {% include 'includes/header.html' %} + + {% if creator %} +

{{ creator.user.username }}

+

Bio: {{ creator.bio }}

+ {% endif %} + + {% include 'includes/footer.html' %} + +
+ + {% include 'includes/scripts.html' %} + + + diff --git a/xmrbackers/templates/creator/creators.html b/xmrbackers/templates/creator/creators.html new file mode 100644 index 0000000..967fe60 --- /dev/null +++ b/xmrbackers/templates/creator/creators.html @@ -0,0 +1,27 @@ + + + + {% include 'includes/head.html' %} + + +
+ + {% include 'includes/header.html' %} + + {% if creators %} +

All Creators

+
    + {% for c in creators %} +
  • {{ c.user.username }} - profile created {{ c.create_date | humanize }}
  • + {% endfor %} +
+ {% endif %} + + {% include 'includes/footer.html' %} + +
+ + {% include 'includes/scripts.html' %} + + + diff --git a/xmrbackers/templates/includes/header.html b/xmrbackers/templates/includes/header.html index 034359f..b454fd6 100644 --- a/xmrbackers/templates/includes/header.html +++ b/xmrbackers/templates/includes/header.html @@ -15,6 +15,8 @@ {% endif %} +
+ {% with messages = get_flashed_messages() %} {% if messages %} diff --git a/xmrbackers/templates/index.html b/xmrbackers/templates/index.html index cc6681e..9205c7c 100644 --- a/xmrbackers/templates/index.html +++ b/xmrbackers/templates/index.html @@ -11,7 +11,11 @@ {% if feed %} {% for k in feed %}

{{ k }}

-

{{ feed[k]}}

+ {% if k == 'new_creators' %} +

{{ feed[k] }}

+ {% else %} +

{{ feed[k]}}

+ {% endif %} {% endfor %} {% else %}