broken profile settings

This commit is contained in:
Xevion
2019-07-11 23:03:47 -05:00
parent e7b05ee4f9
commit 4b2d3aab53
4 changed files with 40 additions and 20 deletions

View File

@@ -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

View File

@@ -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):

View File

@@ -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'])

View File

@@ -4,7 +4,7 @@
{{ super() }}
<script>
$(document).ready(function () {
$('#form-ajax').submit(function (e) {
$('#psform-ajax').submit(function (e) {
var url = "{{ url_for('profile_settings_submit') }}"; // send the form data here.
$.ajax({
type: "POST",
@@ -20,7 +20,7 @@
$.ajaxSetup({
beforeSend: function (xhr, settings) {
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", "{{ form.csrf_token._value() }}")
xhr.setRequestHeader("X-CSRFToken", "{{ psform.csrf_token._value() }}")
}
}
})
@@ -31,6 +31,11 @@
padding-left: 3rem;
}
</style>
<style type="text/css">
.tab-left {
padding-left: 3rem;
}
</style>
{% endblock head %}
{% block dashboard_body %}
@@ -38,17 +43,17 @@
<h1 class="title">Profile Settings</h1>
<!-- Profile Email Settings Form -->
<form class="form-ajax" action="" method="POST" novalidate>
{{ form.hidden_tag() }}
{{ psform.hidden_tag() }}
<div class="field tab-left">
<h4 class="title is-4">{{ form.show_email.label }}</h4>
{{ form.show_email(class="radio") }}
<h4 class="title is-4">{{ psform.show_email.label }}</h4>
{{ psform.show_email(class="radio") }}
</div>
</form>
<!-- Profile Picture Form -->
<form class="form-ajax" action="" method="POST" novalidate>
{{ form.hidden_tag() }}
<h4 class="title is-4">{{ form.profile_picture_file.label }}</h4>
{{ form.profile_picture_file(class="") }}
{{ ppform.hidden_tag() }}
<h4 class="title is-4">{{ ppform.profile_picture_file.label }}</h4>
{{ ppform.profile_picture_file(class="") }}
<div class="field tab-left">
<div class="file">
<label class="file-label">
@@ -65,7 +70,7 @@
</div>
</div>
{{ form.submit(class="button is-danger") }}
{{ ppform.submit(class="button is-danger") }}
</form>
</section>
{% endblock dashboard_body %}