From 84f123a0ab529ac8a649e0e0ca4a49fd0c828db3 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 18 Mar 2018 18:14:55 +0000 Subject: [PATCH] Fix profile page --- app/templates/macros/forms.html | 42 +++++++++++++ app/templates/users/user_profile_page.html | 72 ++++++++++++++++++++++ app/views/users.py | 12 +--- 3 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 app/templates/macros/forms.html create mode 100644 app/templates/users/user_profile_page.html diff --git a/app/templates/macros/forms.html b/app/templates/macros/forms.html new file mode 100644 index 00000000..a2b75a7a --- /dev/null +++ b/app/templates/macros/forms.html @@ -0,0 +1,42 @@ +{% macro render_field(field, label=None, label_visible=true, right_url=None, right_label=None) -%} +
+ {% if field.type != 'HiddenField' and label_visible %} + {% if not label %}{% set label=field.label.text %}{% endif %} + + {% endif %} + {{ field(class_='form-control', **kwargs) }} + {% if field.errors %} + {% for e in field.errors %} +

{{ e }}

+ {% endfor %} + {% endif %} +
+{%- endmacro %} + +{% macro render_checkbox_field(field, label=None) -%} + {% if not label %}{% set label=field.label.text %}{% endif %} +
+ +
+{%- endmacro %} + +{% macro render_radio_field(field) -%} + {% for value, label, checked in field.iter_choices() %} +
+ +
+ {% endfor %} +{%- endmacro %} + +{% macro render_submit_field(field, label=None, tabindex=None) -%} + {% if not label %}{% set label=field.label.text %}{% endif %} + {##} + +{%- endmacro %} diff --git a/app/templates/users/user_profile_page.html b/app/templates/users/user_profile_page.html new file mode 100644 index 00000000..0eb6adb5 --- /dev/null +++ b/app/templates/users/user_profile_page.html @@ -0,0 +1,72 @@ +{% extends "base.html" %} + +{% block title %} + {{ user.username }} +{% endblock %} + +{% block content %} + +
+

{{ user.username }}

+ + + + + + + {% if user == current_user %} + + + + + + + + + {% endif %} +
Accounts: + {% if user.forums_username %} + + Minetest Forum + + {% elif user == current_user %} + Link Forums Account + {% endif %} + | + {% if user.github_username %} + GitHub + {% elif user == current_user %} + Link Github + {% endif %} + + {% if user == current_user %} + 🌎 + {% endif %} +
Email: + {{ user.email }} | + {% if user.email %}change{% else %}add{% endif %} + 🔒 +
Password: + + {% if user.password %}Change password{% else %}Add password{% endif %} + 🔒 +
+
+ +{% if form %} + {% from "macros/forms.html" import render_field, render_submit_field %} +
+

Edit Details

+ +
+
+ {{ form.hidden_tag() }} + + {{ render_field(form.display_name, tabindex=240) }} + + {{ render_submit_field(form.submit, tabindex=280) }} +
+
+
+{% endif %} +{% endblock %} diff --git a/app/views/users.py b/app/views/users.py index 99cf19c4..1dc5e296 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -13,17 +13,11 @@ from flask_user.forms import RegisterForm from flask_wtf import FlaskForm from wtforms import StringField, SubmitField, validators class MyRegisterForm(RegisterForm): - first_name = StringField('First name', validators=[ - validators.DataRequired('First name is required')]) - last_name = StringField('Last name', validators=[ - validators.DataRequired('Last name is required')]) + display_name = StringField("Diplay name") # Define the User profile form class UserProfileForm(FlaskForm): - first_name = StringField('First name', validators=[ - validators.DataRequired('First name is required')]) - last_name = StringField('Last name', validators=[ - validators.DataRequired('Last name is required')]) + display_name = StringField("Diplay name") submit = SubmitField('Save') @app.route('/user/', methods=['GET', 'POST']) @@ -42,7 +36,7 @@ def user_profile_page(username=None): if user == current_user: # Initialize form - form = UserProfileForm(request.form, current_user) + form = UserProfileForm(formdata=request.form, obj=current_user) # Process valid POST if request.method=='POST' and form.validate():