<s> import os <EOL> from flask import Flask , render_template , session , redirect , url_for <EOL> from flask . ext . script import Manager <EOL> from flask . ext . bootstrap import Bootstrap <EOL> from flask . ext . moment import Moment <EOL> from flask . ext . wtf import Form <EOL> from wtforms import StringField , SubmitField <EOL> from wtforms . validators import Required <EOL> from flask . ext . sqlalchemy import SQLAlchemy <EOL> basedir = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> app = Flask ( __name__ ) <EOL> app . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> app . config [ '<STR_LIT>' ] = '<STR_LIT>' + os . path . join ( basedir , '<STR_LIT>' ) <EOL> app . config [ '<STR_LIT>' ] = True <EOL> manager = Manager ( app ) <EOL> bootstrap = Bootstrap ( app ) <EOL> moment = Moment ( app ) <EOL> db = SQLAlchemy ( app ) <EOL> class Role ( db . Model ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> name = db . Column ( db . String ( <NUM_LIT:64> ) , unique = True ) <EOL> users = db . relationship ( '<STR_LIT>' , backref = '<STR_LIT>' , lazy = '<STR_LIT>' ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . name <EOL> class User ( db . Model ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> username = db . Column ( db . String ( <NUM_LIT:64> ) , unique = True , index = True ) <EOL> role_id = db . Column ( db . Integer , db . ForeignKey ( '<STR_LIT>' ) ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . username <EOL> class NameForm ( Form ) : <EOL> name = StringField ( '<STR_LIT>' , validators = [ Required ( ) ] ) <EOL> submit = SubmitField ( '<STR_LIT>' ) <EOL> @ app . errorhandler ( <NUM_LIT> ) <EOL> def page_not_found ( e ) : <EOL> return render_template ( '<STR_LIT>' ) , <NUM_LIT> <EOL> @ app . errorhandler ( <NUM_LIT> ) <EOL> def internal_server_error ( e ) : <EOL> return render_template ( '<STR_LIT>' ) , <NUM_LIT> <EOL> @ app . route ( '<STR_LIT:/>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def index ( ) : <EOL> form = NameForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> user = User . query . filter_by ( username = form . name . data ) . first ( ) <EOL> if user is None : <EOL> user = User ( username = form . name . data ) <EOL> db . session . add ( user ) <EOL> session [ '<STR_LIT>' ] = False <EOL> else : <EOL> session [ '<STR_LIT>' ] = True <EOL> session [ '<STR_LIT:name>' ] = form . name . data <EOL> return redirect ( url_for ( '<STR_LIT:index>' ) ) <EOL> return render_template ( '<STR_LIT>' , form = form , name = session . get ( '<STR_LIT:name>' ) , <EOL> known = session . get ( '<STR_LIT>' , False ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> manager . run ( ) </s>
