<s> import os <EOL> import os . path as op <EOL> from flask import Flask <EOL> from flask . ext . sqlalchemy import SQLAlchemy <EOL> from flask . ext import admin <EOL> from flask . ext . admin . contrib . sqla import ModelView <EOL> app = Flask ( __name__ ) <EOL> app . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> app . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> app . config [ '<STR_LIT>' ] = '<STR_LIT>' + app . config [ '<STR_LIT>' ] <EOL> app . config [ '<STR_LIT>' ] = True <EOL> db = SQLAlchemy ( app ) <EOL> class User ( db . Model ) : <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> name = db . Column ( db . Unicode ( <NUM_LIT:64> ) ) <EOL> email = db . Column ( db . Unicode ( <NUM_LIT:64> ) ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> class Page ( db . Model ) : <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> title = db . Column ( db . Unicode ( <NUM_LIT:64> ) ) <EOL> content = db . Column ( db . UnicodeText ) <EOL> def __unicode__ ( self ) : <EOL> return self . name <EOL> class CustomView ( ModelView ) : <EOL> list_template = '<STR_LIT>' <EOL> create_template = '<STR_LIT>' <EOL> edit_template = '<STR_LIT>' <EOL> class UserAdmin ( CustomView ) : <EOL> column_searchable_list = ( '<STR_LIT:name>' , ) <EOL> column_filters = ( '<STR_LIT:name>' , '<STR_LIT:email>' ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return '<STR_LIT>' <EOL> admin = admin . Admin ( app , '<STR_LIT>' , base_template = '<STR_LIT>' ) <EOL> admin . add_view ( UserAdmin ( User , db . session ) ) <EOL> admin . add_view ( CustomView ( Page , db . session ) ) <EOL> def build_sample_db ( ) : <EOL> """<STR_LIT>""" <EOL> db . drop_all ( ) <EOL> db . create_all ( ) <EOL> first_names = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> last_names = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> for i in range ( len ( first_names ) ) : <EOL> user = User ( ) <EOL> user . name = first_names [ i ] + "<STR_LIT:U+0020>" + last_names [ i ] <EOL> user . email = first_names [ i ] . lower ( ) + "<STR_LIT>" <EOL> db . session . add ( user ) <EOL> sample_text = [ <EOL> { <EOL> '<STR_LIT:title>' : "<STR_LIT>" , <EOL> '<STR_LIT:content>' : "<STR_LIT>" <EOL> } , <EOL> { <EOL> '<STR_LIT:title>' : "<STR_LIT>" , <EOL> '<STR_LIT:content>' : "<STR_LIT>" <EOL> } , <EOL> { <EOL> '<STR_LIT:title>' : "<STR_LIT>" , <EOL> '<STR_LIT:content>' : "<STR_LIT>" <EOL> } <EOL> ] <EOL> for entry in sample_text : <EOL> page = Page ( ) <EOL> page . title = entry [ '<STR_LIT:title>' ] <EOL> page . content = entry [ '<STR_LIT:content>' ] <EOL> db . session . add ( page ) <EOL> db . session . commit ( ) <EOL> return <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app_dir = op . realpath ( os . path . dirname ( __file__ ) ) <EOL> database_path = op . join ( app_dir , app . config [ '<STR_LIT>' ] ) <EOL> if not os . path . exists ( database_path ) : <EOL> build_sample_db ( ) <EOL> app . run ( debug = True ) </s>
