setting up routes and templates for creators

main
lza_menace 3 years ago
parent 531522e95f
commit 3a3037b82a

@ -13,3 +13,4 @@ SQLAlchemy
WTForms WTForms
quart quart
monero monero
arrow

@ -20,12 +20,13 @@ def create_app():
app.config.from_envvar('QUART_SECRETS') app.config.from_envvar('QUART_SECRETS')
@app.before_serving @app.before_serving
async def startup(): async def startup():
from xmrbackers.routes import meta, api, auth from xmrbackers.routes import meta, api, auth, creator
from xmrbackers import filters from xmrbackers import filters
await _setup_db(app) await _setup_db(app)
app.register_blueprint(meta.bp) app.register_blueprint(meta.bp)
app.register_blueprint(api.bp) app.register_blueprint(api.bp)
app.register_blueprint(auth.bp) app.register_blueprint(auth.bp)
app.register_blueprint(creator.bp)
app.register_blueprint(filters.bp) app.register_blueprint(filters.bp)
login_manager = LoginManager(app) login_manager = LoginManager(app)

@ -1,3 +1,4 @@
import arrow
from datetime import datetime from datetime import datetime
from quart import Blueprint, current_app from quart import Blueprint, current_app
@ -6,6 +7,10 @@ from quart import Blueprint, current_app
bp = Blueprint('filters', 'filters') bp = Blueprint('filters', 'filters')
@bp.app_template_filter('humanize')
def humanize(d):
return arrow.get(d).humanize()
@bp.app_template_filter('ts') @bp.app_template_filter('ts')
def from_ts(v): def from_ts(v):
return datetime.fromtimestamp(v) return datetime.fromtimestamp(v)

@ -55,7 +55,6 @@ class CreatorProfile(pw.Model):
id = pw.AutoField() id = pw.AutoField()
user = pw.ForeignKeyField(User) user = pw.ForeignKeyField(User)
create_date = pw.DateTimeField(default=datetime.now) create_date = pw.DateTimeField(default=datetime.now)
last_login_date = pw.DateTimeField(default=datetime.now)
wallet_address = pw.CharField(null=True) wallet_address = pw.CharField(null=True)
website = pw.CharField(null=True) website = pw.CharField(null=True)
twitter_handle = pw.CharField(null=True) twitter_handle = pw.CharField(null=True)

@ -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/<username>')
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'))

@ -0,0 +1,23 @@
<!DOCTYPE HTML>
<html>
{% include 'includes/head.html' %}
<body class="is-preload landing">
<div id="page-wrapper">
{% include 'includes/header.html' %}
{% if creator %}
<h1>{{ creator.user.username }}</h1>
<p>Bio: {{ creator.bio }}</p>
{% endif %}
{% include 'includes/footer.html' %}
</div>
{% include 'includes/scripts.html' %}
</body>
</html>

@ -0,0 +1,27 @@
<!DOCTYPE HTML>
<html>
{% include 'includes/head.html' %}
<body class="is-preload landing">
<div id="page-wrapper">
{% include 'includes/header.html' %}
{% if creators %}
<h1>All Creators</h1>
<ul>
{% for c in creators %}
<li><a href="{{ url_for('creator.show', username=c.user.username) }}">{{ c.user.username }}</a> - profile created {{ c.create_date | humanize }}</li>
{% endfor %}
</ul>
{% endif %}
{% include 'includes/footer.html' %}
</div>
{% include 'includes/scripts.html' %}
</body>
</html>

@ -15,6 +15,8 @@
{% endif %} {% endif %}
</header> </header>
<hr>
<script src="/static/js/noty.js"></script> <script src="/static/js/noty.js"></script>
{% with messages = get_flashed_messages() %} {% with messages = get_flashed_messages() %}
{% if messages %} {% if messages %}

@ -11,7 +11,11 @@
{% if feed %} {% if feed %}
{% for k in feed %} {% for k in feed %}
<h2>{{ k }}</h2> <h2>{{ k }}</h2>
<p>{{ feed[k]}}</p> {% if k == 'new_creators' %}
<p><a href="{{ url_for('creator.show', username=feed[k]) }}">{{ feed[k] }}</a></p>
{% else %}
<p>{{ feed[k]}}</p>
{% endif %}
{% endfor %} {% endfor %}
{% else %} {% else %}

Loading…
Cancel
Save