split profile view and profile edit into seperate routes and templates

This commit is contained in:
David Lenwell
2013-10-30 04:50:28 -07:00
parent 5d2b97e9a1
commit 79cba4a4fb
3 changed files with 66 additions and 4 deletions

View File

@@ -122,3 +122,12 @@ input[name="openid"] {
margin-right: 6px;
}
.red{
color: red;
}
.green{
color: #329000;
}

View File

@@ -0,0 +1,44 @@
{% extends "layout.html" %}
{% block title %}View Profile{% endblock %}
{% block body %}
<div class="panel panel-default unit one-of-two">
<div class="panel-heading">
<span class="glyphicon glyphicon-user"></span> {{ user.name }}'s profile
<a href="/profile/edit" style="float: right;">
<span class="glyphicon glyphicon-pencil"></span>
</a>
</div>
<table class="table">
<tr>
<td>
E-Mail:
</td>
<td >
{{ user.email }}
{% if user.email_verified %}
<span class="glyphicon glyphicon-ok-circle green" ></span>
{% else %}
<span class="glyphicon glyphicon-remove-circle red"></span>
{% endif %}
</td>
</tr>
<tr>
<td>
Authorized by Vendor:
</td>
<td >
{% if user.authorized %}
<span class="glyphicon glyphicon-ok-circle green" ></span>
{% else %}
<span class="glyphicon glyphicon-remove-circle red"></span>
{% endif %}
</td>
</tr>
</table>
</div>
{% endblock %}

View File

@@ -123,7 +123,7 @@ def create_profile():
'create_profile.html', next_url=oid.get_next_url())
@app.route('/profile', methods=['GET', 'POST'])
@app.route('/profile/edit', methods=['GET', 'POST'])
def edit_profile():
"""Updates a profile"""
if g.user is None:
@@ -131,8 +131,8 @@ def edit_profile():
form = dict(name=g.user.name, email=g.user.email)
if request.method == 'POST':
if 'delete' in request.form:
db.session.delete(g.user)
db.session.commit()
db.delete(g.user)
db.commit()
session['openid'] = None
flash(u'Profile deleted')
return redirect(url_for('index'))
@@ -146,11 +146,20 @@ def edit_profile():
flash(u'Profile successfully created')
g.user.name = form['name']
g.user.email = form['email']
db.session.commit()
db.commit()
return redirect(url_for('edit_profile'))
return render_template('edit_profile.html', form=form)
@app.route('/profile', methods=['GET', 'POST'])
def view_profile():
"""Updates a profile"""
if g.user is None:
abort(401)
return render_template('view_profile.html', user=g.user)
@app.route('/logout')
def logout():
"""logout route"""