diff --git a/app/dashboard.py b/app/dashboard.py index 1f7fcf7..2d6c245 100644 --- a/app/dashboard.py +++ b/app/dashboard.py @@ -1,5 +1,5 @@ from app import app, db, login -from app.forms import ProfileSettingsForm +from app.forms import ProfileSettingsForm, ProfilePictureForm from app.models import User, Search from app.custom import require_role from flask import render_template, redirect, url_for, request, jsonify @@ -13,8 +13,9 @@ def dashboard(): @app.route('/dashboard/profile_settings', methods=['GET']) @login_required def profile_settings(): - form = ProfileSettingsForm() - return render_template('/dashboard/profile_settings.html', form=form) + psform = ProfileSettingsForm() + ppform = ProfilePictureForm() + return render_template('/dashboard/profile_settings.html', psform=psform, ppform=ppform) @app.route('/dashboard/profile_settings/submit', methods=['POST']) @login_required diff --git a/app/forms.py b/app/forms.py index 7c33ba3..f165a93 100644 --- a/app/forms.py +++ b/app/forms.py @@ -28,7 +28,6 @@ class RegistrationForm(FlaskForm): class ProfileSettingsForm(FlaskForm): show_email = RadioField('Show Email', default='registered', choices=[('public', 'Public'), ('registered', 'Registered Users Only'), ('hidden', 'Hidden')]) - submit = SubmitField('Save Profile Settings') class ProfilePictureForm(FlaskForm): diff --git a/app/routes.py b/app/routes.py index 1b7e5b7..6f9dbbe 100644 --- a/app/routes.py +++ b/app/routes.py @@ -6,6 +6,7 @@ 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 import requests import xmltodict @@ -17,8 +18,7 @@ import json fake = faker.Faker() -def strgen(length): - return ''.join(random.choices(list(string.ascii_letters), k=length)) +strgen = lambda length, charset=string.ascii_letters, weights=None : ''.join(random.choices(list(charset), k=length, weights=weights)) @app.errorhandler(401) def unauthorized(e): @@ -41,9 +41,18 @@ def create_panzer(string): img = Image.open("./app/static/panzer.jpeg") draw = ImageDraw.Draw(img) font1 = ImageFont.truetype('./app/static/arial.ttf', size=30) - font2 = ImageFont.truetype('./app/static/arial.ttf', size=30) draw.text((10, 20), 'Oh panzer of the lake, what is your wisdom?', font=font1) - draw.text((250, 500), string, font=font2) + + font2 = ImageFont.truetype('./app/static/arial.ttf', size=30) + + w, h = img.size + lines = wrap(string, width=400) + y_text = h + for line in lines: + width, height = font2.getsize(line) + draw.text(((w - width) / 2, y_text), line, font=font2) + y_text += height + # draw.text((250, 500), string, font=font2) return img @@ -57,6 +66,8 @@ def api(): return 'fuckoff bots' @app.route('/userinfo/') +@login_required +@require_role(roles=['Admin']) def user_info(): prepare = { 'id' : current_user.get_id(), @@ -73,10 +84,14 @@ def user_info(): @app.route('/') def index(): - content = [{'text': fake.paragraph(nb_sentences=15), + # content = [{'text': fake.paragraph(nb_sentences=15), + # 'seed': random.randint(0, 1000), + # 'title': fake.word().title()} + # for _ in range(0)] + content = [{'title': 'Work in Progress', 'seed': random.randint(0, 1000), - 'title': fake.word().title()} - for _ in range(10)] + 'text': 'This portion of my website is still a work in progress. I don\'t know if and when it\'ll be done, or how it will turn out in the end. - Xevion @ (Jul-11-2019)'} + for _ in range(1)] return render_template('index.html', content=content) @app.route('/register/', methods=['GET', 'POST']) diff --git a/app/templates/dashboard/profile_settings.html b/app/templates/dashboard/profile_settings.html index f725416..7f1af74 100644 --- a/app/templates/dashboard/profile_settings.html +++ b/app/templates/dashboard/profile_settings.html @@ -4,7 +4,7 @@ {{ super() }}