<s> from bottle import Bottle , TEMPLATE_PATH <EOL> from beaker . middleware import SessionMiddleware <EOL> import os <EOL> from sqlalchemy import create_engine , Column , Integer , Numeric , Sequence , String <EOL> from sqlalchemy . ext . declarative import declarative_base <EOL> from sqlalchemy . orm import sessionmaker <EOL> import bottle_admin <EOL> from bottle_admin import site <EOL> from bottle_admin . auth import get_aaa <EOL> from bottle_admin . auth . models import Role , User <EOL> from bottle_admin . options import ModelAdmin <EOL> ADMIN_TEMPLATE_PATH = os . path . join ( os . path . dirname ( bottle_admin . __path__ [ <NUM_LIT:0> ] ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> TEMPLATE_PATH . insert ( <NUM_LIT:1> , ADMIN_TEMPLATE_PATH ) <EOL> engine = create_engine ( '<STR_LIT>' , echo = True ) <EOL> Base = declarative_base ( ) <EOL> Base . metadata . drop_all ( bind = engine ) <EOL> class Product ( Base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( Integer , Sequence ( '<STR_LIT>' ) , primary_key = True ) <EOL> name = Column ( String ( <NUM_LIT:50> ) ) <EOL> description = Column ( String ( <NUM_LIT:50> ) ) <EOL> price = Column ( Numeric ( <NUM_LIT:10> , <NUM_LIT:2> ) ) <EOL> def __init__ ( self , name , description , price ) : <EOL> self . name = name <EOL> self . description = description <EOL> self . price = price <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . name , self . fullname , <EOL> self . password ) <EOL> Product . metadata . create_all ( engine ) <EOL> app = Bottle ( ) <EOL> class ProductAdmin ( ModelAdmin ) : <EOL> list_display = ( '<STR_LIT:name>' , '<STR_LIT:description>' , '<STR_LIT>' ) <EOL> site . setup ( engine , app ) <EOL> site . register ( Product , ProductAdmin ) <EOL> session_opts = { <EOL> '<STR_LIT>' : '<STR_LIT:file>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> app = SessionMiddleware ( app , session_opts ) <EOL> session = sessionmaker ( bind = engine ) ( ) <EOL> role_user = Role ( role = '<STR_LIT:user>' , level = <NUM_LIT:50> ) <EOL> session . add ( role_user ) <EOL> role_admin = Role ( role = '<STR_LIT>' , level = <NUM_LIT> ) <EOL> session . add ( role_admin ) <EOL> session . commit ( ) <EOL> aaa = get_aaa ( ) <EOL> hash = aaa . _hash ( '<STR_LIT:user>' , '<STR_LIT>' ) <EOL> session . add ( User ( username = '<STR_LIT:user>' , hash = hash , role = '<STR_LIT:user>' , <EOL> fullname = '<STR_LIT>' , email_addr = '<STR_LIT>' ) ) <EOL> hash = aaa . _hash ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> session . add ( User ( username = '<STR_LIT>' , hash = hash , role = '<STR_LIT>' , <EOL> fullname = '<STR_LIT>' , email_addr = '<STR_LIT>' ) ) <EOL> session . commit ( ) </s>
