mirror of
https://github.com/Xevion/v1.xevion.dev.git
synced 2025-12-06 21:16:56 -06:00
moved panzer into separate file, added 404 error handler, removed profile html page
This commit is contained in:
34
app/panzer.py
Normal file
34
app/panzer.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from app import app
|
||||
from textwrap import wrap
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from io import BytesIO
|
||||
import flask
|
||||
|
||||
@app.route('/panzer/')
|
||||
@app.route('/panzer')
|
||||
@app.route('/panzer/<string>')
|
||||
@app.route('/panzer/<string>/')
|
||||
def panzer(string='bionicles are cooler than sex'):
|
||||
string = string.replace('+', ' ')
|
||||
string = string.replace('\n', '%0A')
|
||||
image = create_panzer(string)
|
||||
return serve_pil_image(image)
|
||||
|
||||
def create_panzer(string):
|
||||
img = Image.open("./app/static/panzer.jpeg")
|
||||
draw = ImageDraw.Draw(img)
|
||||
font1 = ImageFont.truetype('./app/static/arial.ttf', size=30)
|
||||
draw.text((10, 20), 'Oh panzer of the lake, what is your wisdom?', font=font1)
|
||||
font2 = ImageFont.truetype('./app/static/arial.ttf', size=30)
|
||||
topleft = (250, 500)
|
||||
wrapped = wrap(string, width=25)
|
||||
wrapped = [text.replace('%0A', '\n') for text in wrapped]
|
||||
for y, text in enumerate(wrapped):
|
||||
draw.text((topleft[0], topleft[1] + (y * 33)), text, font=font2)
|
||||
return img
|
||||
|
||||
def serve_pil_image(pil_img):
|
||||
img_io = BytesIO()
|
||||
pil_img.save(img_io, 'JPEG', quality=50)
|
||||
img_io.seek(0)
|
||||
return flask.send_file(img_io, mimetype='image/jpeg')
|
||||
@@ -5,9 +5,6 @@ from app.custom import require_role
|
||||
from werkzeug.urls import url_parse
|
||||
from flask import render_template, redirect, url_for, flash, request, jsonify, abort, send_file
|
||||
from flask_login import current_user, login_user, logout_user, login_required
|
||||
from io import BytesIO
|
||||
from textwrap import wrap
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from multiprocessing import Value
|
||||
import flask
|
||||
import requests
|
||||
@@ -76,40 +73,6 @@ def getAvatar(id=''):
|
||||
url = cdn.format(id, user['avatar'])
|
||||
return "<img src=\"{}\">".format(url)
|
||||
|
||||
def serve_pil_image(pil_img):
|
||||
img_io = BytesIO()
|
||||
pil_img.save(img_io, 'JPEG', quality=50)
|
||||
img_io.seek(0)
|
||||
return flask.send_file(img_io, mimetype='image/jpeg')
|
||||
|
||||
@app.route('/panzer/')
|
||||
@app.route('/panzer')
|
||||
@app.route('/panzer/<string>')
|
||||
@app.route('/panzer/<string>/')
|
||||
def panzer(string='bionicles are cooler than sex'):
|
||||
string = string.replace('+', ' ')
|
||||
string = string.replace('\n', '%0A')
|
||||
image = create_panzer(string)
|
||||
return serve_pil_image(image)
|
||||
|
||||
def create_panzer(string):
|
||||
img = Image.open("./app/static/panzer.jpeg")
|
||||
draw = ImageDraw.Draw(img)
|
||||
font1 = ImageFont.truetype('./app/static/arial.ttf', size=30)
|
||||
draw.text((10, 20), 'Oh panzer of the lake, what is your wisdom?', font=font1)
|
||||
font2 = ImageFont.truetype('./app/static/arial.ttf', size=30)
|
||||
topleft = (250, 500)
|
||||
wrapped = wrap(string, width=25)
|
||||
wrapped = [text.replace('%0A', '\n') for text in wrapped]
|
||||
for y, text in enumerate(wrapped):
|
||||
draw.text((topleft[0], topleft[1] + (y * 33)), text, font=font2)
|
||||
return img
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(e):
|
||||
# note that we set the 404 status explicitly
|
||||
return render_template('404.html'), 404
|
||||
|
||||
@app.route('/userinfo/')
|
||||
@login_required
|
||||
@require_role(roles=['Admin'])
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from app import app
|
||||
from flask import send_from_directory, redirect, url_for
|
||||
from flask import send_from_directory, redirect, url_for, render_template
|
||||
import mistune
|
||||
import os
|
||||
|
||||
@@ -19,4 +19,9 @@ def favicon():
|
||||
|
||||
@app.errorhandler(401)
|
||||
def unauthorized(e):
|
||||
return redirect(url_for('login'))
|
||||
return redirect(url_for('login'))
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(e):
|
||||
# note that we set the 404 status explicitly
|
||||
return render_template('404.html'), 404
|
||||
@@ -5,10 +5,10 @@
|
||||
<div class="hero-body">
|
||||
<div class="container has-text-centered">
|
||||
<p class="title">
|
||||
404
|
||||
{{ code }}
|
||||
</p>
|
||||
<p class="subtitle">
|
||||
Content Not Found... <a href="{{ url_for('index') }}">Go home?</a>
|
||||
{{ message }} <em href="{{ url_for('index') }}">Go home?</em>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block body %}
|
||||
|
||||
<section class="section section-padding">
|
||||
<div class="container">
|
||||
<div class="columns is-mobile is-multiline is-centered">
|
||||
<!-- Options Card -->
|
||||
<div class="column is-4">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<div class="card-header-title">
|
||||
{{ user.username }}'s Profile
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
|
||||
<div class="row align-items-center" style="margin-left: 0px; ">
|
||||
<div class="form-group">
|
||||
<!-- Username -->
|
||||
<div class="row mt-4">
|
||||
<div class="col-auto">
|
||||
<label class="mb-1" style="width: 80px;">
|
||||
Username
|
||||
</label>
|
||||
<label style="font-weight: bold;">
|
||||
{{ user.username }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if user.show_email or current_user.has_role('hidden') %}
|
||||
<div class="row mt-3">
|
||||
<div class="col-auto">
|
||||
<label class="mb-1" style="width: 80px;">
|
||||
Email
|
||||
</label>
|
||||
<label style="font-weight: bold;">
|
||||
{{ user.email or '-' }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="row mt-3">
|
||||
<div class="col-auto">
|
||||
<label class="mb-1" style="width: 80px;">
|
||||
Phone
|
||||
</label>
|
||||
<label style="font-weight: bold;">
|
||||
{{ user.phone_number or '-' }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row align-items-center" style="margin-left: -10px; ">
|
||||
<div class="col-auto">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- End Options Card -->
|
||||
</div>
|
||||
<!-- Card Column Content -->
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{% endblock body %}}
|
||||
Reference in New Issue
Block a user