get user page working

master
lza_menace 2 years ago
parent df449ad4ed
commit 119cc3a2fc

@ -2,7 +2,7 @@ from os import path
from datetime import datetime
from secrets import token_urlsafe
from flask import url_for
from flask_login import login_user
from PIL import Image, ImageSequence, ImageFilter
from cv2 import VideoCapture
@ -53,6 +53,11 @@ class User(pw.Model):
self.challenge = gen_challenge()
self.save()
def login(self):
login_user(self)
self.last_login_date = datetime.utcnow()
self.save()
class Meta:
database = db

@ -1,6 +1,6 @@
from flask import Blueprint, render_template
from flask import flash, redirect, url_for
from flask_login import login_user, logout_user, current_user
from flask_login import logout_user, current_user
from nerochan.forms import UserForm, UserRegistration, UserChallenge
from nerochan.helpers import make_wallet_rpc
@ -31,7 +31,7 @@ def register():
wallet_address=form.wallet_address.data,
)
user.save()
login_user(user)
user.login()
return redirect(url_for('main.index'))
return render_template("auth/register.html", form=form)
@ -77,7 +77,7 @@ def challenge(handle):
res = make_wallet_rpc('verify', data)
if res['good']:
user.regenerate_challenge()
login_user(user)
user.login()
flash('Successful login!')
return redirect(url_for('main.index'))
else:

@ -1,7 +1,9 @@
from flask import Blueprint, render_template, redirect, url_for, flash
from math import ceil
from flask import Blueprint, render_template, redirect, url_for, flash, request
from flask_login import login_required
from nerochan.models import User
from nerochan.models import User, Artwork, Transaction
bp = Blueprint('user', 'user')
@ -16,9 +18,29 @@ def show(handle: str):
if not user:
flash('That user does not exist.', 'warning')
return redirect(url_for('main.index'))
ipp = 20
page = request.args.get("page", 1)
try:
page = int(page)
except:
flash('Invalid page number provided.', 'warning')
page = 1
artwork = Artwork.select().where(
Artwork.user == user,
Artwork.approved == True,
Artwork.hidden == False
).order_by(Artwork.upload_date.desc())
# tips = Transaction.select().where(
# Transaction.verified == True,
# ) # need some join magic
paginated_posts = artwork.paginate(page, ipp)
total_pages = ceil(artwork.count() / ipp)
return render_template(
'user/show.html',
user=user
user=user,
artwork=paginated_posts,
page=page,
total_pages=total_pages
)
@bp.route('/profile')

@ -14,7 +14,7 @@
{%- for _artwork in artwork | batch(4) %}
{%- for art in _artwork %}
<a class="artworkLink" href="{{ url_for('artwork.show', id=art.id) }}">
<img src="{{ url_for('main.uploaded_file', filename=art.thumbnail) }}" width="150px">
<img src="{{ url_for('main.uploaded_file', filename=art.thumbnail) }}" width="150px" style="border: 1px solid white;">
</a>
{%- endfor %}
{%- endfor %}

@ -4,9 +4,54 @@
<div class="container">
<div class="row">
<h1>{{ user.handle }}</h1>
<p>User details</p>
<h2 class="no-margin"><strong>{{ user.handle }}</strong></h2>
<span>
{% if user.is_admin %}
<p class="inline nsfw">ADMIN</p>
{% endif %}
{% if user.is_verified %}
<p class="inline nsfw">VERIFIED</p>
{% endif %}
<h6 class="no-margin inline">
registered {{ user.register_date | humanize }} - last login {{ user.last_login_date | humanize }}
</h6>
</span>
<br />
<br />
<h6 class="walletAddress mt-2">{{ user.wallet_address }}</h6>
</div>
<hr>
<div class="row">
<h1>artworks</h1>
{% if artwork %}
{%- for _artwork in artwork | batch(4) %}
{%- for artwork in _artwork %}
<a class="artworkLink" href="{{ url_for('artwork.show', id=artwork.id) }}">
<img src="{{ url_for('main.uploaded_file', filename=artwork.thumbnail) }}" width="150px">
</a>
{%- endfor %}
{%- endfor %}
{% else %}
<p>There's nothing here yet...</p>
{% endif %}
</div>
{% if artwork %}
<div class="row mt-4">
<span class="inline">
{% for i in range(1, total_pages + 1) %}
<h6 class="inline">
{% if i == page %}
{{ page }}
{% else %}
<a href="?page={{ i }}">{{ i }}</a>
{% endif %}
</h6>
{% endfor %}
</span>
</div>
{% endif %}
</div>
{% endblock %}

Loading…
Cancel
Save