Created
January 17, 2013 14:17
-
-
Save mrjoes/4556210 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'admin/master.html' %} | |
{% import 'admin/lib.html' as lib with context %} | |
{% block body %} | |
{% call lib.form_tag() %} | |
{{ lib.render_form_fields(form) }} | |
<input type="submit" /> | |
{% endcall %} | |
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, redirect, url_for, request, flash | |
from flask.ext.admin import Admin, BaseView, expose | |
from flask.ext import wtf | |
app = Flask(__name__) | |
app.config['SECRET_KEY'] = '123456790' | |
user_view = Admin(app, name='User stuff') | |
class User(object): | |
def __init__(self, uid): | |
self.uid = uid | |
def set(self, **kwargs): | |
pass | |
def save(self): | |
pass | |
class ProfileForm(wtf.Form): | |
username = wtf.TextField('Username', [wtf.Required()]) | |
name = wtf.TextField('Name', [wtf.Required()]) | |
class Profile(BaseView): | |
@expose('/') | |
def index(self): | |
return redirect(url_for('.profile', uid=10)) | |
@expose('/<uid>/', methods=('GET', 'POST')) | |
def profile(self, uid): | |
user = User(uid) # gets the user's data from DB | |
form = ProfileForm(request.form, obj=user) | |
if form.validate_on_submit(): | |
data = form.data | |
user.set(**data) | |
user.save() | |
flash("Your profile has been saved") | |
else: | |
flash("form did not validate on submit") | |
return self.render('profile.html', form=form, data=user) | |
user_view.add_view(Profile(name='Profile', url='profile')) | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment